use of net.minecraft.util.EnumFacing in project BetterWithAddons by DaedalusGame.
the class BlockWeight method measureBlock.
public int measureBlock(World world, BlockPos pos, IBlockState state) {
BlockPos checkpos = pos.up();
IBlockState checkstate = world.getBlockState(checkpos);
TileEntity te = world.getTileEntity(checkpos);
boolean isFull = true;
boolean isEmpty = true;
int delay = 20;
if (te != null) {
boolean foundAnyMeasurable = false;
for (EnumFacing facing : EnumFacing.VALUES) {
if (te.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing)) {
IItemHandler inventory = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing);
if (!InventoryUtil.isEmpty(inventory))
isEmpty = false;
if (!InventoryUtil.isFull(inventory))
isFull = false;
foundAnyMeasurable = true;
}
if (te.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, facing)) {
IFluidHandler tank = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, facing);
FluidStack fluid = tank.drain(Integer.MAX_VALUE, false);
if (fluid != null && tank.fill(fluid, false) > 0)
isFull = false;
if (fluid != null && fluid.amount != 0)
isEmpty = false;
foundAnyMeasurable = true;
}
}
if (foundAnyMeasurable)
delay = 1;
else
isFull = false;
} else if (SPECIAL_BEHAVIOR.containsKey(checkstate.getBlock())) {
ISpecialMeasuringBehavior behavior = SPECIAL_BEHAVIOR.get(checkstate.getBlock());
isEmpty = behavior.isEmpty(world, checkpos, checkstate);
isFull = behavior.isFull(world, checkpos, checkstate);
delay = behavior.getDelay(world, checkpos, checkstate);
} else {
isFull = false;
}
boolean active = decideActivity(isEmpty, isFull);
if (active != state.getValue(ACTIVE)) {
world.setBlockState(pos, state.withProperty(ACTIVE, active));
float f = active ? 0.6F : 0.5F;
world.playSound(null, pos, SoundEvents.BLOCK_LEVER_CLICK, SoundCategory.BLOCKS, 1.0F, f);
}
return delay;
}
use of net.minecraft.util.EnumFacing in project BetterWithAddons by DaedalusGame.
the class BlockLoom method spinUpAllAttached.
public void spinUpAllAttached(World world, BlockPos pos, IBlockState state) {
if (world.isRemote)
return;
for (EnumFacing facing : EnumFacing.VALUES) {
if (facing == state.getValue(FACING))
continue;
BlockPos spinPos = pos.offset(facing);
IBlockState spinState = world.getBlockState(spinPos);
if (spinState.getBlock() instanceof ISpindle)
((ISpindle) spinState.getBlock()).spinUp(world, spinPos, spinState, facing);
}
}
use of net.minecraft.util.EnumFacing in project BetterWithAddons by DaedalusGame.
the class BlockRopeSideways method isSupported.
private boolean isSupported(World world, BlockPos pos, IBlockState state, Axis axis) {
EnumRopeShape shape = state.getValue(SHAPE);
EnumFacing forward = EnumFacing.getFacingFromAxis(AxisDirection.POSITIVE, axis);
EnumFacing back = EnumFacing.getFacingFromAxis(AxisDirection.NEGATIVE, axis);
IBlockState state1 = world.getBlockState(pos.offset(forward));
IBlockState state2 = world.getBlockState(pos.offset(back));
return (canFastenBlock(state1.getBlock()) || (state1.getBlock() == this && state1.getValue(SHAPE).has(shape))) && (canFastenBlock(state2.getBlock()) || (state2.getBlock() == this && state2.getValue(SHAPE).has(shape)));
}
use of net.minecraft.util.EnumFacing in project BetterWithAddons by DaedalusGame.
the class AssortedHandler method attachRopeEvent.
@SubscribeEvent
public void attachRopeEvent(PlayerInteractEvent.RightClickBlock event) {
World world = event.getWorld();
BlockPos pos = event.getPos();
IBlockState state = world.getBlockState(pos);
ItemStack stack = event.getItemStack();
EnumFacing facing = event.getFace();
EntityPlayer player = event.getEntityPlayer();
if (stack.getItem() == Item.getItemFromBlock(BWMBlocks.ROPE) && state.getBlock() instanceof BlockFence && state.getBlock() != ModBlocks.ropePost) {
ModBlocks.ropePost.placeFencePost(world, pos);
state = world.getBlockState(pos);
int consumedRope = 1;
if (BlockRopeSideways.canFastenBlock(state.getBlock())) {
consumedRope += attachRope(world, pos, facing, Math.min(stack.getCount() - 1, ropeLimit));
}
if (!player.isCreative())
stack.shrink(consumedRope);
event.setCancellationResult(EnumActionResult.SUCCESS);
event.setCanceled(true);
}
}
use of net.minecraft.util.EnumFacing in project BetterWithAddons by DaedalusGame.
the class TileEntityInvertedGearbox method onChanged.
public void onChanged() {
if (this.getBlockWorld().getTotalWorldTime() % 20L != 0L)
return;
EnumFacing gearfacing = getFacing();
int findPower = 0;
for (EnumFacing facing : EnumFacing.values()) {
if (facing == gearfacing || facing.getOpposite() == gearfacing)
continue;
int power = getMechanicalInput(facing);
if (power > findPower) {
findPower = power;
}
}
if (overpowerChance() && findPower > getMaximumInput(EnumFacing.UP)) {
overpower();
return;
}
if (findPower > 0) {
setPower(0);
markDirty();
return;
}
super.onChanged();
}
Aggregations