along with TAGS
This commit is contained in:
parent
97a2a1633d
commit
e5dea853b0
@ -17,8 +17,9 @@ public class CustomBlocks {
|
|||||||
Learning.LOGGER.info("Registering blocks...");
|
Learning.LOGGER.info("Registering blocks...");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final Block test_block = register("test_block");
|
public static final Block testBlock = register("test_block");
|
||||||
public static final Block damageBlock = register("damage_block", DamageBlock::new, AbstractBlock.Settings.create());
|
public static final Block damageBlock = register("damage_block", DamageBlock::new, AbstractBlock.Settings.create());
|
||||||
|
public static final Block transformBlock = register("transform_block", TransformBlock::new, AbstractBlock.Settings.create());
|
||||||
|
|
||||||
public static final Block register(String blockId) {
|
public static final Block register(String blockId) {
|
||||||
return register(blockId, Block::new, AbstractBlock.Settings.create());
|
return register(blockId, Block::new, AbstractBlock.Settings.create());
|
||||||
|
@ -18,12 +18,15 @@ public class DamageBlock extends Block {
|
|||||||
public DamageBlock(AbstractBlock.Settings settings) {
|
public DamageBlock(AbstractBlock.Settings settings) {
|
||||||
super(settings);
|
super(settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void onSteppedOn(World world, BlockPos pos, BlockState state, Entity entity) {
|
public void onSteppedOn(World world, BlockPos pos, BlockState state, Entity entity) {
|
||||||
if (!world.isClient() && entity.canHit()) {
|
if (!world.isClient() && entity.canHit()) {
|
||||||
entity.damage((ServerWorld)world, world.getDamageSources().generic(), 6f);
|
entity.damage((ServerWorld)world, world.getDamageSources().generic(), 6f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void appendTooltip(ItemStack stack, TooltipContext context, List<Text> tooltip, TooltipType type) {
|
public void appendTooltip(ItemStack stack, TooltipContext context, List<Text> tooltip, TooltipType type) {
|
||||||
super.appendTooltip(stack, context, tooltip, type);
|
super.appendTooltip(stack, context, tooltip, type);
|
||||||
tooltip.add(Text.translatable("toolTip.learning.damage_block"));
|
tooltip.add(Text.translatable("toolTip.learning.damage_block"));
|
||||||
|
38
src/main/java/com/learning/block/TransformBlock.java
Normal file
38
src/main/java/com/learning/block/TransformBlock.java
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
package com.learning.block;
|
||||||
|
|
||||||
|
import com.learning.util.ModTags.ItemTags;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import net.minecraft.block.AbstractBlock;
|
||||||
|
import net.minecraft.block.Block;
|
||||||
|
import net.minecraft.block.BlockState;
|
||||||
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraft.entity.Entity;
|
||||||
|
import net.minecraft.entity.ItemEntity;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.item.Items;
|
||||||
|
import net.minecraft.item.Item.TooltipContext;
|
||||||
|
import net.minecraft.item.tooltip.TooltipType;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
|
|
||||||
|
public class TransformBlock extends Block {
|
||||||
|
public TransformBlock(AbstractBlock.Settings settings) {
|
||||||
|
super(settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSteppedOn(World world, BlockPos pos, BlockState state, Entity entity) {
|
||||||
|
if (!world.isClient() && entity instanceof ItemEntity itemEntity) {
|
||||||
|
if (itemEntity.getStack().isIn(ItemTags.DIAMOND_TRANSFORMABLE)) {
|
||||||
|
itemEntity.setStack(new ItemStack(Items.DIAMOND, itemEntity.getStack().getCount()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void appendTooltip(ItemStack stack, TooltipContext context, List<Text> tooltip, TooltipType type) {
|
||||||
|
super.appendTooltip(stack, context, tooltip, type);
|
||||||
|
tooltip.add(Text.translatable("toolTip.learning.transform_block"));
|
||||||
|
}
|
||||||
|
}
|
@ -25,6 +25,7 @@ public class CustomItems {
|
|||||||
public static Item toast = register("toast", Toast::new, new Item.Settings().food(Foods.toastFood));
|
public static Item toast = register("toast", Toast::new, new Item.Settings().food(Foods.toastFood));
|
||||||
public static Item bakedToast = register("baked_toast", BakedToast::new, new Item.Settings().food(Foods.bakedToastFood, ConsumableComponents.food().consumeSeconds(0.8f).build()));
|
public static Item bakedToast = register("baked_toast", BakedToast::new, new Item.Settings().food(Foods.bakedToastFood, ConsumableComponents.food().consumeSeconds(0.8f).build()));
|
||||||
public static Item damageBlock = register(CustomBlocks.damageBlock, false);
|
public static Item damageBlock = register(CustomBlocks.damageBlock, false);
|
||||||
|
public static Item transformBlock = register(CustomBlocks.transformBlock, false);
|
||||||
|
|
||||||
private static Item register(Block block, Boolean useItemTranslateKey) {
|
private static Item register(Block block, Boolean useItemTranslateKey) {
|
||||||
RegistryKey<Item> key = keyOf(Registries.BLOCK.getKey(block).get());
|
RegistryKey<Item> key = keyOf(Registries.BLOCK.getKey(block).get());
|
||||||
|
@ -29,6 +29,7 @@ public class CustomItemGroup {
|
|||||||
entries.add(CustomItems.toast);
|
entries.add(CustomItems.toast);
|
||||||
entries.add(CustomItems.bakedToast);
|
entries.add(CustomItems.bakedToast);
|
||||||
entries.add(CustomItems.damageBlock);
|
entries.add(CustomItems.damageBlock);
|
||||||
|
entries.add(CustomItems.transformBlock);
|
||||||
})
|
})
|
||||||
.build());
|
.build());
|
||||||
|
|
||||||
|
23
src/main/java/com/learning/util/ModTags.java
Normal file
23
src/main/java/com/learning/util/ModTags.java
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
package com.learning.util;
|
||||||
|
|
||||||
|
import com.learning.Learning;
|
||||||
|
|
||||||
|
import net.minecraft.item.Item;
|
||||||
|
import net.minecraft.registry.RegistryKeys;
|
||||||
|
import net.minecraft.registry.tag.TagKey;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
|
public class ModTags {
|
||||||
|
public static void registerTags() {
|
||||||
|
Learning.LOGGER.info("Registering Tags for " + Learning.MOD_ID + ".");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class ItemTags {
|
||||||
|
|
||||||
|
public static TagKey<Item> DIAMOND_TRANSFORMABLE = register("diamond_transformable");
|
||||||
|
|
||||||
|
private static TagKey<Item> register(String tagId) {
|
||||||
|
return TagKey.of(RegistryKeys.ITEM, Identifier.of(Learning.MOD_ID, tagId));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"variants": {
|
||||||
|
"": {
|
||||||
|
"model": "learning:block/transform_block"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"model": {
|
||||||
|
"type": "minecraft:model",
|
||||||
|
"model": "learning:block/transform_block"
|
||||||
|
}
|
||||||
|
}
|
@ -3,9 +3,11 @@
|
|||||||
"item.learning.baked_toast": "Baked Toast",
|
"item.learning.baked_toast": "Baked Toast",
|
||||||
|
|
||||||
"block.learning.damage_block": "Damage Block",
|
"block.learning.damage_block": "Damage Block",
|
||||||
|
"block.learning.transform_block": "Transform Block",
|
||||||
|
|
||||||
"itemGroup.learning.custom_itemgroup": "My Dear...",
|
"itemGroup.learning.custom_itemgroup": "My Dear...",
|
||||||
|
|
||||||
|
"toolTip.learning.transform_block": "Will turn the specific item into diamond!",
|
||||||
"toolTip.learning.toast0": "A simple fastfood.",
|
"toolTip.learning.toast0": "A simple fastfood.",
|
||||||
"toolTip.learning.toast1": "Will be tastier after baking in the furnace!",
|
"toolTip.learning.toast1": "Will be tastier after baking in the furnace!",
|
||||||
"toolTip.learning.baked_toast": "Yummy!",
|
"toolTip.learning.baked_toast": "Yummy!",
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"parent": "block/cube_bottom_top",
|
"parent": "block/cube_bottom_top",
|
||||||
"textures": {
|
"textures": {
|
||||||
"bottom": "learning:block/damage_block_bottom",
|
"bottom": "learning:block/white_block_bottom",
|
||||||
"top": "learning:block/damage_block_top",
|
"top": "learning:block/damage_block_top",
|
||||||
"side": "learning:block/damage_block_side"
|
"side": "learning:block/damage_block_side"
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"parent": "block/cube_bottom_top",
|
||||||
|
"textures": {
|
||||||
|
"bottom": "learning:block/white_block_bottom",
|
||||||
|
"top": "learning:block/transformblock_top",
|
||||||
|
"side": "learning:block/transformblock_side"
|
||||||
|
}
|
||||||
|
}
|
Binary file not shown.
After Width: | Height: | Size: 298 B |
Binary file not shown.
After Width: | Height: | Size: 232 B |
Before Width: | Height: | Size: 91 B After Width: | Height: | Size: 91 B |
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"values": [
|
||||||
|
"minecraft:coal",
|
||||||
|
"learning:baked_toast"
|
||||||
|
]
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user