diff --git a/src/main/java/de/jottyfan/minecraft/Quickly.java b/src/main/java/de/jottyfan/minecraft/Quickly.java index eded03c..aeaa367 100644 --- a/src/main/java/de/jottyfan/minecraft/Quickly.java +++ b/src/main/java/de/jottyfan/minecraft/Quickly.java @@ -7,6 +7,14 @@ import de.jottyfan.minecraft.block.QuicklyBlocks; import de.jottyfan.minecraft.feature.QuicklyFeatures; import de.jottyfan.minecraft.item.QuicklyItems; import net.fabricmc.api.ModInitializer; +import net.fabricmc.fabric.api.loot.v3.LootTableEvents; +import net.fabricmc.fabric.api.registry.CompostingChanceRegistry; +import net.minecraft.world.item.Items; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.storage.loot.LootPool; +import net.minecraft.world.level.storage.loot.entries.LootItem; +import net.minecraft.world.level.storage.loot.providers.number.ConstantValue; + /** * @@ -18,6 +26,27 @@ public class Quickly implements ModInitializer { public static final Logger LOGGER = LogManager.getLogger(MOD_ID); + private void registerComposterItems() { + CompostingChanceRegistry.INSTANCE.add(QuicklyItems.COTTONSEED, 0.5f); + CompostingChanceRegistry.INSTANCE.add(QuicklyItems.COTTON, 0.75f); + } + + private void registerLootTableChanges() { + LootTableEvents.MODIFY.register((key, tableBuilder, source, registries) -> { + if (source.isBuiltin()) { + if (Blocks.SHORT_GRASS.getLootTable().equals(key)) { + LootPool.Builder poolBuilder = LootPool.lootPool() + .setRolls(ConstantValue.exactly(1f)) + .add(LootItem.lootTableItem(Items.AIR).setWeight(4)) + .add(LootItem.lootTableItem(QuicklyItems.COTTONSEED).setWeight(1)); + tableBuilder.withPool(poolBuilder); + } else if (Blocks.TALL_GRASS.getLootTable().equals(key)) { + // for the canola loot table block later + } + } + }); + } + @Override public void onInitialize() { LOGGER.info("loading {}", MOD_ID); @@ -25,5 +54,8 @@ public class Quickly implements ModInitializer { QuicklyItems.registerModItems(); QuicklyBlocks.registerModBlocks(); QuicklyFeatures.registerFeatures(); + registerComposterItems(); + registerLootTableChanges(); + } } \ No newline at end of file diff --git a/src/main/java/de/jottyfan/minecraft/QuicklyClient.java b/src/main/java/de/jottyfan/minecraft/QuicklyClient.java index dcf5c47..466de95 100644 --- a/src/main/java/de/jottyfan/minecraft/QuicklyClient.java +++ b/src/main/java/de/jottyfan/minecraft/QuicklyClient.java @@ -1,8 +1,9 @@ package de.jottyfan.minecraft; import de.jottyfan.minecraft.block.QuicklyBlocks; -import de.jottyfan.minecraft.item.QuicklyItems; import net.fabricmc.api.ClientModInitializer; +import net.fabricmc.fabric.api.client.rendering.v1.BlockRenderLayerMap; +import net.minecraft.client.renderer.chunk.ChunkSectionLayer; /** * @@ -13,5 +14,6 @@ public class QuicklyClient implements ClientModInitializer { @Override public void onInitializeClient() { + BlockRenderLayerMap.putBlock(QuicklyBlocks.COTTONPLANT, ChunkSectionLayer.CUTOUT); } } diff --git a/src/main/java/de/jottyfan/minecraft/block/BlockPlant.java b/src/main/java/de/jottyfan/minecraft/block/BlockPlant.java new file mode 100644 index 0000000..f0d4f50 --- /dev/null +++ b/src/main/java/de/jottyfan/minecraft/block/BlockPlant.java @@ -0,0 +1,64 @@ +package de.jottyfan.minecraft.block; + +import java.util.List; +import java.util.Random; + +import net.minecraft.core.BlockPos; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.resources.Identifier; +import net.minecraft.world.Containers; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.CropBlock; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.storage.loot.LootParams.Builder; +import net.minecraft.world.phys.BlockHitResult; + +/** + * + * @author jotty + * + */ +public class BlockPlant extends CropBlock { + + private Identifier seed; + private Identifier fruit; + + public BlockPlant(Properties properties, Identifier seed, Identifier fruit) { + super(properties); + this.seed = seed; + this.fruit = fruit; + } + + @Override + protected List getDrops(BlockState state, Builder builder) { + List list = List.of(new ItemStack(getSeed())); + if (isMaxAge(state)) { + list.add(new ItemStack(getSeed(), new Random().nextInt(2))); + list.add(new ItemStack(getFruit(), new Random().nextFloat() > 0.9f ? 2 : 1)); + } + return list; + } + + private Item getFruit() { + return BuiltInRegistries.ITEM.getValue(fruit); + } + + public Item getSeed() { + return BuiltInRegistries.ITEM.getValue(seed); + } + + @Override + protected InteractionResult useWithoutItem(BlockState state, Level level, BlockPos pos, Player player, + BlockHitResult hitResult) { + if (!level.isClientSide() && isMaxAge(state)) { + Containers.dropItemStack(level, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(getSeed())); + level.setBlock(pos, state.setValue(AGE, 0), 2); + return InteractionResult.SUCCESS; + } + return InteractionResult.PASS; + } +} diff --git a/src/main/java/de/jottyfan/minecraft/block/QuicklyBlocks.java b/src/main/java/de/jottyfan/minecraft/block/QuicklyBlocks.java index 25a7444..79cc794 100644 --- a/src/main/java/de/jottyfan/minecraft/block/QuicklyBlocks.java +++ b/src/main/java/de/jottyfan/minecraft/block/QuicklyBlocks.java @@ -13,6 +13,7 @@ import net.minecraft.world.item.BlockItem; import net.minecraft.world.item.CreativeModeTabs; import net.minecraft.world.item.Item; import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.SoundType; import net.minecraft.world.level.block.state.BlockBehaviour.Properties; @@ -28,6 +29,8 @@ public class QuicklyBlocks { public static final Block ORETURQUOISE = registerBlock("oreturquoise", p -> new BlockOreTurquoise(p)); public static final Block OREDEEPSLATETURQUOISE = registerBlock("oredeepslateturquoise", p -> new BlockOreDeepslateTurquoise(p)); + public static final Block COTTONPLANT = registerBlock("blockcottonplant", Properties.ofFullCopy(Blocks.WHEAT), + p -> new BlockPlant(p, Identifier.fromNamespaceAndPath(Quickly.MOD_ID, "cottonseed"), Identifier.fromNamespaceAndPath(Quickly.MOD_ID, "cotton"))); private static final Block registerBlock(String name, Properties properties) { return QuicklyBlocks.registerBlock(name, properties, p -> new Block(p)); @@ -53,6 +56,7 @@ public class QuicklyBlocks { block.accept(TURQUOISEBLOCK); block.accept(ORETURQUOISE); block.accept(OREDEEPSLATETURQUOISE); + block.accept(COTTONPLANT); }); } } diff --git a/src/main/java/de/jottyfan/minecraft/item/Plant.java b/src/main/java/de/jottyfan/minecraft/item/Plant.java new file mode 100644 index 0000000..d851769 --- /dev/null +++ b/src/main/java/de/jottyfan/minecraft/item/Plant.java @@ -0,0 +1,41 @@ +package de.jottyfan.minecraft.item; + +import net.minecraft.core.BlockPos; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.resources.Identifier; +import net.minecraft.world.InteractionResult; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.context.UseOnContext; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; + +/** + * + * @author jotty + * + */ +public class Plant extends Item { + + private Identifier identifier; + + public Plant(Properties properties, Identifier identifier) { + super(properties); + this.identifier = identifier; + } + + @Override + public InteractionResult useOn(UseOnContext context) { + BlockPos pos = context.getClickedPos(); + if (this.asItem().equals(context.getItemInHand().getItem())) { + BlockState state = context.getLevel().getBlockState(pos); + if (Blocks.FARMLAND.equals(state.getBlock()) && context.getLevel().getBlockState(pos.above()).isAir()) { + Block plantBlock = BuiltInRegistries.BLOCK.getValue(identifier); + context.getLevel().setBlock(pos.above(), plantBlock.defaultBlockState(), 2); + context.getItemInHand().shrink(1); + } + } + return super.useOn(context); + } + +} diff --git a/src/main/java/de/jottyfan/minecraft/item/QuicklyItems.java b/src/main/java/de/jottyfan/minecraft/item/QuicklyItems.java index 30ef740..1234c39 100644 --- a/src/main/java/de/jottyfan/minecraft/item/QuicklyItems.java +++ b/src/main/java/de/jottyfan/minecraft/item/QuicklyItems.java @@ -22,6 +22,9 @@ public class QuicklyItems { public static final Item STUB = registerItem("stub", properties -> new Stub(properties)); public static final Item RAWTURQUOISE = registerItem("rawturquoise"); public static final Item TURQUOISEINGOT = registerItem("turquoiseingot"); + public static final Item COTTON = registerItem("cotton"); + public static final Item COTTONPLANT = registerItem("cottonplant"); + public static final Item COTTONSEED = registerItem("cottonseed", properties -> new Plant(properties, Identifier.fromNamespaceAndPath(Quickly.MOD_ID, "cottonplant"))); private static final Item registerItem(String name) { return QuicklyItems.registerItem(name, new Item.Properties()); @@ -47,6 +50,8 @@ public class QuicklyItems { item.accept(STUB); item.accept(RAWTURQUOISE); item.accept(TURQUOISEINGOT); + item.accept(COTTON); + item.accept(COTTONSEED); }); } } diff --git a/src/main/resources/assets/quickly/blockstates/blockcottonplant.json b/src/main/resources/assets/quickly/blockstates/blockcottonplant.json new file mode 100644 index 0000000..6343654 --- /dev/null +++ b/src/main/resources/assets/quickly/blockstates/blockcottonplant.json @@ -0,0 +1,12 @@ +{ + "variants": { + "age=0": { "model": "quickly:block/cottonplant0" }, + "age=1": { "model": "quickly:block/cottonplant1" }, + "age=2": { "model": "quickly:block/cottonplant2" }, + "age=3": { "model": "quickly:block/cottonplant3" }, + "age=4": { "model": "quickly:block/cottonplant4" }, + "age=5": { "model": "quickly:block/cottonplant5" }, + "age=6": { "model": "quickly:block/cottonplant6" }, + "age=7": { "model": "quickly:block/cottonplant7" } + } +} \ No newline at end of file diff --git a/src/main/resources/assets/quickly/items/cotton.json b/src/main/resources/assets/quickly/items/cotton.json new file mode 100644 index 0000000..87eed29 --- /dev/null +++ b/src/main/resources/assets/quickly/items/cotton.json @@ -0,0 +1,6 @@ +{ + "model": { + "type": "minecraft:model", + "model": "quickly:item/cotton" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/quickly/items/cottonplant.json b/src/main/resources/assets/quickly/items/cottonplant.json new file mode 100644 index 0000000..e63d88f --- /dev/null +++ b/src/main/resources/assets/quickly/items/cottonplant.json @@ -0,0 +1,6 @@ +{ + "model": { + "type": "minecraft:model", + "model": "quickly:item/cottonseed" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/quickly/items/cottonseed.json b/src/main/resources/assets/quickly/items/cottonseed.json new file mode 100644 index 0000000..e63d88f --- /dev/null +++ b/src/main/resources/assets/quickly/items/cottonseed.json @@ -0,0 +1,6 @@ +{ + "model": { + "type": "minecraft:model", + "model": "quickly:item/cottonseed" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/quickly/lang/de_de.json b/src/main/resources/assets/quickly/lang/de_de.json index c9427d2..ba7abfd 100644 --- a/src/main/resources/assets/quickly/lang/de_de.json +++ b/src/main/resources/assets/quickly/lang/de_de.json @@ -1,5 +1,8 @@ { + "item.quickly.blockcottonplant": "Baumwollpflanze", "item.quickly.blockturquoise": "Türkisblock", + "item.quickly.cotton": "Baumwolle", + "item.quickly.cottonseed": "Baumwollsaat", "item.quickly.kelpbundle": "Seegrassbündel", "item.quickly.oredeepslateturquoise": "Türkistiefenerz", "item.quickly.oreturquoise": "Türkiserz", diff --git a/src/main/resources/assets/quickly/lang/en_us.json b/src/main/resources/assets/quickly/lang/en_us.json index 8fdb089..ec2ee68 100644 --- a/src/main/resources/assets/quickly/lang/en_us.json +++ b/src/main/resources/assets/quickly/lang/en_us.json @@ -1,5 +1,8 @@ { + "item.quickly.blockcottonplant": "cotton plant", "item.quickly.blockturquoise": "block of turquoise", + "item.quickly.cotton": "cotton", + "item.quickly.cottonseed": "cotton seed", "item.quickly.kelpbundle": "kelp bundle", "item.quickly.oredeepslateturquoise": "turquoise deepslate ore", "item.quickly.oreturquoise": "turquoise ore", diff --git a/src/main/resources/assets/quickly/models/block/cottonplant0.json b/src/main/resources/assets/quickly/models/block/cottonplant0.json new file mode 100644 index 0000000..2093253 --- /dev/null +++ b/src/main/resources/assets/quickly/models/block/cottonplant0.json @@ -0,0 +1,6 @@ +{ + "parent":"block/cross", + "textures":{ + "cross":"quickly:block/cottonplant0" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/quickly/models/block/cottonplant1.json b/src/main/resources/assets/quickly/models/block/cottonplant1.json new file mode 100644 index 0000000..07240d7 --- /dev/null +++ b/src/main/resources/assets/quickly/models/block/cottonplant1.json @@ -0,0 +1,6 @@ +{ + "parent":"block/cross", + "textures":{ + "cross":"quickly:block/cottonplant1" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/quickly/models/block/cottonplant2.json b/src/main/resources/assets/quickly/models/block/cottonplant2.json new file mode 100644 index 0000000..8619c48 --- /dev/null +++ b/src/main/resources/assets/quickly/models/block/cottonplant2.json @@ -0,0 +1,6 @@ +{ + "parent":"block/cross", + "textures":{ + "cross":"quickly:block/cottonplant2" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/quickly/models/block/cottonplant3.json b/src/main/resources/assets/quickly/models/block/cottonplant3.json new file mode 100644 index 0000000..2105027 --- /dev/null +++ b/src/main/resources/assets/quickly/models/block/cottonplant3.json @@ -0,0 +1,6 @@ +{ + "parent":"block/cross", + "textures":{ + "cross":"quickly:block/cottonplant3" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/quickly/models/block/cottonplant4.json b/src/main/resources/assets/quickly/models/block/cottonplant4.json new file mode 100644 index 0000000..c5ddea6 --- /dev/null +++ b/src/main/resources/assets/quickly/models/block/cottonplant4.json @@ -0,0 +1,6 @@ +{ + "parent":"block/cross", + "textures":{ + "cross":"quickly:block/cottonplant4" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/quickly/models/block/cottonplant5.json b/src/main/resources/assets/quickly/models/block/cottonplant5.json new file mode 100644 index 0000000..a949f54 --- /dev/null +++ b/src/main/resources/assets/quickly/models/block/cottonplant5.json @@ -0,0 +1,6 @@ +{ + "parent":"block/cross", + "textures":{ + "cross":"quickly:block/cottonplant5" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/quickly/models/block/cottonplant6.json b/src/main/resources/assets/quickly/models/block/cottonplant6.json new file mode 100644 index 0000000..58e1c39 --- /dev/null +++ b/src/main/resources/assets/quickly/models/block/cottonplant6.json @@ -0,0 +1,6 @@ +{ + "parent":"block/cross", + "textures":{ + "cross":"quickly:block/cottonplant6" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/quickly/models/block/cottonplant7.json b/src/main/resources/assets/quickly/models/block/cottonplant7.json new file mode 100644 index 0000000..ccb57aa --- /dev/null +++ b/src/main/resources/assets/quickly/models/block/cottonplant7.json @@ -0,0 +1,6 @@ +{ + "parent":"block/cross", + "textures":{ + "cross":"quickly:block/cottonplant7" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/quickly/models/item/cotton.json b/src/main/resources/assets/quickly/models/item/cotton.json new file mode 100644 index 0000000..f6a1b73 --- /dev/null +++ b/src/main/resources/assets/quickly/models/item/cotton.json @@ -0,0 +1,6 @@ +{ + "parent": "item/generated", + "textures": { + "layer0": "quickly:item/cotton" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/quickly/models/item/cottonplant.json b/src/main/resources/assets/quickly/models/item/cottonplant.json new file mode 100644 index 0000000..2730ec5 --- /dev/null +++ b/src/main/resources/assets/quickly/models/item/cottonplant.json @@ -0,0 +1,6 @@ +{ + "parent": "item/generated", + "textures": { + "layer0": "quickly:item/cottonplant" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/quickly/models/item/cottonseed.json b/src/main/resources/assets/quickly/models/item/cottonseed.json new file mode 100644 index 0000000..eb10b55 --- /dev/null +++ b/src/main/resources/assets/quickly/models/item/cottonseed.json @@ -0,0 +1,6 @@ +{ + "parent": "item/generated", + "textures": { + "layer0": "quickly:item/cottonseed" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/quickly/textures/block/cottonplant0.png b/src/main/resources/assets/quickly/textures/block/cottonplant0.png new file mode 100644 index 0000000..afcb1ce Binary files /dev/null and b/src/main/resources/assets/quickly/textures/block/cottonplant0.png differ diff --git a/src/main/resources/assets/quickly/textures/block/cottonplant1.png b/src/main/resources/assets/quickly/textures/block/cottonplant1.png new file mode 100644 index 0000000..1a5a64e Binary files /dev/null and b/src/main/resources/assets/quickly/textures/block/cottonplant1.png differ diff --git a/src/main/resources/assets/quickly/textures/block/cottonplant2.png b/src/main/resources/assets/quickly/textures/block/cottonplant2.png new file mode 100644 index 0000000..a3c57c5 Binary files /dev/null and b/src/main/resources/assets/quickly/textures/block/cottonplant2.png differ diff --git a/src/main/resources/assets/quickly/textures/block/cottonplant3.png b/src/main/resources/assets/quickly/textures/block/cottonplant3.png new file mode 100644 index 0000000..6ce03a4 Binary files /dev/null and b/src/main/resources/assets/quickly/textures/block/cottonplant3.png differ diff --git a/src/main/resources/assets/quickly/textures/block/cottonplant4.png b/src/main/resources/assets/quickly/textures/block/cottonplant4.png new file mode 100644 index 0000000..81cd078 Binary files /dev/null and b/src/main/resources/assets/quickly/textures/block/cottonplant4.png differ diff --git a/src/main/resources/assets/quickly/textures/block/cottonplant5.png b/src/main/resources/assets/quickly/textures/block/cottonplant5.png new file mode 100644 index 0000000..677923b Binary files /dev/null and b/src/main/resources/assets/quickly/textures/block/cottonplant5.png differ diff --git a/src/main/resources/assets/quickly/textures/block/cottonplant6.png b/src/main/resources/assets/quickly/textures/block/cottonplant6.png new file mode 100644 index 0000000..c8cacf4 Binary files /dev/null and b/src/main/resources/assets/quickly/textures/block/cottonplant6.png differ diff --git a/src/main/resources/assets/quickly/textures/block/cottonplant7.png b/src/main/resources/assets/quickly/textures/block/cottonplant7.png new file mode 100644 index 0000000..4a296a1 Binary files /dev/null and b/src/main/resources/assets/quickly/textures/block/cottonplant7.png differ diff --git a/src/main/resources/assets/quickly/textures/item/cotton.png b/src/main/resources/assets/quickly/textures/item/cotton.png new file mode 100644 index 0000000..c52801c Binary files /dev/null and b/src/main/resources/assets/quickly/textures/item/cotton.png differ diff --git a/src/main/resources/assets/quickly/textures/item/cottonseed.png b/src/main/resources/assets/quickly/textures/item/cottonseed.png new file mode 100644 index 0000000..935d677 Binary files /dev/null and b/src/main/resources/assets/quickly/textures/item/cottonseed.png differ diff --git a/src/main/resources/data/quickly/recipe/shaped_string_from_cotton.json b/src/main/resources/data/quickly/recipe/shaped_string_from_cotton.json new file mode 100644 index 0000000..f866111 --- /dev/null +++ b/src/main/resources/data/quickly/recipe/shaped_string_from_cotton.json @@ -0,0 +1,15 @@ +{ + "type": "minecraft:crafting_shaped", + "pattern": [ + "c", + "c", + "c" + ], + "key": { + "c": "quickly:cotton" + }, + "result": { + "id": "minecraft:string", + "count": 1 + } +} \ No newline at end of file