Compare commits

..

4 Commits

Author SHA1 Message Date
jotty
3f874e62dc getting cotton seed from short grass works 2025-12-24 23:40:41 +01:00
Jottyfan
20d2adffc7 still no grass is found; source.isBuiltin seems not to be true 2025-12-24 14:01:08 +01:00
Jottyfan
5f1ec39715 plant and harvest works, but getting the first from grass does not yet 2025-12-24 13:35:04 +01:00
Jottyfan
f468cbe4cd mostly done, but still null for some references 2025-12-24 10:26:55 +01:00
34 changed files with 261 additions and 2 deletions

View File

@@ -7,7 +7,13 @@ 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.resources.Identifier;
import net.minecraft.world.level.storage.loot.LootPool;
import net.minecraft.world.level.storage.loot.entries.LootItem;
import net.minecraft.world.level.storage.loot.predicates.LootItemRandomChanceCondition;
import net.minecraft.world.level.storage.loot.providers.number.ConstantValue;
/**
*
* @author jotty
@@ -18,6 +24,30 @@ 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()) {
// TODO: maybe, better harvest cotton from dry grass instead?
Identifier shortGrass = Identifier.fromNamespaceAndPath("minecraft", "blocks/short_grass");
Identifier tallGrass = Identifier.fromNamespaceAndPath("minecraft", "blocks/tall_grass");
if (key.identifier().equals(shortGrass)) {
LootPool.Builder poolBuilder = LootPool.lootPool()
.setRolls(ConstantValue.exactly(1f))
.when(LootItemRandomChanceCondition.randomChance(0.1f))
.add(LootItem.lootTableItem(QuicklyItems.COTTONSEED));
tableBuilder.withPool(poolBuilder);
} else if (key.identifier().equals(tallGrass)) {
// for the canola loot table block later
}
}
});
}
@Override
public void onInitialize() {
LOGGER.info("loading {}", MOD_ID);
@@ -25,5 +55,8 @@ public class Quickly implements ModInitializer {
QuicklyItems.registerModItems();
QuicklyBlocks.registerModBlocks();
QuicklyFeatures.registerFeatures();
registerComposterItems();
registerLootTableChanges();
}
}

View File

@@ -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);
}
}

View File

@@ -0,0 +1,53 @@
package de.jottyfan.minecraft.block;
import de.jottyfan.minecraft.Quickly;
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.phys.BlockHitResult;
/**
*
* @author jotty
*
*/
public class BlockPlant extends CropBlock {
private String seedName;
private String fruitName;
public BlockPlant(Properties properties, String seedName, String fruitName) {
super(properties);
this.seedName = seedName;
this.fruitName = fruitName;
}
public Item getSeed() {
return BuiltInRegistries.ITEM.getValue(Identifier.fromNamespaceAndPath(Quickly.MOD_ID, seedName));
}
public Item getFruit() {
return BuiltInRegistries.ITEM.getValue(Identifier.fromNamespaceAndPath(Quickly.MOD_ID, fruitName));
}
@Override
protected InteractionResult useWithoutItem(BlockState state, Level level, BlockPos pos, Player player,
BlockHitResult hitResult) {
if (!level.isClientSide() && isMaxAge(state)) {
int fruitAmount = (level.getRandom().nextFloat() > 0.9f) ? 2 : 1;
Containers.dropItemStack(level, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(getFruit(), fruitAmount));
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;
}
}

View File

@@ -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, "cottonseed", "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);
});
}
}

View File

@@ -0,0 +1,45 @@
package de.jottyfan.minecraft.item;
import de.jottyfan.minecraft.Quickly;
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 String plantName;
public Plant(Properties properties, String plantName) {
super(properties);
this.plantName = plantName;
}
private Block getPlant() {
return BuiltInRegistries.BLOCK.getValue(Identifier.fromNamespaceAndPath(Quickly.MOD_ID, plantName));
}
@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()) {
context.getLevel().setBlock(pos.above(), getPlant().defaultBlockState(), 2);
context.getItemInHand().shrink(1);
}
}
return super.useOn(context);
}
}

View File

@@ -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, "blockcottonplant"));
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);
});
}
}

View File

@@ -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" }
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "quickly:item/cotton"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "quickly:item/cottonseed"
}
}

View File

@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "quickly:item/cottonseed"
}
}

View File

@@ -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",

View File

@@ -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",

View File

@@ -0,0 +1,6 @@
{
"parent":"block/cross",
"textures":{
"cross":"quickly:block/cottonplant0"
}
}

View File

@@ -0,0 +1,6 @@
{
"parent":"block/cross",
"textures":{
"cross":"quickly:block/cottonplant1"
}
}

View File

@@ -0,0 +1,6 @@
{
"parent":"block/cross",
"textures":{
"cross":"quickly:block/cottonplant2"
}
}

View File

@@ -0,0 +1,6 @@
{
"parent":"block/cross",
"textures":{
"cross":"quickly:block/cottonplant3"
}
}

View File

@@ -0,0 +1,6 @@
{
"parent":"block/cross",
"textures":{
"cross":"quickly:block/cottonplant4"
}
}

View File

@@ -0,0 +1,6 @@
{
"parent":"block/cross",
"textures":{
"cross":"quickly:block/cottonplant5"
}
}

View File

@@ -0,0 +1,6 @@
{
"parent":"block/cross",
"textures":{
"cross":"quickly:block/cottonplant6"
}
}

View File

@@ -0,0 +1,6 @@
{
"parent":"block/cross",
"textures":{
"cross":"quickly:block/cottonplant7"
}
}

View File

@@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "quickly:item/cotton"
}
}

View File

@@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "quickly:item/cottonplant"
}
}

View File

@@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "quickly:item/cottonseed"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

@@ -0,0 +1,15 @@
{
"type": "minecraft:crafting_shaped",
"pattern": [
"c",
"c",
"c"
],
"key": {
"c": "quickly:cotton"
},
"result": {
"id": "minecraft:string",
"count": 1
}
}