This commit is contained in:
@@ -1,9 +1,13 @@
|
||||
package de.jottyfan.minecraft;
|
||||
|
||||
import de.jottyfan.minecraft.block.ModBlocks;
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
import net.fabricmc.fabric.api.client.rendering.v1.BlockRenderLayerMap;
|
||||
import net.minecraft.client.render.BlockRenderLayer;
|
||||
|
||||
public class GtamfmdClient implements ClientModInitializer {
|
||||
@Override
|
||||
public void onInitializeClient() {
|
||||
BlockRenderLayerMap.putBlock(ModBlocks.CHRISTMASTREE, BlockRenderLayer.CUTOUT);
|
||||
}
|
||||
}
|
||||
|
||||
39
src/main/java/de/jottyfan/minecraft/block/ChristmasTree.java
Normal file
39
src/main/java/de/jottyfan/minecraft/block/ChristmasTree.java
Normal file
@@ -0,0 +1,39 @@
|
||||
package de.jottyfan.minecraft.block;
|
||||
|
||||
import de.jottyfan.minecraft.item.ModItems;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.SweetBerryBushBlock;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldView;
|
||||
import net.minecraft.world.event.GameEvent;
|
||||
|
||||
public class ChristmasTree extends SweetBerryBushBlock {
|
||||
|
||||
public ChristmasTree(Settings settings) {
|
||||
super(settings);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ItemStack getPickStack(WorldView world, BlockPos pos, BlockState state, boolean includeData) {
|
||||
return new ItemStack(ModItems.GINGERBREAD);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit) {
|
||||
if (state.get(AGE) > 1) {
|
||||
dropStack(world, pos, new ItemStack(ModItems.GINGERBREAD));
|
||||
BlockState blockState = state.with(AGE, 1);
|
||||
world.setBlockState(pos, blockState, Block.NOTIFY_LISTENERS);
|
||||
world.emitGameEvent(GameEvent.BLOCK_CHANGE, pos, GameEvent.Emitter.of(player, blockState));
|
||||
return ActionResult.SUCCESS;
|
||||
} else {
|
||||
return super.onUse(state, world, pos, player, hit);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,11 @@
|
||||
package de.jottyfan.minecraft.block;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
import de.jottyfan.minecraft.Gtamfmd;
|
||||
import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents;
|
||||
import net.minecraft.block.AbstractBlock;
|
||||
import net.minecraft.block.AbstractBlock.Settings;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.BlockItem;
|
||||
import net.minecraft.item.Item;
|
||||
@@ -20,10 +23,20 @@ public class ModBlocks {
|
||||
AbstractBlock.Settings.create().strength(4f).requiresTool().sounds(BlockSoundGroup.AMETHYST_BLOCK));
|
||||
public static final Block RUBY_ORE = registerBlock(Identifier.of(Gtamfmd.MOD_ID, "ruby_ore"),
|
||||
AbstractBlock.Settings.create().strength(4f).requiresTool());
|
||||
public static final Block CHRISTMASTREE = registerSpecialBlock(Identifier.of(Gtamfmd.MOD_ID, "christmastree"),
|
||||
AbstractBlock.Settings.create().ticksRandomly().noCollision().luminance(state -> 15),
|
||||
x -> new ChristmasTree(x));
|
||||
|
||||
// functional interface
|
||||
private static Block registerSpecialBlock(Identifier identifier, Settings settings, Function<Settings, Block> function) {
|
||||
Block block = function.apply(settings.registryKey(RegistryKey.of(RegistryKeys.BLOCK, identifier)));
|
||||
registerBlockItem(identifier, block, new Item.Settings());
|
||||
return Registry.register(Registries.BLOCK, identifier, block);
|
||||
}
|
||||
|
||||
private static Block registerBlock(Identifier identifier, Block.Settings settings) {
|
||||
Block block = new Block(settings.registryKey(RegistryKey.of(RegistryKeys.BLOCK, identifier)));
|
||||
registerBlockItem(identifier, block, new Item.Settings());
|
||||
registerBlockItem(identifier, block, new Item.Settings());
|
||||
return Registry.register(Registries.BLOCK, identifier, block);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,9 +4,11 @@ import java.util.Map;
|
||||
|
||||
import org.joml.Random;
|
||||
|
||||
import de.jottyfan.minecraft.block.ModBlocks;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.entity.ItemEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ItemUsageContext;
|
||||
@@ -14,6 +16,7 @@ import net.minecraft.item.Items;
|
||||
import net.minecraft.sound.SoundCategory;
|
||||
import net.minecraft.sound.SoundEvents;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
@@ -45,6 +48,17 @@ public class StubItem extends Item {
|
||||
world.spawnEntity(entity);
|
||||
}
|
||||
}
|
||||
} else if (Blocks.DIRT.equals(clickedBlock) && world.getBlockState(pos.up()).isAir()) {
|
||||
if (!world.isClient()) {
|
||||
world.setBlockState(pos.up(), ModBlocks.CHRISTMASTREE.getDefaultState());
|
||||
world.playSound(null, pos, SoundEvents.ITEM_CROP_PLANT,
|
||||
SoundCategory.BLOCKS);
|
||||
Hand hand = context.getHand();
|
||||
PlayerEntity player = context.getPlayer();
|
||||
ItemStack stack = player.getStackInHand(hand);
|
||||
stack.increment(-1);
|
||||
player.setStackInHand(hand, stack);
|
||||
}
|
||||
}
|
||||
return ActionResult.SUCCESS;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"variants": {
|
||||
"age=0": { "model": "gtamfmd:block/christmastree0" },
|
||||
"age=1": { "model": "gtamfmd:block/christmastree1" },
|
||||
"age=2": { "model": "gtamfmd:block/christmastree2" },
|
||||
"age=3": { "model": "gtamfmd:block/christmastree3" }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,5 +3,6 @@
|
||||
"item.gtamfmd.stub": "Stummel",
|
||||
"item.gtamfmd.ruby": "Rubin",
|
||||
"item.gtamfmd.ruby_block": "Rubinblock",
|
||||
"item.gtamfmd.ruby_ore": "Rubinerz"
|
||||
"item.gtamfmd.ruby_ore": "Rubinerz",
|
||||
"item.gtamfmd.christmastree": "Weihnachtsbaum"
|
||||
}
|
||||
|
||||
@@ -3,5 +3,6 @@
|
||||
"item.gtamfmd.stub": "Stub",
|
||||
"item.gtamfmd.ruby": "Ruby",
|
||||
"item.gtamfmd.ruby_block": "Ruby block",
|
||||
"item.gtamfmd.ruby_ore": "Ruby ore"
|
||||
"item.gtamfmd.ruby_ore": "Ruby ore",
|
||||
"item.gtamfmd.christmastree": "Christmas tree"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"parent": "minecraft:block/cross",
|
||||
"textures": {
|
||||
"cross": "gtamfmd:block/christmastree0"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"parent": "minecraft:block/cross",
|
||||
"textures": {
|
||||
"cross": "gtamfmd:block/christmastree1"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"parent": "minecraft:block/cross",
|
||||
"textures": {
|
||||
"cross": "gtamfmd:block/christmastree2"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"parent": "minecraft:block/cross",
|
||||
"textures": {
|
||||
"cross": "gtamfmd:block/christmastree3"
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 295 B |
Binary file not shown.
|
After Width: | Height: | Size: 542 B |
Binary file not shown.
|
After Width: | Height: | Size: 543 B |
Binary file not shown.
|
After Width: | Height: | Size: 580 B |
Reference in New Issue
Block a user