block
This commit is contained in:
parent
babd5f9860
commit
64b4a2a2df
36
src/main/java/com/learning/block/CustomBlocks.java
Normal file
36
src/main/java/com/learning/block/CustomBlocks.java
Normal file
@ -0,0 +1,36 @@
|
||||
package com.learning.block;
|
||||
|
||||
import com.learning.Learning;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
import net.minecraft.registry.Registries;
|
||||
import net.minecraft.registry.Registry;
|
||||
import net.minecraft.registry.RegistryKey;
|
||||
import net.minecraft.registry.RegistryKeys;
|
||||
import net.minecraft.block.AbstractBlock;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
public class CustomBlocks {
|
||||
public static void registerBlocks() {
|
||||
Learning.LOGGER.info("Registering blocks...");
|
||||
}
|
||||
|
||||
public static final Block test_block = register("test_block");
|
||||
public static final Block damageBlock = register("damage_block", DamageBlock::new, AbstractBlock.Settings.create());
|
||||
|
||||
public static final Block register(String blockId) {
|
||||
return register(blockId, Block::new, AbstractBlock.Settings.create());
|
||||
}
|
||||
|
||||
public static Block register(String blockId, Function<AbstractBlock.Settings, Block> factory, AbstractBlock.Settings settings) {
|
||||
RegistryKey<Block> key = keyOf(blockId);
|
||||
return Registry.register(Registries.BLOCK, key, factory.apply(settings.registryKey(key)));
|
||||
|
||||
}
|
||||
|
||||
private static final RegistryKey<Block> keyOf(String blockId) {
|
||||
return RegistryKey.of(RegistryKeys.BLOCK, Identifier.of(Learning.MOD_ID, blockId));
|
||||
}
|
||||
}
|
21
src/main/java/com/learning/block/DamageBlock.java
Normal file
21
src/main/java/com/learning/block/DamageBlock.java
Normal file
@ -0,0 +1,21 @@
|
||||
package com.learning.block;
|
||||
|
||||
|
||||
import net.minecraft.block.AbstractBlock;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.entity.Entity;
|
||||
|
||||
public class DamageBlock extends Block {
|
||||
public DamageBlock(AbstractBlock.Settings settings) {
|
||||
super(settings);
|
||||
}
|
||||
public void onSteppedOn(World world, BlockPos pos, BlockState state, Entity entity) {
|
||||
if (!world.isClient()) {
|
||||
entity.damage((ServerWorld)world, world.getDamageSources().generic(), 6f);
|
||||
}
|
||||
}
|
||||
}
|
@ -3,5 +3,6 @@ package com.learning.component;
|
||||
import net.minecraft.component.type.FoodComponent;
|
||||
|
||||
public class Foods {
|
||||
public static FoodComponent toastFood = new FoodComponent.Builder().nutrition(4).build();
|
||||
public static FoodComponent toastFood = new FoodComponent.Builder().nutrition(2).build();
|
||||
public static FoodComponent bakedToastFood = new FoodComponent.Builder().nutrition(6).build();
|
||||
}
|
||||
|
21
src/main/java/com/learning/item/BakedToast.java
Normal file
21
src/main/java/com/learning/item/BakedToast.java
Normal file
@ -0,0 +1,21 @@
|
||||
package com.learning.item;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.tooltip.TooltipType;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Formatting;
|
||||
|
||||
public class BakedToast extends Item {
|
||||
public BakedToast(Item.Settings settings) {
|
||||
super(settings);
|
||||
}
|
||||
|
||||
@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.baked_toast").formatted(Formatting.GOLD));
|
||||
}
|
||||
}
|
@ -4,37 +4,61 @@ package com.learning.item;
|
||||
import java.util.function.Function;
|
||||
|
||||
import com.learning.Learning;
|
||||
import com.learning.component.Foods;
|
||||
import com.learning.item.Toast;
|
||||
import com.learning.block.CustomBlocks;
|
||||
import com.learning.component.Foods;
|
||||
|
||||
import net.minecraft.item.BlockItem;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.registry.Registries;
|
||||
import net.minecraft.registry.Registry;
|
||||
import net.minecraft.registry.RegistryKey;
|
||||
import net.minecraft.registry.RegistryKeys;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.component.type.ConsumableComponents;
|
||||
|
||||
public class CustomItem {
|
||||
public static void registerItems() {
|
||||
Learning.LOGGER.info("Registering Items...");
|
||||
}
|
||||
public static void registerItems() {
|
||||
Learning.LOGGER.info("Registering Items...");
|
||||
}
|
||||
|
||||
public static Item toast = register("toast", Toast::new, new Item.Settings().food(Foods.toastFood, ConsumableComponents.food().consumeSeconds(0.5f).build()));
|
||||
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 damageBlock = register(CustomBlocks.damageBlock);
|
||||
|
||||
private static Item register(String itemId) {
|
||||
return register(itemId, new Item.Settings());
|
||||
}
|
||||
private static Item register(Block block) {
|
||||
RegistryKey<Item> key = keyOf(Registries.BLOCK.getKey(block).get());
|
||||
return Registry.register(Registries.ITEM, key, new BlockItem(block, new Item.Settings().useItemPrefixedTranslationKey().registryKey(key)));
|
||||
|
||||
}
|
||||
|
||||
private static Item register(String itemId, Item.Settings settings) {
|
||||
return register(itemId, Item::new, settings);
|
||||
}
|
||||
private static Item register(String itemId) {
|
||||
return register(itemId, new Item.Settings());
|
||||
}
|
||||
|
||||
private static Item register(String itemId, Item.Settings settings) {
|
||||
return register(itemId, Item::new, settings);
|
||||
}
|
||||
|
||||
private static Item register(String itemId, Function<Item.Settings, Item> factory, Item.Settings settings) {
|
||||
RegistryKey<Item> key = keyOf(itemId);
|
||||
return Registry.register(Registries.ITEM, key, factory.apply(settings.registryKey(key)));
|
||||
}
|
||||
private static RegistryKey<Item> keyOf(String itemId) {
|
||||
return RegistryKey.of(RegistryKeys.ITEM, Identifier.of(Learning.MOD_ID, itemId));
|
||||
}
|
||||
private static Item register(String itemId, Function<Item.Settings, Item> factory, Item.Settings settings) {
|
||||
RegistryKey<Item> key = keyOf(itemId);
|
||||
return register(key, factory, settings);
|
||||
}
|
||||
|
||||
private static Item register(RegistryKey<Item> key, Function<Item.Settings, Item> factory, Item.Settings settings) {
|
||||
return register(key, factory.apply(settings.registryKey(key)));
|
||||
}
|
||||
|
||||
private static Item register(RegistryKey<Item> key, Item item) {
|
||||
return Registry.register(Registries.ITEM, key, item);
|
||||
|
||||
}
|
||||
|
||||
private static RegistryKey<Item> keyOf(String itemId) {
|
||||
return RegistryKey.of(RegistryKeys.ITEM, Identifier.of(Learning.MOD_ID, itemId));
|
||||
}
|
||||
|
||||
private static RegistryKey<Item> keyOf(RegistryKey<Block> blockKey) {
|
||||
return RegistryKey.of(RegistryKeys.ITEM, blockKey.getValue());
|
||||
}
|
||||
}
|
||||
|
@ -12,17 +12,17 @@ import java.util.List;
|
||||
|
||||
public class Toast extends Item {
|
||||
public Toast(Item.Settings settings) {
|
||||
super(settings);
|
||||
super(settings);
|
||||
}
|
||||
|
||||
@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.toast0").formatted(Formatting.GRAY));
|
||||
if (Screen.hasControlDown()) {
|
||||
if (Screen.hasShiftDown()) {
|
||||
tooltip.add(Text.translatable("toolTip.learning.toast1"));
|
||||
} else {
|
||||
tooltip.add(Text.translatable("toolTip.learning.hold_control"));
|
||||
tooltip.add(Text.translatable("toolTip.learning.hold_shift"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,26 +14,28 @@ import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
public class CustomItemGroup {
|
||||
public static void registerItemGroup() {
|
||||
public static void registerItemGroup() {
|
||||
Learning.LOGGER.info("Registering ItemGroup...");
|
||||
Learning.LOGGER.info("Registering item into ItemGroups...");
|
||||
ItemGroupEvents.modifyEntriesEvent(ItemGroups.FOOD_AND_DRINK).register(
|
||||
register -> register.add(CustomItem.toast)
|
||||
);
|
||||
}
|
||||
register -> register.add(CustomItem.toast)
|
||||
);
|
||||
}
|
||||
|
||||
public static ItemGroup customItemGroup = register("custom_itemgroup", ItemGroup.create(null, -1)
|
||||
.icon(() -> new ItemStack(CustomItem.toast))
|
||||
.displayName(Text.translatable("itemGroup.learning.custom_itemgroup"))
|
||||
.entries((displayContext, entries) -> {
|
||||
entries.add(CustomItem.toast);
|
||||
})
|
||||
.build());
|
||||
public static ItemGroup customItemGroup = register("custom_itemgroup", ItemGroup.create(null, -1)
|
||||
.icon(() -> new ItemStack(CustomItem.toast))
|
||||
.displayName(Text.translatable("itemGroup.learning.custom_itemgroup"))
|
||||
.entries((displayContext, entries) -> {
|
||||
entries.add(CustomItem.toast);
|
||||
entries.add(CustomItem.bakedToast);
|
||||
entries.add(CustomItem.damageBlock);
|
||||
})
|
||||
.build());
|
||||
|
||||
private static ItemGroup register(String groupId, ItemGroup itemGroup) {
|
||||
return Registry.register(
|
||||
Registries.ITEM_GROUP,
|
||||
Identifier.of(Learning.MOD_ID, groupId),
|
||||
itemGroup);
|
||||
}
|
||||
return Registry.register(
|
||||
Registries.ITEM_GROUP,
|
||||
Identifier.of(Learning.MOD_ID, groupId),
|
||||
itemGroup);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,7 @@
|
||||
{
|
||||
"variants": {
|
||||
"": {
|
||||
"model": "learning:block/damage_block"
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
{
|
||||
"model": {
|
||||
"type": "minecraft:model",
|
||||
"model": "learning:item/baked_toast"
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
{
|
||||
"model": {
|
||||
"type": "minecraft:model",
|
||||
"model": "learning:block/damage_block"
|
||||
}
|
||||
}
|
@ -5,5 +5,6 @@
|
||||
|
||||
"toolTip.learning.toast0": "A simple fastfood.",
|
||||
"toolTip.learning.toast1": "Will be tastier after baking in the furnace!",
|
||||
"toolTip.learning.hold_control": "Hold §6Control §rto show more information."
|
||||
"toolTip.learning.hold_control": "Hold §6Control §rto show more information.",
|
||||
"toolTip.learning.hold_shift": "Hold §6Shift §rto show more information."
|
||||
}
|
||||
|
@ -0,0 +1,8 @@
|
||||
{
|
||||
"parent": "block/cube_bottom_top",
|
||||
"textures": {
|
||||
"bottom": "learning:block/damage_block_bottom",
|
||||
"top": "learning:block/damage_block_top",
|
||||
"side": "learning:block/damage_block_side"
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
{
|
||||
"parent": "item/generated",
|
||||
"textures": {
|
||||
"layer0": "learning:item/baked_toast"
|
||||
}
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 91 B |
Binary file not shown.
After Width: | Height: | Size: 260 B |
Binary file not shown.
After Width: | Height: | Size: 211 B |
BIN
src/main/resources/assets/learning/textures/item/baked_toast.png
Normal file
BIN
src/main/resources/assets/learning/textures/item/baked_toast.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 149 B |
Loading…
x
Reference in New Issue
Block a user