use of net.minecraft.block.BlockState in project BluePower by Qmunity.
the class IOHelper method getInventoryForTE.
public static IInventory getInventoryForTE(TileEntity te) {
if (te instanceof IInventory) {
IInventory inv = (IInventory) te;
BlockState block = te.getBlockState();
if (block.getBlock() instanceof ChestBlock) {
inv = (IInventory) ((ChestBlock) block.getBlock()).getMenuProvider(block, te.getLevel(), te.getBlockPos());
}
return inv;
} else {
return null;
}
}
use of net.minecraft.block.BlockState in project BluePower by Qmunity.
the class BlockContainerFacingBase method setState.
public static void setState(boolean active, World worldIn, BlockPos pos) {
BlockState iblockstate = worldIn.getBlockState(pos);
TileEntity tileentity = worldIn.getBlockEntity(pos);
worldIn.setBlock(pos, iblockstate.setValue(ACTIVE, active), 3);
if (tileentity != null) {
tileentity.clearRemoved();
worldIn.setBlockEntity(pos, tileentity);
}
}
use of net.minecraft.block.BlockState in project BluePower by Qmunity.
the class RenderEngine method render.
@Override
public void render(TileEngine engine, float f, MatrixStack matrixStack, IRenderTypeBuffer iRenderTypeBuffer, int i, int i1) {
World world = engine.getLevel();
BlockRendererDispatcher dispatcher = Minecraft.getInstance().getBlockRenderer();
BlockPos pos = engine.getBlockPos();
BlockState state = BPBlocks.engine.defaultBlockState().setValue(BlockEngine.FACING, engine.getOrientation());
Direction facing = engine.getOrientation();
matrixStack.pushPose();
float rotationX = 90.0F;
float rotation = 0.0F;
if (facing == Direction.NORTH) {
matrixStack.translate(0, 1, 0);
rotation = 0F;
} else if (facing == Direction.SOUTH) {
matrixStack.translate(1, 1, 1);
rotation = 180F;
} else if (facing == Direction.EAST) {
matrixStack.translate(1, 1, 0);
rotation = 90F;
} else if (facing == Direction.WEST) {
matrixStack.translate(0, 1, 1);
rotation = -90F;
} else if (facing == Direction.UP) {
matrixStack.translate(0, 1, 1);
rotationX = 180F;
} else if (facing == Direction.DOWN) {
rotationX = 0F;
}
matrixStack.mulPose(Vector3f.XP.rotationDegrees(rotationX));
matrixStack.mulPose(Vector3f.ZP.rotationDegrees(rotation));
matrixStack.pushPose();
float f2 = 0;
if (engine.isActive) {
f += engine.pumpTick;
if (engine.pumpSpeed > 0) {
f /= engine.pumpSpeed;
}
f2 = ((float) (.5 - .5 * Math.cos(3.1415926535897931D * (double) f)) / 4);
}
matrixStack.translate(0, f2, 0);
IBakedModel glider = dispatcher.getBlockModel(state.setValue(BlockEngine.GLIDER, true));
// Render the glider
IVertexBuilder builder = iRenderTypeBuffer.getBuffer(RenderType.cutout());
dispatcher.getModelRenderer().renderModel(world, glider, state.setValue(BlockEngine.GLIDER, true), pos, matrixStack, builder, false, new Random(), 0, 0, EmptyModelData.INSTANCE);
matrixStack.popPose();
matrixStack.pushPose();
matrixStack.translate(0.5, 0, 0.5);
long angle = engine.isActive ? (System.currentTimeMillis() / 10) % 360 : 0;
matrixStack.mulPose(Vector3f.YP.rotationDegrees(angle));
matrixStack.translate(-0.5, 0, -0.5);
IBakedModel gear = dispatcher.getBlockModel(state.setValue(BlockEngine.GEAR, true));
// Render the rotating cog
dispatcher.getModelRenderer().renderModel(world, gear, state.setValue(BlockEngine.GEAR, true), pos, matrixStack, iRenderTypeBuffer.getBuffer(RenderType.cutout()), false, new Random(), 0, 0, EmptyModelData.INSTANCE);
matrixStack.popPose();
matrixStack.popPose();
}
use of net.minecraft.block.BlockState in project BluePower by Qmunity.
the class TileBPMicroblock method markDirtyClient.
private void markDirtyClient() {
setChanged();
if (getLevel() != null) {
BlockState state = getLevel().getBlockState(getBlockPos());
getLevel().sendBlockUpdated(getBlockPos(), state, state, 3);
}
}
use of net.minecraft.block.BlockState in project BluePower by Qmunity.
the class ItemSickle method mineBlock.
@Override
public boolean mineBlock(ItemStack stack, World world, BlockState state, BlockPos pos, LivingEntity entityLiving) {
boolean used = false;
if (!(entityLiving instanceof PlayerEntity))
return false;
PlayerEntity player = (PlayerEntity) entityLiving;
if (state.getBlock().getTags().contains(new ResourceLocation("minecraft:leaves")) || state.getBlock() instanceof LeavesBlock) {
for (int i = -1; i <= 1; i++) {
for (int j = -1; j <= 1; j++) {
for (int k = -1; k <= 1; k++) {
BlockState blockToCheck = world.getBlockState(pos.offset(i, j, k));
if (blockToCheck.getBlock().getTags().contains(new ResourceLocation("minecraft:leaves")) || blockToCheck.getBlock() instanceof LeavesBlock) {
if (blockToCheck.canHarvestBlock(world, pos.offset(i, j, k), player)) {
world.destroyBlock(pos.offset(i, j, k), true);
}
used = true;
}
}
}
}
if (used) {
stack.hurtAndBreak(1, player, (playerEntity) -> playerEntity.broadcastBreakEvent(EquipmentSlotType.MAINHAND));
}
return used;
}
if ((state.getBlock() instanceof LilyPadBlock)) {
for (int i = -2; i <= 2; i++) {
for (int j = -2; j <= 2; j++) {
Block blockToCheck = world.getBlockState(pos.offset(i, 0, j)).getBlock();
BlockState meta = world.getBlockState(pos.offset(i, 0, j));
if (blockToCheck instanceof LilyPadBlock) {
if (blockToCheck.canHarvestBlock(meta, world, pos.offset(i, 0, j), player)) {
world.destroyBlock(pos.offset(i, 0, j), true);
}
used = true;
}
}
}
}
if (!(state.getBlock() instanceof LilyPadBlock)) {
for (int i = -2; i <= 2; i++) {
for (int j = -2; j <= 2; j++) {
Block blockToCheck = world.getBlockState(pos.offset(i, 0, j)).getBlock();
if (blockToCheck instanceof BushBlock && !(blockToCheck instanceof LilyPadBlock)) {
if (blockToCheck.canHarvestBlock(world.getBlockState(pos.offset(i, 0, j)), world, pos.offset(i, 0, j), player)) {
world.destroyBlock(pos.offset(i, 0, j), true);
}
used = true;
}
}
}
}
if (used) {
stack.hurtAndBreak(1, player, (playerEntity) -> playerEntity.broadcastBreakEvent(EquipmentSlotType.MAINHAND));
}
return used;
}
Aggregations