mostly done, but still null for some references
@@ -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();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
64
src/main/java/de/jottyfan/minecraft/block/BlockPlant.java
Normal 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;
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
41
src/main/java/de/jottyfan/minecraft/item/Plant.java
Normal 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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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" }
|
||||
}
|
||||
}
|
||||
6
src/main/resources/assets/quickly/items/cotton.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"model": {
|
||||
"type": "minecraft:model",
|
||||
"model": "quickly:item/cotton"
|
||||
}
|
||||
}
|
||||
6
src/main/resources/assets/quickly/items/cottonplant.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"model": {
|
||||
"type": "minecraft:model",
|
||||
"model": "quickly:item/cottonseed"
|
||||
}
|
||||
}
|
||||
6
src/main/resources/assets/quickly/items/cottonseed.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"model": {
|
||||
"type": "minecraft:model",
|
||||
"model": "quickly:item/cottonseed"
|
||||
}
|
||||
}
|
||||
@@ -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",
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"parent":"block/cross",
|
||||
"textures":{
|
||||
"cross":"quickly:block/cottonplant0"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"parent":"block/cross",
|
||||
"textures":{
|
||||
"cross":"quickly:block/cottonplant1"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"parent":"block/cross",
|
||||
"textures":{
|
||||
"cross":"quickly:block/cottonplant2"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"parent":"block/cross",
|
||||
"textures":{
|
||||
"cross":"quickly:block/cottonplant3"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"parent":"block/cross",
|
||||
"textures":{
|
||||
"cross":"quickly:block/cottonplant4"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"parent":"block/cross",
|
||||
"textures":{
|
||||
"cross":"quickly:block/cottonplant5"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"parent":"block/cross",
|
||||
"textures":{
|
||||
"cross":"quickly:block/cottonplant6"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"parent":"block/cross",
|
||||
"textures":{
|
||||
"cross":"quickly:block/cottonplant7"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"parent": "item/generated",
|
||||
"textures": {
|
||||
"layer0": "quickly:item/cotton"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"parent": "item/generated",
|
||||
"textures": {
|
||||
"layer0": "quickly:item/cottonplant"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"parent": "item/generated",
|
||||
"textures": {
|
||||
"layer0": "quickly:item/cottonseed"
|
||||
}
|
||||
}
|
||||
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 1.2 KiB |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 5.4 KiB |
|
After Width: | Height: | Size: 5.6 KiB |
|
After Width: | Height: | Size: 5.7 KiB |
|
After Width: | Height: | Size: 6.2 KiB |
|
After Width: | Height: | Size: 2.1 KiB |
BIN
src/main/resources/assets/quickly/textures/item/cotton.png
Normal file
|
After Width: | Height: | Size: 2.3 KiB |
BIN
src/main/resources/assets/quickly/textures/item/cottonseed.png
Normal file
|
After Width: | Height: | Size: 1.7 KiB |
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"type": "minecraft:crafting_shaped",
|
||||
"pattern": [
|
||||
"c",
|
||||
"c",
|
||||
"c"
|
||||
],
|
||||
"key": {
|
||||
"c": "quickly:cotton"
|
||||
},
|
||||
"result": {
|
||||
"id": "minecraft:string",
|
||||
"count": 1
|
||||
}
|
||||
}
|
||||