use of net.minecraft.block.BlockState in project BluePower by Qmunity.
the class ItemSeedBag method useOn.
@Override
public ActionResultType useOn(ItemUseContext context) {
PlayerEntity player = context.getPlayer();
World worldIn = context.getLevel();
Hand hand = context.getHand();
BlockPos pos = context.getClickedPos();
if (player.isCrouching()) {
return ActionResultType.PASS;
}
ItemStackHandler seedBagInvHandler = new ItemStackHandler(9);
// Get Active hand
Hand activeHand = Hand.MAIN_HAND;
ItemStack seedBag = player.getItemInHand(activeHand);
if (!(seedBag.getItem() instanceof ItemSeedBag)) {
seedBag = player.getOffhandItem();
activeHand = Hand.OFF_HAND;
}
// Get Items from the NBT Handler
if (seedBag.hasTag())
seedBagInvHandler.deserializeNBT(seedBag.getTag().getCompound("inv"));
ItemStack seed = getSeedType(player.getItemInHand(hand));
Block block = Block.byItem(seed.getItem());
if (!seed.isEmpty() && block instanceof IPlantable) {
IPlantable plant = (IPlantable) block;
BlockState b = worldIn.getBlockState(pos);
if (b.getBlock().canSustainPlant(b, worldIn, pos, Direction.UP, plant) && worldIn.isEmptyBlock(pos.relative(Direction.UP))) {
for (int i = 0; i < 9; i++) {
ItemStack is = seedBagInvHandler.getStackInSlot(i);
if (!is.isEmpty()) {
worldIn.setBlock(pos.relative(Direction.UP), block.defaultBlockState(), 0);
seedBagInvHandler.extractItem(i, 1, false);
break;
}
}
// Update items in the NBT
if (!seedBag.hasTag())
seedBag.setTag(new CompoundNBT());
if (seedBag.getTag() != null) {
seedBag.getTag().put("inv", seedBagInvHandler.serializeNBT());
}
return ActionResultType.SUCCESS;
}
}
return ActionResultType.PASS;
}
use of net.minecraft.block.BlockState in project BluePower by Qmunity.
the class ItemBPPart method place.
@Override
public ActionResultType place(BlockItemUseContext context) {
BlockState state = context.getLevel().getBlockState(context.getClickedPos());
BlockState thisState = getBlock().getStateForPlacement(context);
if (state.getBlock() instanceof IBPPartBlock && thisState != null && !AABBUtils.testOcclusion(((IBPPartBlock) thisState.getBlock()).getOcclusionShape(thisState), state.getShape(context.getLevel(), context.getClickedPos()))) {
// Save the Tile Entity Data
CompoundNBT nbt = new CompoundNBT();
TileEntity tileEntity = context.getLevel().getBlockEntity(context.getClickedPos());
if (tileEntity != null) {
nbt = tileEntity.save(nbt);
}
// Replace with Multipart
context.getLevel().setBlockAndUpdate(context.getClickedPos(), BPBlocks.multipart.defaultBlockState());
tileEntity = context.getLevel().getBlockEntity(context.getClickedPos());
if (tileEntity instanceof TileBPMultipart) {
// Add the original State to the Multipart
((TileBPMultipart) tileEntity).addState(state);
// Restore the Tile Entity Data
TileEntity tile = ((TileBPMultipart) tileEntity).getTileForState(state);
if (tile != null)
tile.load(state, nbt);
// Add the new State
((TileBPMultipart) tileEntity).addState(thisState);
thisState.getBlock().setPlacedBy(context.getLevel(), context.getClickedPos(), thisState, context.getPlayer(), context.getItemInHand());
}
// Update Self
state.neighborChanged(context.getLevel(), context.getClickedPos(), state.getBlock(), context.getClickedPos(), false);
context.getItemInHand().shrink(1);
// Place Sound
context.getLevel().playSound(null, context.getClickedPos(), SoundEvents.STONE_PLACE, SoundCategory.BLOCKS, 1.0F, 1.0F);
return ActionResultType.SUCCESS;
} else if (state.getBlock() instanceof BlockBPMultipart && thisState != null && !AABBUtils.testOcclusion(((IBPPartBlock) thisState.getBlock()).getOcclusionShape(thisState), state.getShape(context.getLevel(), context.getClickedPos()))) {
// Add to the Existing Multipart
TileEntity tileEntity = context.getLevel().getBlockEntity(context.getClickedPos());
if (tileEntity instanceof TileBPMultipart) {
((TileBPMultipart) tileEntity).addState(thisState);
thisState.getBlock().setPlacedBy(context.getLevel(), context.getClickedPos(), thisState, context.getPlayer(), context.getItemInHand());
// Update Neighbors
for (Direction dir : Direction.values()) {
context.getLevel().getBlockState(context.getClickedPos().relative(dir)).neighborChanged(context.getLevel(), context.getClickedPos().relative(dir), state.getBlock(), context.getClickedPos(), false);
}
// Update Self
state.neighborChanged(context.getLevel(), context.getClickedPos(), state.getBlock(), context.getClickedPos(), false);
context.getItemInHand().shrink(1);
// Place Sound
context.getLevel().playSound(null, context.getClickedPos(), SoundEvents.STONE_PLACE, SoundCategory.BLOCKS, 1.0F, 1.0F);
return ActionResultType.SUCCESS;
}
}
return super.place(context);
}
use of net.minecraft.block.BlockState in project BluePower by Qmunity.
the class BPMultipartModel method getQuads.
@Nonnull
@Override
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, @Nonnull Random rand, @Nonnull IModelData extraData) {
BlockRendererDispatcher brd = Minecraft.getInstance().getBlockRenderer();
Map<BlockState, IModelData> stateInfo = extraData.getData(TileBPMultipart.STATE_INFO);
if (stateInfo != null) {
return stateInfo.keySet().stream().flatMap(i -> brd.getBlockModel(i).getQuads(i, side, rand, stateInfo.get(i)).stream().map(q -> stateInfo.get(i).hasProperty(TileWire.COLOR_INFO) ? transform(q, stateInfo.get(i).getData(TileWire.COLOR_INFO), stateInfo.get(i).hasProperty(TileWire.LIGHT_INFO) ? stateInfo.get(i).getData(TileWire.LIGHT_INFO) : false) : q)).collect(Collectors.toList());
} else {
return Collections.emptyList();
}
}
use of net.minecraft.block.BlockState in project BluePower by Qmunity.
the class RenderLamp method render.
@Override
public void render(TileLamp te, float v, MatrixStack matrixStack, IRenderTypeBuffer iRenderTypeBuffer, int partialTicks, int destroyStage) {
if (// || Loader.isModLoaded("albedo"))
!(te.getBlockState().getBlock() instanceof BlockLamp))
return;
BlockState stateLamp = te.getBlockState();
BlockLamp bLamp = (BlockLamp) stateLamp.getBlock();
if (te.getLevel() == null) {
return;
}
int power = stateLamp.getValue(BlockLamp.POWER);
int color = bLamp.getColor(stateLamp, te.getLevel(), te.getBlockPos(), 0);
int redMask = 0xFF0000, greenMask = 0xFF00, blueMask = 0xFF;
int r = (color & redMask) >> 16;
int g = (color & greenMask) >> 8;
int b = (color & blueMask);
AxisAlignedBB box = stateLamp.getShape(te.getLevel(), te.getBlockPos()).bounds();
// Define our base Glow
box = box.equals(new AxisAlignedBB(0, 0, 0, 1, 1, 1)) ? box.inflate(0.05) : box.inflate(0.03125);
boolean[] renderFaces = new boolean[] { true, true, true, true, true, true };
// Remove overlapping Glow
if (stateLamp.getShape(te.getLevel(), te.getBlockPos()).bounds().equals(new AxisAlignedBB(0, 0, 0, 1, 1, 1))) {
for (Direction face : Direction.values()) {
BlockState state = te.getLevel().getBlockState(te.getBlockPos().relative(face.getOpposite()));
if (state.getBlock() instanceof BlockLamp && state.getShape(te.getLevel(), te.getBlockPos()).bounds().equals(new AxisAlignedBB(0, 0, 0, 1, 1, 1))) {
if (state.getValue(BlockLamp.POWER) > 0) {
renderFaces[face.get3DDataValue()] = false;
double offsetx = (face.getStepX() * 0.05) > 0 ? (face.getStepX() * 0.05) : 0;
double offsety = (face.getStepY() * 0.05) > 0 ? (face.getStepY() * 0.05) : 0;
double offsetz = (face.getStepZ() * 0.05) > 0 ? (face.getStepZ() * 0.05) : 0;
double toffsetx = (face.getStepX() * 0.05) < 0 ? (face.getStepX() * 0.05) : 0;
double toffsety = (face.getStepY() * 0.05) < 0 ? (face.getStepY() * 0.05) : 0;
double toffsetz = (face.getStepZ() * 0.05) < 0 ? (face.getStepZ() * 0.05) : 0;
box = new AxisAlignedBB(box.minX + offsetx, box.minY + offsety, box.minZ + offsetz, box.maxX + toffsetx, box.maxY + toffsety, box.maxZ + toffsetz);
}
}
}
}
matrixStack.pushPose();
double powerDivision = power / 18D;
com.bluepowermod.client.render.RenderHelper.drawColoredCube(box, iRenderTypeBuffer.getBuffer(BPRenderTypes.LAMP_GLOW), matrixStack, r, g, b, (int) (powerDivision * 200), 200, renderFaces);
matrixStack.popPose();
}
use of net.minecraft.block.BlockState in project BluePower by Qmunity.
the class TileWire method getCapability.
@Nonnull
@Override
public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable Direction side) {
List<Direction> directions = new ArrayList<>(BlockBPCableBase.FACING.getPossibleValues());
if (level != null) {
BlockState state = getBlockState();
if (state.getBlock() instanceof BlockAlloyWire) {
// Remove upward connections
directions.remove(state.getValue(BlockAlloyWire.FACING));
// Make sure the cable is on the same side of the block
directions.removeIf(d -> level.getBlockState(worldPosition.relative(d)).getBlock() instanceof BlockAlloyWire && level.getBlockState(worldPosition.relative(d)).getValue(BlockAlloyWire.FACING) != state.getValue(BlockAlloyWire.FACING));
// Make sure the cable is the same color or none
// if(device.getInsulationColor(null) != MinecraftColor.NONE)
// directions.removeIf(d -> {
// TileEntity tile = world.getBlockEntity(worldPosition.relative(d));
// return tile instanceof TileWire
// && !(((TileWire) tile).device.getInsulationColor(d) == device.getInsulationColor(d.getOpposite())
// || ((TileWire) tile).device.getInsulationColor(d) == MinecraftColor.NONE);
// });
}
}
if (cap == CapabilityRedstoneDevice.UNINSULATED_CAPABILITY && (side == null || directions.contains(side))) {
if (redstoneCap == null)
redstoneCap = LazyOptional.of(() -> device);
return redstoneCap.cast();
}
return LazyOptional.empty();
}
Aggregations