added first block kelpbundle
This commit is contained in:
@@ -17,6 +17,6 @@ public class Quickly implements ModInitializer {
|
||||
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
LOGGER.info("Hello Fabric world!");
|
||||
LOGGER.info("loading {}", MOD_ID);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package de.jottyfan.minecraft;
|
||||
|
||||
import de.jottyfan.minecraft.block.QuicklyBlocks;
|
||||
import de.jottyfan.minecraft.item.QuicklyItems;
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
|
||||
@@ -13,5 +14,6 @@ public class QuicklyClient implements ClientModInitializer {
|
||||
@Override
|
||||
public void onInitializeClient() {
|
||||
QuicklyItems.registerModItems();
|
||||
QuicklyBlocks.registerModBlocks();
|
||||
}
|
||||
}
|
||||
|
||||
47
src/main/java/de/jottyfan/minecraft/block/QuicklyBlocks.java
Normal file
47
src/main/java/de/jottyfan/minecraft/block/QuicklyBlocks.java
Normal file
@@ -0,0 +1,47 @@
|
||||
package de.jottyfan.minecraft.block;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
import de.jottyfan.minecraft.Quickly;
|
||||
import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
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.SoundType;
|
||||
import net.minecraft.world.level.block.state.BlockBehaviour.Properties;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author jotty
|
||||
*
|
||||
*/
|
||||
public class QuicklyBlocks {
|
||||
public static final Block KELPBUNDLE = registerBlock("kelpbundle",
|
||||
Properties.of().instabreak().sound(SoundType.WET_GRASS).strength(0.1f).friction(0.95f), p -> new Block(p));
|
||||
|
||||
private static final Block registerBlock(String name, Properties properties, Function<Properties, Block> function) {
|
||||
Identifier identifier = Identifier.fromNamespaceAndPath(Quickly.MOD_ID, name);
|
||||
|
||||
ResourceKey<Block> blockResourceKey = ResourceKey.create(Registries.BLOCK, identifier);
|
||||
Block block = function.apply(properties.setId(blockResourceKey));
|
||||
Registry.register(BuiltInRegistries.BLOCK, identifier, block);
|
||||
|
||||
ResourceKey<Item> itemResourceKey = ResourceKey.create(Registries.ITEM, identifier);
|
||||
BlockItem blockItem = new BlockItem(block, new Item.Properties().setId(itemResourceKey).modelId(identifier).useItemDescriptionPrefix());
|
||||
Registry.register(BuiltInRegistries.ITEM, identifier, blockItem);
|
||||
|
||||
return block;
|
||||
}
|
||||
|
||||
public static void registerModBlocks() {
|
||||
ItemGroupEvents.modifyEntriesEvent(CreativeModeTabs.BUILDING_BLOCKS).register(block -> {
|
||||
block.accept(KELPBUNDLE);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -19,18 +19,18 @@ import net.minecraft.world.item.Item.Properties;
|
||||
*
|
||||
*/
|
||||
public class QuicklyItems {
|
||||
public static final Item MY_ITEM = registerItem("stub", new Item.Properties(), p -> new Stub(p));
|
||||
public static final Item STUB = registerItem("stub", new Item.Properties(), p -> new Stub(p));
|
||||
|
||||
private static final Item registerItem(String name, Item.Properties properties, Function<Properties, Item> function) {
|
||||
Identifier identifier = Identifier.fromNamespaceAndPath(Quickly.MOD_ID, name);
|
||||
ResourceKey<Item> rc = ResourceKey.create(Registries.ITEM, identifier);
|
||||
Item i = function.apply(properties.setId(rc).modelId(identifier).useItemDescriptionPrefix());
|
||||
return Registry.register(BuiltInRegistries.ITEM, identifier, i);
|
||||
ResourceKey<Item> itemResourceKey = ResourceKey.create(Registries.ITEM, identifier);
|
||||
Item item = function.apply(properties.setId(itemResourceKey).modelId(identifier).useItemDescriptionPrefix());
|
||||
return Registry.register(BuiltInRegistries.ITEM, identifier, item);
|
||||
}
|
||||
|
||||
public static void registerModItems() {
|
||||
ItemGroupEvents.modifyEntriesEvent(CreativeModeTabs.TOOLS_AND_UTILITIES).register(i -> {
|
||||
i.accept(MY_ITEM);
|
||||
ItemGroupEvents.modifyEntriesEvent(CreativeModeTabs.TOOLS_AND_UTILITIES).register(item -> {
|
||||
item.accept(STUB);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package de.jottyfan.minecraft.item;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
import de.jottyfan.minecraft.block.QuicklyBlocks;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
@@ -16,7 +17,19 @@ import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
|
||||
public class Stub extends Item {
|
||||
/**
|
||||
*
|
||||
* @author jotty
|
||||
*
|
||||
*/
|
||||
public class Stub extends Item {
|
||||
|
||||
// @formatter:off
|
||||
private static final Map<Block, Item> SLASH_MAP = Map.of(
|
||||
Blocks.HAY_BLOCK, Items.WHEAT,
|
||||
Blocks.DRIED_KELP_BLOCK, Items.DRIED_KELP,
|
||||
QuicklyBlocks.KELPBUNDLE, Items.KELP);
|
||||
// @formatter:on
|
||||
|
||||
public Stub(Properties properties) {
|
||||
super(properties.stacksTo(64));
|
||||
@@ -24,12 +37,6 @@ public class Stub extends Item {
|
||||
|
||||
@Override
|
||||
public InteractionResult useOn(UseOnContext context) {
|
||||
Map<Block, Item> SLASH_MAP = Map.of(
|
||||
Blocks.HAY_BLOCK, Items.WHEAT,
|
||||
Blocks.DRIED_KELP_BLOCK, Items.DRIED_KELP);
|
||||
// ,
|
||||
// ModBlocks.BLOCK_KELPSTACK, Items.KELP);
|
||||
|
||||
Level level = context.getLevel();
|
||||
BlockPos pos = context.getClickedPos();
|
||||
Block clickedBlock = level.getBlockState(pos).getBlock();
|
||||
@@ -41,9 +48,8 @@ public class Stub extends Item {
|
||||
ItemStack stack = new ItemStack(SLASH_MAP.get(clickedBlock));
|
||||
float xScatter = new Random().nextFloat();
|
||||
float yScatter = new Random().nextFloat();
|
||||
ItemEntity entity = new ItemEntity(level, pos.getX(), pos.getY(), pos.getZ(),
|
||||
stack, xScatter, yScatter, 0.2);
|
||||
level.addFreshEntity(entity);
|
||||
ItemEntity entity = new ItemEntity(level, pos.getX(), pos.getY(), pos.getZ(), stack, xScatter, yScatter, 0.2);
|
||||
level.addFreshEntity(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user