use of net.minecraft.block.state.IBlockState in project Traverse by ProfessorProspector.
the class WorldGenFallenTree method generate.
public boolean generate(World worldIn, Random rand, BlockPos position) {
int num = rand.nextInt(5);
EnumFacing orientation;
if (num == 0) {
orientation = EnumFacing.EAST;
stateWood = stateWood.withProperty(BlockLog.LOG_AXIS, BlockLog.EnumAxis.X);
} else if (num == 1) {
orientation = EnumFacing.WEST;
stateWood = stateWood.withProperty(BlockLog.LOG_AXIS, BlockLog.EnumAxis.X);
} else if (num == 1) {
orientation = EnumFacing.SOUTH;
stateWood = stateWood.withProperty(BlockLog.LOG_AXIS, BlockLog.EnumAxis.Z);
} else {
orientation = EnumFacing.NORTH;
stateWood = stateWood.withProperty(BlockLog.LOG_AXIS, BlockLog.EnumAxis.Z);
}
int i = rand.nextInt(2) + this.minTreeLength;
boolean flag = true;
if (position.getY() >= 1 && position.getY() + i + 1 <= worldIn.getHeight()) {
for (int j = position.getY(); j <= position.getY() + 1 + i; ++j) {
int k = 1;
if (j == position.getY()) {
k = 0;
}
if (j >= position.getY() + 1 + i - 2) {
k = 2;
}
BlockPos.MutableBlockPos mutablePos = new BlockPos.MutableBlockPos();
for (int l = position.getX() - k; l <= position.getX() + k && flag; ++l) {
for (int i1 = position.getZ() - k; i1 <= position.getZ() + k && flag; ++i1) {
if (j >= 0 && j < worldIn.getHeight()) {
if (!this.isReplaceable(worldIn, mutablePos.setPos(l, j, i1))) {
flag = false;
}
} else {
flag = false;
}
}
}
}
if (!flag) {
return false;
} else {
IBlockState state = worldIn.getBlockState(position.down());
if (state.getBlock().canSustainPlant(state, worldIn, position.down(), net.minecraft.util.EnumFacing.UP, (net.minecraft.block.BlockSapling) Blocks.SAPLING) && position.getY() < worldIn.getHeight() - i - 1) {
state.getBlock().onPlantGrow(state, worldIn, position.down(), position);
for (int j3 = 0; j3 < i; ++j3) {
BlockPos offsetPos = position.offset(orientation, j3);
state = worldIn.getBlockState(offsetPos);
if (state.getBlock().isAir(state, worldIn, offsetPos) || state.getBlock().isLeaves(state, worldIn, offsetPos) || state.getMaterial() == Material.VINE) {
this.setBlockAndNotifyAdequately(worldIn, position.offset(orientation, j3), this.stateWood);
}
}
return true;
} else {
return false;
}
}
} else {
return false;
}
}
use of net.minecraft.block.state.IBlockState in project Railcraft by Railcraft.
the class BlockOre method randomTick.
@Override
public void randomTick(World worldIn, BlockPos pos, IBlockState state, Random random) {
EnumOre ore = getVariant(state);
IBlockState newState = null;
switch(ore) {
case COPPER:
newState = EnumOreMetal.COPPER.getDefaultState();
break;
case LEAD:
newState = EnumOreMetal.LEAD.getDefaultState();
break;
case SILVER:
newState = EnumOreMetal.SILVER.getDefaultState();
break;
case TIN:
newState = EnumOreMetal.TIN.getDefaultState();
break;
case POOR_TIN:
newState = EnumOreMetalPoor.TIN.getDefaultState();
break;
case POOR_GOLD:
newState = EnumOreMetalPoor.GOLD.getDefaultState();
break;
case POOR_COPPER:
newState = EnumOreMetalPoor.COPPER.getDefaultState();
break;
case POOR_IRON:
newState = EnumOreMetalPoor.IRON.getDefaultState();
break;
case POOR_LEAD:
newState = EnumOreMetalPoor.LEAD.getDefaultState();
break;
case POOR_SILVER:
newState = EnumOreMetalPoor.SILVER.getDefaultState();
break;
}
if (newState != null)
WorldPlugin.setBlockState(worldIn, pos, newState);
}
use of net.minecraft.block.state.IBlockState in project Railcraft by Railcraft.
the class ItemFirestoneRefined method onItemUse.
@Override
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
if (player.canPlayerEdit(pos, side, stack)) {
Block block = WorldPlugin.getBlock(world, pos);
if (block != Blocks.STONE) {
List<ItemStack> drops = block.getDrops(world, pos, WorldPlugin.getBlockState(world, pos), 0);
if (drops.size() == 1 && drops.get(0) != null && drops.get(0).getItem() instanceof ItemBlock) {
ItemStack cooked = FurnaceRecipes.instance().getSmeltingResult(drops.get(0));
if (cooked != null && cooked.getItem() instanceof ItemBlock) {
IBlockState newState = InvTools.getBlockStateFromStack(cooked, world, pos);
if (newState != null) {
WorldPlugin.setBlockState(world, pos, newState);
SoundHelper.playSound(world, null, pos, SoundEvents.ITEM_FIRECHARGE_USE, SoundCategory.BLOCKS, 1.0F, itemRand.nextFloat() * 0.4F + 0.8F);
stack.damageItem(1, player);
return EnumActionResult.SUCCESS;
}
}
}
}
}
pos = pos.offset(side);
if (player.canPlayerEdit(pos, side, stack) && world.isAirBlock(pos)) {
SoundHelper.playSound(world, null, pos, SoundEvents.ITEM_FIRECHARGE_USE, SoundCategory.BLOCKS, 1.0F, itemRand.nextFloat() * 0.4F + 0.8F);
world.setBlockState(pos, Blocks.FIRE.getDefaultState());
stack.damageItem(1, player);
return EnumActionResult.SUCCESS;
}
return EnumActionResult.FAIL;
}
use of net.minecraft.block.state.IBlockState in project Railcraft by Railcraft.
the class TileTankBase method placeIronTank.
public static void placeIronTank(World world, BlockPos pos, int patternIndex, FluidStack fluid) {
MultiBlockPattern pattern = TileTankBase.patterns.get(patternIndex);
Map<Character, IBlockState> blockMapping = new HashMap<Character, IBlockState>();
blockMapping.put('B', EnumMachineBeta.TANK_IRON_WALL.getDefaultState());
blockMapping.put('W', EnumMachineBeta.TANK_IRON_GAUGE.getDefaultState());
TileEntity tile = pattern.placeStructure(world, pos, blockMapping);
if (tile instanceof TileTankBase) {
TileTankBase master = (TileTankBase) tile;
master.tank.setFluid(fluid);
}
}
use of net.minecraft.block.state.IBlockState in project Railcraft by Railcraft.
the class ItemSignalLabel method onItemUse.
@Override
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
if (Game.isHost(worldIn) && playerIn.isSneaking() && stack.hasDisplayName()) {
TileEntity tile = worldIn.getTileEntity(pos);
Set<AbstractPair> pairs = new HashSet<AbstractPair>();
if (tile instanceof IReceiverTile) {
pairs.add(((IReceiverTile) tile).getReceiver());
}
if (tile instanceof IControllerTile) {
pairs.add(((IControllerTile) tile).getController());
}
if (tile instanceof ISignalBlockTile) {
pairs.add(((ISignalBlockTile) tile).getSignalBlock());
}
if (!pairs.isEmpty()) {
String newName = stack.getDisplayName();
boolean done = false;
for (AbstractPair pair : pairs) {
if (!newName.equals(pair.getName())) {
pair.setName(newName);
done = true;
}
}
if (done) {
--stack.stackSize;
PlayerPlugin.swingArm(playerIn, hand);
IBlockState state = WorldPlugin.getBlockState(worldIn, pos);
worldIn.notifyBlockUpdate(pos, state, state, 3);
return EnumActionResult.SUCCESS;
}
}
}
return super.onItemUse(stack, playerIn, worldIn, pos, hand, facing, hitX, hitY, hitZ);
}
Aggregations