use of net.minecraft.block.BlockState in project BluePower by Qmunity.
the class TileBPMultipart method markDirtyClient.
private void markDirtyClient() {
setChanged();
if (getLevel() != null) {
BlockState state = getLevel().getBlockState(getBlockPos());
getLevel().sendBlockUpdated(getBlockPos(), state, state, 3);
}
this.requestModelDataUpdate();
}
use of net.minecraft.block.BlockState in project BluePower by Qmunity.
the class TileBPMultipart method onDataPacket.
@Override
public void onDataPacket(NetworkManager networkManager, SUpdateTileEntityPacket packet) {
List<BlockState> states = getStates();
CompoundNBT tagCompound = packet.getTag();
super.onDataPacket(networkManager, packet);
load(getBlockState(), tagCompound);
if (level.isClientSide) {
// Update if needed
if (!getStates().equals(states)) {
level.blockEntityChanged(getBlockPos(), this.getTileEntity());
}
}
}
use of net.minecraft.block.BlockState in project BluePower by Qmunity.
the class TileBlockBreaker method redstoneChanged.
@Override
protected void redstoneChanged(boolean newValue) {
super.redstoneChanged(newValue);
if (!level.isClientSide && newValue) {
Direction direction = getFacingDirection();
BlockState breakState = level.getBlockState(worldPosition.relative(direction));
if (!canBreakBlock(breakState.getBlock(), level, breakState, worldPosition.relative(direction)))
return;
List<ItemStack> breakStacks = breakState.getBlock().getDrops(breakState, (ServerWorld) level, worldPosition.relative(direction), this);
// destroyBlock
level.destroyBlock(worldPosition.relative(direction), false);
addItemsToOutputBuffer(breakStacks);
}
}
use of net.minecraft.block.BlockState in project BluePower by Qmunity.
the class TileBattery method tick.
@Override
public void tick() {
if (!level.isClientSide) {
storage.resetCurrent();
// Balance power of attached blulectric blocks.
for (Direction facing : Direction.values()) {
TileEntity tile = level.getBlockEntity(worldPosition.relative(facing));
if (tile != null)
tile.getCapability(CapabilityBlutricity.BLUTRICITY_CAPABILITY, facing.getOpposite()).ifPresent(exStorage -> EnergyHelper.balancePower(exStorage, storage));
}
double energy = storage.getEnergy();
int batteryLevel = (int) ((energy / MAX_ENERGY) * 6);
BlockState state = getBlockState();
if (state.getValue(BlockBattery.LEVEL) != batteryLevel) {
this.level.setBlockAndUpdate(worldPosition, state.setValue(BlockBattery.LEVEL, batteryLevel));
markForRenderUpdate();
setChanged();
}
}
}
use of net.minecraft.block.BlockState in project BluePower by Qmunity.
the class TileBlulectricCable method getCapability.
@Nonnull
@Override
public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable Direction side) {
List<Direction> directions = new ArrayList<>(BlockBlulectricCable.FACING.getPossibleValues());
if (level != null) {
BlockState state = getBlockState();
if (state.getBlock() instanceof BlockBlulectricCable) {
// Remove upward connections
directions.remove(state.getValue(BlockBlulectricCable.FACING));
// Make sure the cable is on the same side of the block
directions.removeIf(d -> level.getBlockState(worldPosition.relative(d)).getBlock() instanceof BlockBlulectricCable && level.getBlockState(worldPosition.relative(d)).getValue(BlockBlulectricCable.FACING) != state.getValue(BlockBlulectricCable.FACING));
}
}
if (cap == CapabilityBlutricity.BLUTRICITY_CAPABILITY && (side == null || directions.contains(side))) {
if (blutricityCap == null)
blutricityCap = LazyOptional.of(() -> storage);
return blutricityCap.cast();
}
return LazyOptional.empty();
}
Aggregations