mostly done, but still null for some references

This commit is contained in:
Jottyfan
2025-12-24 10:26:55 +01:00
parent 455f8f9f86
commit f468cbe4cd
34 changed files with 266 additions and 1 deletions

View File

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

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,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<ItemStack> getDrops(BlockState state, Builder builder) {
List<ItemStack> 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;
}
}

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

View File

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

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

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