use of net.minecraft.block.state.IBlockState in project Railcraft by Railcraft.
the class TileTankWater method placeWaterTank.
public static void placeWaterTank(World world, BlockPos pos, int water) {
MultiBlockPattern pattern = TileTankWater.patterns.get(0);
Map<Character, IBlockState> blockMapping = new HashMap<Character, IBlockState>();
blockMapping.put('B', EnumMachineAlpha.TANK_WATER.getDefaultState());
TileEntity tile = pattern.placeStructure(world, pos, blockMapping);
if (tile instanceof TileTankWater) {
TileTankWater master = (TileTankWater) tile;
master.tank.setFluid(Fluids.WATER.get(water));
}
}
use of net.minecraft.block.state.IBlockState in project Overloaded by CJ-MC-Mods.
the class ItemMultiTool method breakAndUseEnergy.
/**
* @return True if the break was successful, false otherwise
*/
@Nonnull
private BlockResult breakAndUseEnergy(@Nonnull World worldIn, @Nonnull BlockPos blockPos, @Nonnull IEnergyStorage energy, EntityPlayerMP player, int efficiency, int unbreaking) {
IBlockState state = worldIn.getBlockState(blockPos);
if (!player.capabilities.isCreativeMode) {
float hardness = state.getBlockHardness(worldIn, blockPos);
if (hardness < 0) {
return BlockResult.FAIL_UNBREAKABLE;
}
float floatBreakCost = getBreakCost(hardness, efficiency, unbreaking, getDistance(player, blockPos));
if (Float.isInfinite(floatBreakCost) || Float.isNaN(floatBreakCost))
return BlockResult.FAIL_ENERGY;
int breakCost = Math.round(floatBreakCost);
if (breakCost < 0 || energy.getEnergyStored() < breakCost) {
return BlockResult.FAIL_ENERGY;
}
}
BlockEvent.BreakEvent event = new BlockEvent.BreakEvent(worldIn, blockPos, state, player);
MinecraftForge.EVENT_BUS.post(event);
if (event.isCanceled())
return BlockResult.FAIL_REMOVE;
boolean result = PlayerInteractionUtil.tryHarvestBlock(player, worldIn, blockPos);
return result ? BlockResult.SUCCESS : BlockResult.FAIL_REMOVE;
}
use of net.minecraft.block.state.IBlockState in project AgriCraft by AgriCraft.
the class TileEntitySprinkler method irrigate.
/**
* Depending on the block type either irrigates farmland or forces plant
* GROWTH (based on chance)
*/
private void irrigate(BlockPos pos, boolean farmlandOnly) {
IBlockState state = this.getWorld().getBlockState(pos);
Block block = state.getBlock();
if (block instanceof BlockFarmland && block.getMetaFromState(state) < 7) {
// irrigate farmland
int flag = counter == 0 ? 2 : 6;
worldObj.setBlockState(pos, block.getStateFromMeta(7), flag);
} else if (!farmlandOnly && ((block instanceof IPlantable) || (block instanceof IGrowable))) {
// X1 chance to force GROWTH tick on plant every Y1 ticks
if (counter == 0 && worldObj.rand.nextDouble() <= AgriCraftConfig.sprinklerGrowthChancePercent) {
block.updateTick(this.getWorld(), pos, state, worldObj.rand);
}
}
}
use of net.minecraft.block.state.IBlockState in project AgriCraft by AgriCraft.
the class CustomWoodType method getIcon.
@SideOnly(Side.CLIENT)
@Nonnull
public TextureAtlasSprite getIcon() {
if (texture == null) {
try {
IBlockState state = block.getStateFromMeta(meta);
texture = Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes().getTexture(state);
} catch (Exception e) {
AgriCore.getLogger("agricraft").debug("Unable to load texture for custom wood block {0}!", block.getLocalizedName());
AgriCore.getLogger("agricraft").trace(e);
texture = Minecraft.getMinecraft().getTextureMapBlocks().getMissingSprite();
}
}
return texture;
}
use of net.minecraft.block.state.IBlockState in project Overloaded by CJ-MC-Mods.
the class PlayerInteractionUtil method tryHarvestBlock.
public static boolean tryHarvestBlock(EntityPlayerMP player, World world, BlockPos pos) {
int exp = net.minecraftforge.common.ForgeHooks.onBlockBreakEvent(world, player.interactionManager.getGameType(), player, pos);
if (exp == -1) {
return false;
} else {
IBlockState iblockstate = world.getBlockState(pos);
TileEntity tileentity = world.getTileEntity(pos);
Block block = iblockstate.getBlock();
if ((block instanceof BlockCommandBlock || block instanceof BlockStructure) && !player.canUseCommandBlock()) {
world.notifyBlockUpdate(pos, iblockstate, iblockstate, 3);
return false;
} else {
world.playEvent(null, 2001, pos, Block.getStateId(iblockstate));
boolean flag1;
if (player.capabilities.isCreativeMode) {
flag1 = removeBlock(world, pos, player, false);
player.connection.sendPacket(new SPacketBlockChange(world, pos));
} else {
ItemStack itemstack1 = player.getHeldItemMainhand();
ItemStack itemstack2 = itemstack1.isEmpty() ? ItemStack.EMPTY : itemstack1.copy();
boolean flag = iblockstate.getBlock().canHarvestBlock(world, pos, player);
itemstack1.onBlockDestroyed(world, iblockstate, pos, player);
flag1 = removeBlock(world, pos, player, flag);
if (flag1 && flag) {
iblockstate.getBlock().harvestBlock(world, player, pos, iblockstate, tileentity, itemstack2);
}
}
// Drop experience
if (!player.isCreative() && flag1 && exp > 0) {
iblockstate.getBlock().dropXpOnBlockBreak(world, player.getPosition(), exp);
}
return flag1;
}
}
}
Aggregations