Umbrella moss
This commit is contained in:
parent
ba4bc366c8
commit
e3a20b4b80
18 changed files with 857 additions and 0 deletions
9
src/main/java/ru/betterend/blocks/BlockUmbrellaMoss.java
Normal file
9
src/main/java/ru/betterend/blocks/BlockUmbrellaMoss.java
Normal file
|
@ -0,0 +1,9 @@
|
|||
package ru.betterend.blocks;
|
||||
|
||||
import ru.betterend.blocks.basis.BlockPlant;
|
||||
|
||||
public class BlockUmbrellaMoss extends BlockPlant {
|
||||
public BlockUmbrellaMoss() {
|
||||
super(12);
|
||||
}
|
||||
}
|
44
src/main/java/ru/betterend/blocks/BlockUmbrellaMossTall.java
Normal file
44
src/main/java/ru/betterend/blocks/BlockUmbrellaMossTall.java
Normal file
|
@ -0,0 +1,44 @@
|
|||
package ru.betterend.blocks;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.ItemEntity;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.state.StateManager;
|
||||
import net.minecraft.state.property.IntProperty;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import ru.betterend.blocks.basis.BlockDoublePlant;
|
||||
import ru.betterend.registry.BlockRegistry;
|
||||
import ru.betterend.util.BlocksHelper;
|
||||
|
||||
public class BlockUmbrellaMossTall extends BlockDoublePlant {
|
||||
public static final IntProperty ROTATION = IntProperty.of("rotation", 0, 3);
|
||||
|
||||
public BlockUmbrellaMossTall() {
|
||||
super(12);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void grow(ServerWorld world, Random random, BlockPos pos, BlockState state) {
|
||||
ItemEntity item = new ItemEntity(world, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, new ItemStack(BlockRegistry.UMBRELLA_MOSS));
|
||||
world.spawnEntity(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlaced(World world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack itemStack) {
|
||||
int rot = world.random.nextInt(4);
|
||||
BlocksHelper.setWithoutUpdate(world, pos, this.getDefaultState().with(ROTATION, rot));
|
||||
BlocksHelper.setWithoutUpdate(world, pos.up(), this.getDefaultState().with(ROTATION, rot).with(TOP, true));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void appendProperties(StateManager.Builder<Block, BlockState> stateManager) {
|
||||
super.appendProperties(stateManager);
|
||||
stateManager.add(ROTATION);
|
||||
}
|
||||
}
|
143
src/main/java/ru/betterend/blocks/basis/BlockDoublePlant.java
Normal file
143
src/main/java/ru/betterend/blocks/basis/BlockDoublePlant.java
Normal file
|
@ -0,0 +1,143 @@
|
|||
package ru.betterend.blocks.basis;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
|
||||
import net.minecraft.block.AbstractBlock;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.block.Fertilizable;
|
||||
import net.minecraft.block.Material;
|
||||
import net.minecraft.block.ShapeContext;
|
||||
import net.minecraft.enchantment.EnchantmentHelper;
|
||||
import net.minecraft.enchantment.Enchantments;
|
||||
import net.minecraft.entity.ItemEntity;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.loot.context.LootContext;
|
||||
import net.minecraft.loot.context.LootContextParameters;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.sound.BlockSoundGroup;
|
||||
import net.minecraft.state.StateManager;
|
||||
import net.minecraft.state.property.BooleanProperty;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.shape.VoxelShape;
|
||||
import net.minecraft.world.BlockView;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldAccess;
|
||||
import net.minecraft.world.WorldView;
|
||||
import ru.betterend.client.ERenderLayer;
|
||||
import ru.betterend.client.IRenderTypeable;
|
||||
import ru.betterend.registry.BlockTagRegistry;
|
||||
import ru.betterend.util.BlocksHelper;
|
||||
|
||||
public class BlockDoublePlant extends BlockBaseNotFull implements IRenderTypeable, Fertilizable {
|
||||
private static final VoxelShape SHAPE = Block.createCuboidShape(4, 2, 4, 12, 16, 12);
|
||||
public static final BooleanProperty TOP = BooleanProperty.of("top");
|
||||
|
||||
public BlockDoublePlant() {
|
||||
super(FabricBlockSettings.of(Material.REPLACEABLE_PLANT)
|
||||
.breakByTool(FabricToolTags.SHEARS)
|
||||
.sounds(BlockSoundGroup.WET_GRASS)
|
||||
.breakByHand(true)
|
||||
.noCollision());
|
||||
this.setDefaultState(this.stateManager.getDefaultState().with(TOP, false));
|
||||
}
|
||||
|
||||
public BlockDoublePlant(int light) {
|
||||
super(FabricBlockSettings.of(Material.REPLACEABLE_PLANT)
|
||||
.breakByTool(FabricToolTags.SHEARS)
|
||||
.sounds(BlockSoundGroup.WET_GRASS)
|
||||
.lightLevel((state) -> { return state.get(TOP) ? light : 0; })
|
||||
.breakByHand(true)
|
||||
.noCollision());
|
||||
this.setDefaultState(this.stateManager.getDefaultState().with(TOP, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void appendProperties(StateManager.Builder<Block, BlockState> stateManager) {
|
||||
stateManager.add(TOP);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ePos) {
|
||||
Vec3d vec3d = state.getModelOffset(view, pos);
|
||||
return SHAPE.offset(vec3d.x, vec3d.y, vec3d.z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractBlock.OffsetType getOffsetType() {
|
||||
return AbstractBlock.OffsetType.XZ;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
|
||||
BlockState down = world.getBlockState(pos.down());
|
||||
BlockState up = world.getBlockState(pos.up());
|
||||
return state.get(TOP) ? down.getBlock() == this : down.isIn(BlockTagRegistry.END_GROUND) && (up.getMaterial().isReplaceable());
|
||||
}
|
||||
|
||||
public boolean canStayAt(BlockState state, WorldView world, BlockPos pos) {
|
||||
BlockState down = world.getBlockState(pos.down());
|
||||
BlockState up = world.getBlockState(pos.up());
|
||||
return state.get(TOP) ? down.getBlock() == this : down.isIn(BlockTagRegistry.END_GROUND) && (up.getBlock() == this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getStateForNeighborUpdate(BlockState state, Direction facing, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
|
||||
if (!canStayAt(state, world, pos)) {
|
||||
return Blocks.AIR.getDefaultState();
|
||||
}
|
||||
else {
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getDroppedStacks(BlockState state, LootContext.Builder builder) {
|
||||
if (state.get(TOP)) {
|
||||
return Lists.newArrayList();
|
||||
}
|
||||
|
||||
ItemStack tool = builder.get(LootContextParameters.TOOL);
|
||||
if (tool != null && tool.getItem().isIn(FabricToolTags.SHEARS) || EnchantmentHelper.getLevel(Enchantments.SILK_TOUCH, tool) > 0) {
|
||||
return Lists.newArrayList(new ItemStack(this));
|
||||
}
|
||||
else {
|
||||
return Lists.newArrayList();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ERenderLayer getRenderLayer() {
|
||||
return ERenderLayer.CUTOUT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFertilizable(BlockView world, BlockPos pos, BlockState state, boolean isClient) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canGrow(World world, Random random, BlockPos pos, BlockState state) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void grow(ServerWorld world, Random random, BlockPos pos, BlockState state) {
|
||||
ItemEntity item = new ItemEntity(world, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, new ItemStack(this));
|
||||
world.spawnEntity(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlaced(World world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack itemStack) {
|
||||
BlocksHelper.setWithoutUpdate(world, pos.up(), this.getDefaultState().with(TOP, true));
|
||||
}
|
||||
}
|
115
src/main/java/ru/betterend/blocks/basis/BlockPlant.java
Normal file
115
src/main/java/ru/betterend/blocks/basis/BlockPlant.java
Normal file
|
@ -0,0 +1,115 @@
|
|||
package ru.betterend.blocks.basis;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
|
||||
import net.minecraft.block.AbstractBlock;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.block.Fertilizable;
|
||||
import net.minecraft.block.Material;
|
||||
import net.minecraft.block.ShapeContext;
|
||||
import net.minecraft.enchantment.EnchantmentHelper;
|
||||
import net.minecraft.enchantment.Enchantments;
|
||||
import net.minecraft.entity.ItemEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.loot.context.LootContext;
|
||||
import net.minecraft.loot.context.LootContextParameters;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.sound.BlockSoundGroup;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.util.shape.VoxelShape;
|
||||
import net.minecraft.world.BlockView;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldAccess;
|
||||
import net.minecraft.world.WorldView;
|
||||
import ru.betterend.client.ERenderLayer;
|
||||
import ru.betterend.client.IRenderTypeable;
|
||||
import ru.betterend.registry.BlockTagRegistry;
|
||||
|
||||
public class BlockPlant extends BlockBaseNotFull implements IRenderTypeable, Fertilizable {
|
||||
private static final VoxelShape SHAPE = Block.createCuboidShape(4, 2, 4, 12, 14, 12);
|
||||
|
||||
public BlockPlant() {
|
||||
super(FabricBlockSettings.of(Material.REPLACEABLE_PLANT)
|
||||
.breakByTool(FabricToolTags.SHEARS)
|
||||
.sounds(BlockSoundGroup.GRASS)
|
||||
.breakByHand(true)
|
||||
.noCollision());
|
||||
}
|
||||
|
||||
public BlockPlant(int light) {
|
||||
super(FabricBlockSettings.of(Material.REPLACEABLE_PLANT)
|
||||
.breakByTool(FabricToolTags.SHEARS)
|
||||
.sounds(BlockSoundGroup.GRASS)
|
||||
.lightLevel(light)
|
||||
.breakByHand(true)
|
||||
.noCollision());
|
||||
}
|
||||
|
||||
@Override
|
||||
public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ePos) {
|
||||
Vec3d vec3d = state.getModelOffset(view, pos);
|
||||
return SHAPE.offset(vec3d.x, vec3d.y, vec3d.z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractBlock.OffsetType getOffsetType() {
|
||||
return AbstractBlock.OffsetType.XZ;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
|
||||
BlockState down = world.getBlockState(pos.down());
|
||||
return down.isIn(BlockTagRegistry.END_GROUND);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getStateForNeighborUpdate(BlockState state, Direction facing, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
|
||||
if (!canPlaceAt(state, world, pos)) {
|
||||
return Blocks.AIR.getDefaultState();
|
||||
}
|
||||
else {
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getDroppedStacks(BlockState state, LootContext.Builder builder) {
|
||||
ItemStack tool = builder.get(LootContextParameters.TOOL);
|
||||
if (tool != null && tool.getItem().isIn(FabricToolTags.SHEARS) || EnchantmentHelper.getLevel(Enchantments.SILK_TOUCH, tool) > 0) {
|
||||
return Lists.newArrayList(new ItemStack(this));
|
||||
}
|
||||
else {
|
||||
return Lists.newArrayList();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ERenderLayer getRenderLayer() {
|
||||
return ERenderLayer.CUTOUT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFertilizable(BlockView world, BlockPos pos, BlockState state, boolean isClient) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canGrow(World world, Random random, BlockPos pos, BlockState state) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void grow(ServerWorld world, Random random, BlockPos pos, BlockState state) {
|
||||
ItemEntity item = new ItemEntity(world, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, new ItemStack(this));
|
||||
world.spawnEntity(item);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue