Mosses, fixes

This commit is contained in:
paulevsGitch 2020-10-01 01:39:06 +03:00
parent 4eb7105e33
commit 72b173a9e3
28 changed files with 354 additions and 53 deletions

View file

@ -0,0 +1,30 @@
package ru.betterend.blocks;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.block.BlockState;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.BlockView;
import ru.betterend.blocks.basis.BlockPlant;
import ru.betterend.registry.BlockRegistry;
public class BlockGlowingMoss extends BlockPlant {
public BlockGlowingMoss(int light) {
super(light);
}
@Override
protected boolean isTerrain(BlockState state) {
return state.getBlock() == BlockRegistry.END_MOSS || state.getBlock() == BlockRegistry.END_MYCELIUM;
}
@Environment(EnvType.CLIENT)
public boolean hasEmissiveLighting(BlockView world, BlockPos pos) {
return true;
}
@Environment(EnvType.CLIENT)
public float getAmbientOcclusionLightLevel(BlockView world, BlockPos pos) {
return 1F;
}
}

View file

@ -1,9 +0,0 @@
package ru.betterend.blocks;
import ru.betterend.blocks.basis.BlockPlant;
public class BlockUmbrellaMoss extends BlockPlant {
public BlockUmbrellaMoss() {
super(12);
}
}

View file

@ -2,23 +2,15 @@ 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);
}
@ -30,15 +22,7 @@ public class BlockUmbrellaMossTall extends BlockDoublePlant {
}
@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);
protected boolean isTerrain(BlockState state) {
return state.getBlock() == BlockRegistry.END_MOSS || state.getBlock() == BlockRegistry.END_MYCELIUM;
}
}

View file

@ -25,6 +25,7 @@ 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.state.property.IntProperty;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Vec3d;
@ -40,6 +41,7 @@ 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 IntProperty ROTATION = IntProperty.of("rotation", 0, 3);
public static final BooleanProperty TOP = BooleanProperty.of("top");
public BlockDoublePlant() {
@ -63,7 +65,7 @@ public class BlockDoublePlant extends BlockBaseNotFull implements IRenderTypeabl
@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> stateManager) {
stateManager.add(TOP);
stateManager.add(TOP, ROTATION);
}
@Override
@ -81,15 +83,19 @@ public class BlockDoublePlant extends BlockBaseNotFull implements IRenderTypeabl
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());
return state.get(TOP) ? down.getBlock() == this : isTerrain(down) && (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);
return state.get(TOP) ? down.getBlock() == this : isTerrain(down) && (up.getBlock() == this);
}
protected boolean isTerrain(BlockState state) {
return state.isIn(BlockTagRegistry.END_GROUND);
}
@Override
public BlockState getStateForNeighborUpdate(BlockState state, Direction facing, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
if (!canStayAt(state, world, pos)) {
@ -138,6 +144,9 @@ public class BlockDoublePlant extends BlockBaseNotFull implements IRenderTypeabl
@Override
public void onPlaced(World world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack itemStack) {
BlocksHelper.setWithoutUpdate(world, pos.up(), this.getDefaultState().with(TOP, true));
int rot = world.random.nextInt(4);
BlockState bs = this.getDefaultState().with(ROTATION, rot);
BlocksHelper.setWithoutUpdate(world, pos, bs);
BlocksHelper.setWithoutUpdate(world, pos.up(), bs.with(TOP, true));
}
}

View file

@ -68,7 +68,11 @@ public class BlockPlant extends BlockBaseNotFull implements IRenderTypeable, Fer
@Override
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
BlockState down = world.getBlockState(pos.down());
return down.isIn(BlockTagRegistry.END_GROUND);
return isTerrain(down);
}
protected boolean isTerrain(BlockState state) {
return state.isIn(BlockTagRegistry.END_GROUND);
}
@Override