Created
May 18, 2020 17:08
-
-
Save BoogieMonster1O1/f56e5368cf5167a6452e741c5586ad87 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import net.minecraft.block.Block; | |
import net.minecraft.block.BlockState; | |
import net.minecraft.entity.LivingEntity; | |
import net.minecraft.item.ItemStack; | |
import net.minecraft.state.property.IntProperty; | |
import net.minecraft.util.math.BlockPos; | |
import net.minecraft.world.IWorld; | |
import net.minecraft.world.World; | |
import static io.github.boogiemonster1o1.ner.Elements.BlockS.POLISHED_LIMESTONE_COLUMN; | |
import static net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings.copy; | |
import static net.minecraft.block.Blocks.STONE_SLAB; | |
public class PolishedLimestoneColumnBlock extends ColumnBlock{ | |
private static IntProperty TYPE = IntProperty.of("type",0,3); | |
public PolishedLimestoneColumnBlock() { | |
super(copy(STONE_SLAB)); | |
} | |
@Override | |
public void onPlaced(World world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack itemStack) { | |
BlockState def = world.getBlockState(pos); | |
int defA = def.get(TYPE); | |
BlockPos below = pos.down(1); | |
BlockPos above = pos.up(1); | |
Block aboveBlock = world.getBlockState(above).getBlock(); | |
Block belowBlock = world.getBlockState(below).getBlock(); | |
if(aboveBlock == POLISHED_LIMESTONE_COLUMN && belowBlock == POLISHED_LIMESTONE_COLUMN){ | |
world.setBlockState(pos,def.with(TYPE,2)); | |
} | |
else if(aboveBlock == POLISHED_LIMESTONE_COLUMN && belowBlock != POLISHED_LIMESTONE_COLUMN){ | |
world.setBlockState(pos,def.with(TYPE,1)); | |
} | |
else if(belowBlock == POLISHED_LIMESTONE_COLUMN && aboveBlock != POLISHED_LIMESTONE_COLUMN){ | |
world.setBlockState(pos,def.with(TYPE,3)); | |
} | |
} | |
@Override | |
public void onBroken(IWorld world, BlockPos pos, BlockState state){ | |
BlockPos below = pos.down(1); | |
BlockPos above = pos.up(1); | |
BlockState belowState = world.getBlockState(below); | |
BlockState aboveState = world.getBlockState(above); | |
Block belowBlock = belowState.getBlock(); | |
Block aboveBlock = aboveState.getBlock(); | |
if(aboveBlock == POLISHED_LIMESTONE_COLUMN){ | |
BlockPos aboveAbove = above.up(1); | |
BlockState aboveAboveState = world.getBlockState(aboveAbove); | |
Block aboveAboveBlock = aboveAboveState.getBlock(); | |
if(aboveAboveBlock == POLISHED_LIMESTONE_COLUMN){ | |
world.setBlockState(aboveAbove,aboveAboveState.with(TYPE,2),0); | |
} | |
else world.setBlockState(aboveAbove,aboveAboveState.with(TYPE,0),0); | |
} | |
if(belowBlock == POLISHED_LIMESTONE_COLUMN){ | |
BlockPos belowBelow = below.down(1); | |
BlockState belowBelowState = world.getBlockState(belowBelow); | |
Block belowBelowBlock = belowBelowState.getBlock(); | |
if(belowBelowBlock == POLISHED_LIMESTONE_COLUMN){ | |
world.setBlockState(belowBelow,belowBelowState.with(TYPE,3),0); | |
} | |
else world.setBlockState(belowBelow,belowBelowState.with(TYPE,0),0); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment