@Override public boolean onBlockActivated( World world, int x, int y, int z, EntityPlayer entityplayer, int side, float hitX, float hitY, float hitZ) { super.onBlockActivated(world, x, y, z, entityplayer, side, hitX, hitY, hitZ); TileEntityQuern te = (TileEntityQuern) world.getBlockTileEntity(x, y, z); if (!world.isRemote) { if (!te.shouldRotate && hitX >= 0.65 && hitZ >= 0.65 && te.storage[2] != null) { te.shouldRotate = true; world.playSoundEffect(x, y, z, TFC_Sounds.STONEDRAG, 1, 1); } else if ((!te.shouldRotate && (hitX < 0.65 || hitZ < 0.65)) || te.storage[2] == null) { entityplayer.openGui(TerraFirmaCraft.instance, 33, world, x, y, z); } } else if (!te.shouldRotate && hitX >= 0.65 && hitZ >= 0.65 && te.hasQuern) { te.shouldRotate = true; } return true; }
public boolean onBlockActivated( World world, int i, int j, int k, EntityPlayer entityplayer, int side, float hitX, float hitY, float hitZ) { if (!world.isRemote) { TileEntityToolRack te = (TileEntityToolRack) world.getBlockTileEntity(i, j, k); int dir = world.getBlockMetadata(i, j, k); if (te != null) { if (dir == 0) { if (hitX < 0.5 && hitY > 0.5) { handleArea(world, i, j, k, entityplayer, te, 0, 0); } else if (hitX > 0.5 && hitY > 0.5) { handleArea(world, i, j, k, entityplayer, te, 1, 0); } else if (hitX < 0.5) { handleArea(world, i, j, k, entityplayer, te, 2, 0); } else if (hitX > 0.5) { handleArea(world, i, j, k, entityplayer, te, 3, 0); } } else if (dir == 1) { if (hitZ < 0.5 && hitY > 0.5) { handleArea(world, i, j, k, entityplayer, te, 0, 1); } else if (hitZ > 0.5 && hitY > 0.5) { handleArea(world, i, j, k, entityplayer, te, 1, 1); } else if (hitZ < 0.5) { handleArea(world, i, j, k, entityplayer, te, 2, 1); } else if (hitZ > 0.5) { handleArea(world, i, j, k, entityplayer, te, 3, 1); } } else if (dir == 2) { if (hitX < 0.5 && hitY > 0.5) { handleArea(world, i, j, k, entityplayer, te, 0, 2); } else if (hitX > 0.5 && hitY > 0.5) { handleArea(world, i, j, k, entityplayer, te, 1, 2); } else if (hitX < 0.5) { handleArea(world, i, j, k, entityplayer, te, 2, 2); } else if (hitX > 0.5) { handleArea(world, i, j, k, entityplayer, te, 3, 2); } } else if (dir == 3) { if (hitZ < 0.5 && hitY > 0.5) { handleArea(world, i, j, k, entityplayer, te, 0, 3); } else if (hitZ > 0.5 && hitY > 0.5) { handleArea(world, i, j, k, entityplayer, te, 1, 3); } else if (hitZ < 0.5) { handleArea(world, i, j, k, entityplayer, te, 2, 3); } else if (hitZ > 0.5) { handleArea(world, i, j, k, entityplayer, te, 3, 3); } } te.broadcastPacketInRange(te.createUpdatePacket()); return true; } } return false; }
@ForgeSubscribe public void DrawBlockHighlightEvent(DrawBlockHighlightEvent evt) { World world = evt.player.worldObj; double var8 = evt.player.lastTickPosX + (evt.player.posX - evt.player.lastTickPosX) * (double) evt.partialTicks; double var10 = evt.player.lastTickPosY + (evt.player.posY - evt.player.lastTickPosY) * (double) evt.partialTicks; double var12 = evt.player.lastTickPosZ + (evt.player.posZ - evt.player.lastTickPosZ) * (double) evt.partialTicks; boolean isMetalHoe = false; if (evt.currentItem != null && evt.currentItem.getItem().shiftedIndex != TFCItems.IgInHoe.shiftedIndex && evt.currentItem.getItem().shiftedIndex != TFCItems.IgExHoe.shiftedIndex && evt.currentItem.getItem().shiftedIndex != TFCItems.SedHoe.shiftedIndex && evt.currentItem.getItem().shiftedIndex != TFCItems.MMHoe.shiftedIndex) { isMetalHoe = true; } if (evt.currentItem != null && evt.currentItem.getItem() instanceof ItemCustomHoe && isMetalHoe && PlayerManagerTFC.getInstance().getClientPlayer().hoeMode == 1) { int id = world.getBlockId(evt.target.blockX, evt.target.blockY, evt.target.blockZ); int crop = 0; if (id == Block.crops.blockID && (world.getBlockId(evt.target.blockX, evt.target.blockY - 1, evt.target.blockZ) == TFCBlocks.tilledSoil.blockID || world.getBlockId(evt.target.blockX, evt.target.blockY - 1, evt.target.blockZ) == TFCBlocks.tilledSoil2.blockID)) { id = TFCBlocks.tilledSoil.blockID; crop = 1; } if (id == TFCBlocks.tilledSoil.blockID || id == TFCBlocks.tilledSoil2.blockID) { TileEntityFarmland te = (TileEntityFarmland) world.getBlockTileEntity( evt.target.blockX, evt.target.blockY - crop, evt.target.blockZ); te.requestNutrientData(); float timeMultiplier = (float) TFC_Time.daysInYear / 360f; int soilMax = (int) (25000 * timeMultiplier); // Setup GL for the depthbox GL11.glEnable(GL11.GL_BLEND); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); GL11.glColor4ub( TFC_Settings.cropNutrientAColor[0], TFC_Settings.cropNutrientAColor[1], TFC_Settings.cropNutrientAColor[2], TFC_Settings.cropNutrientAColor[3]); GL11.glDisable(GL11.GL_CULL_FACE); // GL11.glLineWidth(6.0F); GL11.glDisable(GL11.GL_TEXTURE_2D); GL11.glDepthMask(false); double offset = 0; double nutrient = 1.02 + ((double) te.nutrients[0] / (double) soilMax) * 0.5; drawBox( AxisAlignedBB.getAABBPool() .addOrModifyAABBInPool( evt.target.blockX + offset, evt.target.blockY + 1.01 - crop, evt.target.blockZ, evt.target.blockX + offset + 0.3333, evt.target.blockY + nutrient - crop, evt.target.blockZ + 1) .expand(0.002F, 0.002F, 0.002F) .getOffsetBoundingBox(-var8, -var10, -var12)); offset = 0.3333; nutrient = 1.02 + ((double) te.nutrients[1] / (double) soilMax) * 0.5; GL11.glColor4ub( TFC_Settings.cropNutrientBColor[0], TFC_Settings.cropNutrientBColor[1], TFC_Settings.cropNutrientBColor[2], TFC_Settings.cropNutrientBColor[3]); drawBox( AxisAlignedBB.getAABBPool() .addOrModifyAABBInPool( evt.target.blockX + offset, evt.target.blockY + 1.01 - crop, evt.target.blockZ, evt.target.blockX + offset + 0.3333, evt.target.blockY + nutrient - crop, evt.target.blockZ + 1) .expand(0.002F, 0.002F, 0.002F) .getOffsetBoundingBox(-var8, -var10, -var12)); offset = 0.6666; nutrient = 1.02 + ((double) te.nutrients[2] / (double) soilMax) * 0.5; GL11.glColor4ub( TFC_Settings.cropNutrientCColor[0], TFC_Settings.cropNutrientCColor[1], TFC_Settings.cropNutrientCColor[2], TFC_Settings.cropNutrientCColor[3]); drawBox( AxisAlignedBB.getAABBPool() .addOrModifyAABBInPool( evt.target.blockX + offset, evt.target.blockY + 1.01 - crop, evt.target.blockZ, evt.target.blockX + offset + 0.3333, evt.target.blockY + nutrient - crop, evt.target.blockZ + 1) .expand(0.002F, 0.002F, 0.002F) .getOffsetBoundingBox(-var8, -var10, -var12)); GL11.glEnable(GL11.GL_CULL_FACE); /** Draw the outliens around the boxes */ GL11.glColor4f(0.1F, 0.1F, 0.1F, 1.0F); GL11.glLineWidth(3.0F); GL11.glDepthMask(false); offset = 0; nutrient = 1.02 + ((double) te.nutrients[0] / (double) soilMax) * 0.5; drawOutlinedBoundingBox( AxisAlignedBB.getAABBPool() .addOrModifyAABBInPool( evt.target.blockX + offset, evt.target.blockY + 1.01 - crop, evt.target.blockZ, evt.target.blockX + offset + 0.3333, evt.target.blockY + nutrient - crop, evt.target.blockZ + 1) .expand(0.002F, 0.002F, 0.002F) .getOffsetBoundingBox(-var8, -var10, -var12)); offset = 0.3333; nutrient = 1.02 + ((double) te.nutrients[1] / (double) soilMax) * 0.5; drawOutlinedBoundingBox( AxisAlignedBB.getAABBPool() .addOrModifyAABBInPool( evt.target.blockX + offset, evt.target.blockY + 1.01 - crop, evt.target.blockZ, evt.target.blockX + offset + 0.3333, evt.target.blockY + nutrient - crop, evt.target.blockZ + 1) .expand(0.002F, 0.002F, 0.002F) .getOffsetBoundingBox(-var8, -var10, -var12)); offset = 0.6666; nutrient = 1.02 + ((double) te.nutrients[2] / (double) soilMax) * 0.5; drawOutlinedBoundingBox( AxisAlignedBB.getAABBPool() .addOrModifyAABBInPool( evt.target.blockX + offset, evt.target.blockY + 1.01 - crop, evt.target.blockZ, evt.target.blockX + offset + 0.3333, evt.target.blockY + nutrient - crop, evt.target.blockZ + 1) .expand(0.002F, 0.002F, 0.002F) .getOffsetBoundingBox(-var8, -var10, -var12)); } } else if (evt.currentItem != null && evt.currentItem.getItem() instanceof ItemCustomHoe && PlayerManagerTFC.getInstance().getClientPlayer().hoeMode == 2) { int id = world.getBlockId(evt.target.blockX, evt.target.blockY, evt.target.blockZ); int crop = 0; if (id == Block.crops.blockID && (world.getBlockId(evt.target.blockX, evt.target.blockY - 1, evt.target.blockZ) == TFCBlocks.tilledSoil.blockID || world.getBlockId(evt.target.blockX, evt.target.blockY - 1, evt.target.blockZ) == TFCBlocks.tilledSoil2.blockID)) { id = TFCBlocks.tilledSoil.blockID; crop = 1; } if (id == TFCBlocks.tilledSoil.blockID || id == TFCBlocks.tilledSoil2.blockID) { boolean water = TFC.Blocks.BlockFarmland.isWaterNearby( world, evt.target.blockX, evt.target.blockY - crop, evt.target.blockZ); GL11.glEnable(GL11.GL_BLEND); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); if (water) GL11.glColor4ub((byte) 14, (byte) 23, (byte) 212, (byte) 200); else GL11.glColor4ub((byte) 0, (byte) 0, (byte) 0, (byte) 200); GL11.glDisable(GL11.GL_CULL_FACE); // GL11.glLineWidth(6.0F); GL11.glDisable(GL11.GL_TEXTURE_2D); GL11.glDepthMask(false); drawFace( AxisAlignedBB.getAABBPool() .addOrModifyAABBInPool( evt.target.blockX, evt.target.blockY + 1.01 - crop, evt.target.blockZ, evt.target.blockX + 1, evt.target.blockY + 1.02 - crop, evt.target.blockZ + 1) .expand(0.002F, 0.002F, 0.002F) .getOffsetBoundingBox(-var8, -var10, -var12)); GL11.glEnable(GL11.GL_CULL_FACE); } } else if (evt.currentItem != null && evt.currentItem.getItem() instanceof ItemCustomHoe && PlayerManagerTFC.getInstance().getClientPlayer().hoeMode == 3) { int id = world.getBlockId(evt.target.blockX, evt.target.blockY, evt.target.blockZ); if (id == Block.crops.blockID && (world.getBlockId(evt.target.blockX, evt.target.blockY - 1, evt.target.blockZ) == TFCBlocks.tilledSoil.blockID || world.getBlockId(evt.target.blockX, evt.target.blockY - 1, evt.target.blockZ) == TFCBlocks.tilledSoil2.blockID)) { TileEntityCrop te = (TileEntityCrop) world.getBlockTileEntity(evt.target.blockX, evt.target.blockY, evt.target.blockZ); CropIndex index = CropManager.getInstance().getCropFromId(te.cropId); boolean fullyGrown = te.growth >= index.numGrowthStages; GL11.glEnable(GL11.GL_BLEND); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); if (fullyGrown) GL11.glColor4ub((byte) 64, (byte) 200, (byte) 37, (byte) 200); else GL11.glColor4ub((byte) 200, (byte) 37, (byte) 37, (byte) 200); GL11.glDisable(GL11.GL_CULL_FACE); // GL11.glLineWidth(6.0F); GL11.glDisable(GL11.GL_TEXTURE_2D); GL11.glDepthMask(false); drawFace( AxisAlignedBB.getAABBPool() .addOrModifyAABBInPool( evt.target.blockX, evt.target.blockY + 0.01, evt.target.blockZ, evt.target.blockX + 1, evt.target.blockY + 0.02, evt.target.blockZ + 1) .expand(0.002F, 0.002F, 0.002F) .getOffsetBoundingBox(-var8, -var10, -var12)); GL11.glEnable(GL11.GL_CULL_FACE); } } }
@Override public void updateTick(World world, int i, int j, int k, Random rand) { FloraManager manager = FloraManager.getInstance(); FloraIndex fi = manager.findMatchingIndex(this.getType(world.getBlockMetadata(i, j, k))); float temp = TFC_Climate.getHeightAdjustedTemp(i, j, k); if (!world.isRemote && world.getBlockTileEntity(i, j, k) != null && TFC_Time.currentMonth < 6 && fi != null && temp >= fi.minTemp && temp < fi.maxTemp) { TileEntityFruitTreeWood te = (TileEntityFruitTreeWood) world.getBlockTileEntity(i, j, k); int t = 1; if (TFC_Time.currentMonth < 3) t = 2; int leafGrowthRate = 20; int trunkGrowTime = 30; int branchGrowTime = 20; // grow upward if (te.birthTimeWood + trunkGrowTime < TFC_Time.totalDays() && te.height < 3 && te.isTrunk && rand.nextInt(16 / t) == 0 && (world.getBlockId(i, j + 1, k) == 0 || world.getBlockId(i, j + 1, k) == TFCBlocks.fruitTreeLeaves.blockID)) { world.setBlockAndMetadata(i, j + 1, k, this.blockID, world.getBlockMetadata(i, j, k)); ((TileEntityFruitTreeWood) world.getBlockTileEntity(i, j + 1, k)).setTrunk(true); ((TileEntityFruitTreeWood) world.getBlockTileEntity(i, j + 1, k)).setHeight(te.height + 1); ((TileEntityFruitTreeWood) world.getBlockTileEntity(i, j + 1, k)).setBirth(); ((TileEntityFruitTreeWood) world.getBlockTileEntity(i, j, k)).setBirthWood(trunkGrowTime); } else if (te.birthTimeWood + branchGrowTime < TFC_Time.totalDays() && te.height == 2 && te.isTrunk && rand.nextInt(16 / t) == 0 && world.getBlockId(i, j + 1, k) != blockID) { int r = rand.nextInt(4); if (r == 0 && world.getBlockId(i + 1, j, k) == 0 || world.getBlockId(i + 1, j, k) == TFCBlocks.fruitTreeLeaves.blockID) { world.setBlockAndMetadata(i + 1, j, k, this.blockID, world.getBlockMetadata(i, j, k)); ((TileEntityFruitTreeWood) world.getBlockTileEntity(i + 1, j, k)).setTrunk(false); ((TileEntityFruitTreeWood) world.getBlockTileEntity(i + 1, j, k)).setHeight(te.height); ((TileEntityFruitTreeWood) world.getBlockTileEntity(i + 1, j, k)).setBirth(); } else if (r == 1 && world.getBlockId(i, j, k - 1) == 0 || world.getBlockId(i, j, k - 1) == TFCBlocks.fruitTreeLeaves.blockID) { world.setBlockAndMetadata(i, j, k - 1, this.blockID, world.getBlockMetadata(i, j, k)); ((TileEntityFruitTreeWood) world.getBlockTileEntity(i, j, k - 1)).setTrunk(false); ((TileEntityFruitTreeWood) world.getBlockTileEntity(i, j, k - 1)).setHeight(te.height); ((TileEntityFruitTreeWood) world.getBlockTileEntity(i, j, k - 1)).setBirth(); } else if (r == 2 && world.getBlockId(i - 1, j, k) == 0 || world.getBlockId(i - 1, j, k) == TFCBlocks.fruitTreeLeaves.blockID) { world.setBlockAndMetadata(i - 1, j, k, this.blockID, world.getBlockMetadata(i, j, k)); ((TileEntityFruitTreeWood) world.getBlockTileEntity(i - 1, j, k)).setTrunk(false); ((TileEntityFruitTreeWood) world.getBlockTileEntity(i - 1, j, k)).setHeight(te.height); ((TileEntityFruitTreeWood) world.getBlockTileEntity(i - 1, j, k)).setBirth(); } else if (r == 3 && world.getBlockId(i, j, k + 1) == 0 || world.getBlockId(i, j, k + 1) == TFCBlocks.fruitTreeLeaves.blockID) { world.setBlockAndMetadata(i, j, k + 1, this.blockID, world.getBlockMetadata(i, j, k)); ((TileEntityFruitTreeWood) world.getBlockTileEntity(i, j, k + 1)).setTrunk(false); ((TileEntityFruitTreeWood) world.getBlockTileEntity(i, j, k + 1)).setHeight(te.height); ((TileEntityFruitTreeWood) world.getBlockTileEntity(i, j, k + 1)).setBirth(); } ((TileEntityFruitTreeWood) world.getBlockTileEntity(i, j, k)).setBirthWood(branchGrowTime); } else if (te.birthTimeWood + 1 < TFC_Time.totalDays() && rand.nextInt(leafGrowthRate) == 0 && world.getBlockId(i, j + 2, k) != blockID) { if (world.getBlockId(i, j + 1, k) == 0 && world.getBlockId(i, j + 2, k) == 0 && BlockFruitLeaves.canStay( world, i, j + 1, k, TFCBlocks.fruitTreeLeaves.blockID)) // above { world.setBlockAndMetadata( i, j + 1, k, TFCBlocks.fruitTreeLeaves.blockID, world.getBlockMetadata(i, j, k)); world.markBlockForUpdate(i, j + 1, k); } else if (world.getBlockId(i + 1, j, k) == 0 && world.getBlockId(i + 1, j + 1, k) == 0 && BlockFruitLeaves.canStay( world, i + 1, j, k, TFCBlocks.fruitTreeLeaves.blockID)) // +x { world.setBlockAndMetadata( i + 1, j, k, TFCBlocks.fruitTreeLeaves.blockID, world.getBlockMetadata(i, j, k)); world.markBlockForUpdate(i + 1, j, k); } else if (world.getBlockId(i - 1, j, k) == 0 && world.getBlockId(i - 1, j + 1, k) == 0 && BlockFruitLeaves.canStay( world, i - 1, j, k, TFCBlocks.fruitTreeLeaves.blockID)) // -x { world.setBlockAndMetadata( i - 1, j, k, TFCBlocks.fruitTreeLeaves.blockID, world.getBlockMetadata(i, j, k)); world.markBlockForUpdate(i - 1, j, k); } else if (world.getBlockId(i, j, k + 1) == 0 && world.getBlockId(i, j + 1, k + 1) == 0 && BlockFruitLeaves.canStay( world, i, j, k + 1, TFCBlocks.fruitTreeLeaves.blockID)) // +z { world.setBlockAndMetadata( i, j, k + 1, TFCBlocks.fruitTreeLeaves.blockID, world.getBlockMetadata(i, j, k)); world.markBlockForUpdate(i, j, k + 1); } else if (world.getBlockId(i, j, k - 1) == 0 && world.getBlockId(i, j + 1, k - 1) == 0 && BlockFruitLeaves.canStay( world, i, j, k - 1, TFCBlocks.fruitTreeLeaves.blockID)) // -z { world.setBlockAndMetadata( i, j, k - 1, TFCBlocks.fruitTreeLeaves.blockID, world.getBlockMetadata(i, j, k)); world.markBlockForUpdate(i, j, k - 1); } else if (world.getBlockId(i + 1, j, k - 1) == 0 && world.getBlockId(i + 1, j + 1, k - 1) == 0 && BlockFruitLeaves.canStay( world, i + 1, j, k - 1, TFCBlocks.fruitTreeLeaves.blockID)) // +x/-z { world.setBlockAndMetadata( i + 1, j, k - 1, TFCBlocks.fruitTreeLeaves.blockID, world.getBlockMetadata(i, j, k)); world.markBlockForUpdate(i + 1, j, k - 1); } else if (world.getBlockId(i + 1, j, k + 1) == 0 && world.getBlockId(i + 1, j + 1, k + 1) == 0 && BlockFruitLeaves.canStay( world, i + 1, j, k + 1, TFCBlocks.fruitTreeLeaves.blockID)) // +x/+z { world.setBlockAndMetadata( i + 1, j, k + 1, TFCBlocks.fruitTreeLeaves.blockID, world.getBlockMetadata(i, j, k)); world.markBlockForUpdate(i + 1, j, k + 1); } else if (world.getBlockId(i - 1, j, k - 1) == 0 && world.getBlockId(i - 1, j + 1, k - 1) == 0 && BlockFruitLeaves.canStay( world, i - 1, j, k - 1, TFCBlocks.fruitTreeLeaves.blockID)) // -x/-z { world.setBlockAndMetadata( i - 1, j, k - 1, TFCBlocks.fruitTreeLeaves.blockID, world.getBlockMetadata(i, j, k)); world.markBlockForUpdate(i - 1, j, k - 1); } else if (world.getBlockId(i - 1, j, k + 1) == 0 && world.getBlockId(i - 1, j + 1, k + 1) == 0 && BlockFruitLeaves.canStay( world, i - 1, j, k + 1, TFCBlocks.fruitTreeLeaves.blockID)) // -x/+z { world.setBlockAndMetadata( i - 1, j, k + 1, TFCBlocks.fruitTreeLeaves.blockID, world.getBlockMetadata(i, j, k)); world.markBlockForUpdate(i - 1, j, k + 1); } } } }