mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-18 19:29:17 +00:00
Fix #574 clean up candle code
This commit is contained in:
1 parent
614ba3f6a9
commit
80cfe423aa
18 files changed
+329
-371
No files matched your search
@@ -10,11 +10,17 @@
|
||||
******************************************************************************/
|
||||
package forestry.apiculture.gadgets;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockTorch;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
@@ -27,10 +33,10 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
@@ -38,14 +44,42 @@ import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
import forestry.api.core.Tabs;
|
||||
import forestry.core.ForestryClient;
|
||||
import forestry.core.config.Defaults;
|
||||
import forestry.core.render.TextureManager;
|
||||
import forestry.core.utils.StackUtils;
|
||||
import forestry.core.utils.StringUtil;
|
||||
|
||||
public class BlockCandle extends BlockTorch {
|
||||
|
||||
private final ArrayList<Item> lightingItems = new ArrayList<Item>();
|
||||
private static final ImmutableMap<String, Integer> colours;
|
||||
private static final Set<Item> lightingItems;
|
||||
public static final String colourTagName = "colour";
|
||||
|
||||
static {
|
||||
colours = ImmutableMap.<String, Integer>builder()
|
||||
.put("dyeWhite", new Color(255, 255, 255).getRGB())
|
||||
.put("dyeOrange", new Color(219, 125, 62).getRGB())
|
||||
.put("dyeMagenta", new Color(255, 20, 255).getRGB())
|
||||
.put("dyeLightBlue", new Color(107, 138, 201).getRGB())
|
||||
.put("dyeYellow", new Color(255, 255, 20).getRGB())
|
||||
.put("dyeLime", new Color(20, 255, 20).getRGB())
|
||||
.put("dyePink", new Color(208, 132, 153).getRGB())
|
||||
.put("dyeGray", new Color(74, 74, 74).getRGB())
|
||||
.put("dyeLightGray", new Color(154, 161, 161).getRGB())
|
||||
.put("dyeCyan", new Color(20, 255, 255).getRGB())
|
||||
.put("dyePurple", new Color(126, 61, 181).getRGB())
|
||||
.put("dyeBlue", new Color(20, 20, 255).getRGB())
|
||||
.put("dyeBrown", new Color(79, 50, 31).getRGB())
|
||||
.put("dyeGreen", new Color(53, 70, 27).getRGB())
|
||||
.put("dyeRed", new Color(150, 52, 48).getRGB())
|
||||
.put("dyeBlack", new Color(20, 20, 20).getRGB())
|
||||
.build();
|
||||
|
||||
lightingItems = new HashSet<Item>(Arrays.asList(
|
||||
Items.flint_and_steel,
|
||||
Items.flint,
|
||||
Item.getItemFromBlock(Blocks.torch)
|
||||
));
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
private IIcon litStump;
|
||||
@@ -61,10 +95,6 @@ public class BlockCandle extends BlockTorch {
|
||||
this.setHardness(0.0F);
|
||||
this.setStepSound(soundTypeWood);
|
||||
setCreativeTab(Tabs.tabApiculture);
|
||||
|
||||
lightingItems.add(Items.flint_and_steel);
|
||||
lightingItems.add(Items.flint);
|
||||
lightingItems.add(Item.getItemFromBlock(Blocks.torch));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -95,31 +125,24 @@ public class BlockCandle extends BlockTorch {
|
||||
|
||||
@Override
|
||||
public int getLightValue(IBlockAccess world, int x, int y, int z) {
|
||||
int meta = world.getBlockMetadata(x, y, z);
|
||||
return (isLit(meta)) ? 14 : 0;
|
||||
TileEntity tileEntity = world.getTileEntity(x, y, z);
|
||||
if (tileEntity instanceof TileCandle && ((TileCandle) tileEntity).isLit()) {
|
||||
return 14;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side) {
|
||||
IIcon i = this.unlitStump;
|
||||
if (this.isLit(world.getBlockMetadata(x, y, z))) {
|
||||
i = this.litStump;
|
||||
}
|
||||
return i;
|
||||
}*/
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public IIcon getTextureFromPassAndMeta(int meta, int pass) {
|
||||
public IIcon getTextureFromPassAndLit(int pass, boolean isLit) {
|
||||
IIcon i;
|
||||
if (pass == 0) {
|
||||
if (isLit(meta)) {
|
||||
if (isLit) {
|
||||
i = this.litTip;
|
||||
} else {
|
||||
i = this.unlitTip;
|
||||
}
|
||||
} else {
|
||||
if (isLit(meta)) {
|
||||
if (isLit) {
|
||||
i = this.litStump;
|
||||
} else {
|
||||
i = this.unlitStump;
|
||||
@@ -128,232 +151,157 @@ public class BlockCandle extends BlockTorch {
|
||||
return i;
|
||||
}
|
||||
|
||||
public int getColourFromItemStack(ItemStack stack) {
|
||||
int colour = 0xffffff;
|
||||
if (stack.hasTagCompound()) {
|
||||
NBTTagCompound tag = stack.getTagCompound();
|
||||
colour = (tag.getByte("red") << 16) | (tag.getByte("green") << 8) | tag.getByte("blue");
|
||||
}
|
||||
return colour;
|
||||
}
|
||||
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
@Override
|
||||
public void getSubBlocks(Item item, CreativeTabs par2CreativeTabs, List itemList) {
|
||||
itemList.add(new ItemStack(this, 1, 0));
|
||||
}
|
||||
|
||||
// Dye names correspond to colour values as below.
|
||||
private static final String[] dyes = {"dyeWhite", "dyeOrange", "dyeMagenta", "dyeLightBlue",
|
||||
"dyeYellow", "dyeLime", "dyePink", "dyeGray",
|
||||
"dyeLightGray", "dyeCyan", "dyePurple", "dyeBlue",
|
||||
"dyeBrown", "dyeGreen", "dyeRed", "dyeBlack"};
|
||||
|
||||
private static final int[][] colours = {{255, 255, 255}, {219, 125, 62}, {255, 20, 255}, {107, 138, 201},
|
||||
{255, 255, 20}, {20, 255, 20}, {208, 132, 153}, {74, 74, 74},
|
||||
{154, 161, 161}, {20, 255, 255}, {126, 61, 181}, {20, 20, 255},
|
||||
{79, 50, 31}, {53, 70, 27}, {150, 52, 48}, {20, 20, 20}};
|
||||
|
||||
public static final String colourTagName = "colour";
|
||||
|
||||
@Override
|
||||
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int facing, float facingX, float facingY, float facingZ) {
|
||||
boolean flag = false;
|
||||
int meta = world.getBlockMetadata(x, y, z);
|
||||
boolean toggleLitState = true;
|
||||
ItemStack held = player.getCurrentEquippedItem();
|
||||
TileEntity tileEntity = world.getTileEntity(x, y, z);
|
||||
if (!(tileEntity instanceof TileCandle)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!isLit(meta)) {
|
||||
if (held == null || !lightingItems.contains(held.getItem())) {
|
||||
TileCandle tileCandle = (TileCandle) tileEntity;
|
||||
final boolean isLit = tileCandle.isLit();
|
||||
|
||||
boolean flag = false;
|
||||
boolean toggleLitState = true;
|
||||
ItemStack heldItem = player.getCurrentEquippedItem();
|
||||
|
||||
if (!isLit) {
|
||||
if (heldItem == null || !lightingItems.contains(heldItem.getItem())) {
|
||||
toggleLitState = false;
|
||||
} else if (StackUtils.equals(this, held) && isLit(held)) {
|
||||
} else if (StackUtils.equals(this, heldItem) && isLit(heldItem)) {
|
||||
toggleLitState = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (held != null) {
|
||||
// Ensure a TileEntity exists. May be able to remove this in future versions.
|
||||
TileCandle te = (TileCandle) world.getTileEntity(x, y, z);
|
||||
if (te == null) {
|
||||
world.setTileEntity(x, y, z, this.createTileEntity(world, meta));
|
||||
te = (TileCandle) world.getTileEntity(x, y, z);
|
||||
}
|
||||
|
||||
if (StackUtils.equals(this, held)) {
|
||||
if (!isLit(held)) {
|
||||
if (heldItem != null) {
|
||||
if (StackUtils.equals(this, heldItem)) {
|
||||
if (!isLit(heldItem)) {
|
||||
// Copy the colour of an unlit, coloured candle.
|
||||
if (held.hasTagCompound() && held.getTagCompound().hasKey(colourTagName)) {
|
||||
te.setColour(held.getTagCompound().getInteger(colourTagName));
|
||||
if (heldItem.hasTagCompound() && heldItem.getTagCompound().hasKey(colourTagName)) {
|
||||
tileCandle.setColour(heldItem.getTagCompound().getInteger(colourTagName));
|
||||
} else {
|
||||
// Reset to white if item has no
|
||||
te.setColour(0xffffff);
|
||||
tileCandle.setColour(0xffffff);
|
||||
}
|
||||
} else {
|
||||
toggleLitState = true;
|
||||
}
|
||||
flag = true;
|
||||
} else {
|
||||
// Check for dye-able ness.
|
||||
boolean matched = false;
|
||||
for (int i = 0; i < dyes.length; ++i) {
|
||||
for (ItemStack stack : OreDictionary.getOres(dyes[i])) {
|
||||
if (OreDictionary.itemMatches(stack, held, true)) {
|
||||
if (isLit(meta)) {
|
||||
te.setColour(colours[i][0], colours[i][1], colours[i][2]);
|
||||
} else {
|
||||
te.addColour(colours[i][0], colours[i][1], colours[i][2]);
|
||||
}
|
||||
world.markBlockForUpdate(x, y, z);
|
||||
matched = true;
|
||||
toggleLitState = false;
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (matched) {
|
||||
break;
|
||||
}
|
||||
boolean dyed = tryDye(heldItem, isLit, tileCandle);
|
||||
if (dyed) {
|
||||
world.markBlockForUpdate(x, y, z);
|
||||
toggleLitState = false;
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (toggleLitState) {
|
||||
meta = this.toggleLitStatus(meta);
|
||||
world.setBlockMetadataWithNotify(x, y, z, meta, Defaults.FLAG_BLOCK_SYNCH | Defaults.FLAG_BLOCK_UPDATE);
|
||||
tileCandle.setLit(!isLit);
|
||||
world.markBlockForUpdate(x, y, z);
|
||||
flag = true;
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void breakBlock(World world, int x, int y, int z, Block block, int meta) {
|
||||
if (!world.isRemote) {
|
||||
TileCandle tc = (TileCandle) world.getTileEntity(x, y, z);
|
||||
int newMeta = isLit(meta) ? 1 : 0;
|
||||
ItemStack stack = new ItemStack(this, 1, newMeta);
|
||||
if (tc != null && tc.getColour() != 0xffffff) {
|
||||
// When dropped, tag new item stack with colour. Unless it's white, then do no such thing for maximum stacking.
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
tag.setInteger(colourTagName, tc.getColour());
|
||||
stack.setTagCompound(tag);
|
||||
private static boolean tryDye(ItemStack held, boolean isLit, TileCandle tileCandle) {
|
||||
// Check for dye-able ness.
|
||||
boolean matched = false;
|
||||
for (Map.Entry<String, Integer> colour : colours.entrySet()) {
|
||||
String colourName = colour.getKey();
|
||||
for (ItemStack stack : OreDictionary.getOres(colourName)) {
|
||||
if (OreDictionary.itemMatches(stack, held, true)) {
|
||||
if (isLit) {
|
||||
tileCandle.setColour(colour.getValue());
|
||||
} else {
|
||||
tileCandle.addColour(colour.getValue());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
this.dropBlockAsItem(world, x, y, z, stack);
|
||||
}
|
||||
super.breakBlock(world, x, y, z, block, meta);
|
||||
return false;
|
||||
}
|
||||
|
||||
/* DROP HANDLING */
|
||||
// Hack: When harvesting we need to get the drops in onBlockHarvested,
|
||||
// because Mojang destroys the block and tile before calling getDrops.
|
||||
protected ThreadLocal<ItemStack> drop = new ThreadLocal<ItemStack>();
|
||||
|
||||
@Override
|
||||
public void onBlockHarvested(World world, int x, int y, int z, int metadata, EntityPlayer player) {
|
||||
if (!world.isRemote) {
|
||||
ItemStack itemStack = getCandleDrop(world, x, y, z);
|
||||
drop.set(itemStack);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune) {
|
||||
ItemStack dropStack = drop.get();
|
||||
drop.remove();
|
||||
|
||||
// not harvested, get drops normally
|
||||
if (dropStack == null) {
|
||||
dropStack = getCandleDrop(world, x, y, z);
|
||||
}
|
||||
|
||||
ArrayList<ItemStack> drops = new ArrayList<ItemStack>(1);
|
||||
drops.add(dropStack);
|
||||
|
||||
return drops;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z) {
|
||||
return getCandleDrop(world, x, y, z);
|
||||
}
|
||||
|
||||
private ItemStack getCandleDrop(World world, int x, int y, int z) {
|
||||
TileEntity tileEntity = world.getTileEntity(x, y, z);
|
||||
if (!(tileEntity instanceof TileCandle)) {
|
||||
return null;
|
||||
}
|
||||
TileCandle tileCandle = (TileCandle) tileEntity;
|
||||
int colour = tileCandle.getColour();
|
||||
|
||||
int newMeta = tileCandle.isLit() ? 1 : 0;
|
||||
ItemStack itemStack = new ItemStack(this, 1, newMeta);
|
||||
if (colour != 0xffffff) {
|
||||
// When dropped, tag new item stack with colour. Unless it's white, then do no such thing for maximum stacking.
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
tag.setInteger(colourTagName, colour);
|
||||
itemStack.setTagCompound(tag);
|
||||
}
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase player, ItemStack itemStack) {
|
||||
TileCandle tc = (TileCandle) (world.getTileEntity(x, y, z));
|
||||
tc.setColour(this.getColourValueFromItemStack(itemStack));
|
||||
if (isLit(itemStack)) {
|
||||
int meta = world.getBlockMetadata(x, y, z);
|
||||
world.setBlockMetadataWithNotify(x, y, z, this.toggleLitStatus(meta), Defaults.FLAG_BLOCK_SYNCH | Defaults.FLAG_BLOCK_UPDATE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dropBlockAsItemWithChance(World par1World, int par2, int par3, int par4, int par5, float par6, int par7) {
|
||||
// Does nothing to prevent extra candles from falling.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockHarvested(World par1World, int par2, int par3, int par4, int par5, EntityPlayer par6EntityPlayer) {
|
||||
// Does nothing to prevent extra candles from falling.
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean func_150109_e(World world, int x, int y, int z) {
|
||||
// Slightly tweaked version of BlockTorch's version to account for TE nonsense.
|
||||
if (!this.canPlaceBlockAt(world, x, y, z)) {
|
||||
if (world.getBlock(x, y, z) == this) {
|
||||
world.setBlockToAir(x, y, z);
|
||||
}
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
TileCandle tileCandle = (TileCandle) (world.getTileEntity(x, y, z));
|
||||
int colour = getColourValueFromItemStack(itemStack);
|
||||
boolean isLit = isLit(itemStack);
|
||||
tileCandle.setColour(colour);
|
||||
tileCandle.setLit(isLit);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void randomDisplayTick(World world, int x, int y, int z, Random random) {
|
||||
if (isLit(world.getBlockMetadata(x, y, z))) {
|
||||
int l = world.getBlockMetadata(x, y, z) & 0x07;
|
||||
double d0 = x + 0.5F;
|
||||
double d1 = y + 0.7F;
|
||||
double d2 = z + 0.5F;
|
||||
double d3 = 0.2199999988079071D;
|
||||
double d4 = 0.27000001072883606D;
|
||||
|
||||
if (l == 1) {
|
||||
world.spawnParticle("smoke", d0 - d4, d1 + d3, d2, 0.0D, 0.0D, 0.0D);
|
||||
world.spawnParticle("flame", d0 - d4, d1 + d3, d2, 0.0D, 0.0D, 0.0D);
|
||||
} else if (l == 2) {
|
||||
world.spawnParticle("smoke", d0 + d4, d1 + d3, d2, 0.0D, 0.0D, 0.0D);
|
||||
world.spawnParticle("flame", d0 + d4, d1 + d3, d2, 0.0D, 0.0D, 0.0D);
|
||||
} else if (l == 3) {
|
||||
world.spawnParticle("smoke", d0, d1 + d3, d2 - d4, 0.0D, 0.0D, 0.0D);
|
||||
world.spawnParticle("flame", d0, d1 + d3, d2 - d4, 0.0D, 0.0D, 0.0D);
|
||||
} else if (l == 4) {
|
||||
world.spawnParticle("smoke", d0, d1 + d3, d2 + d4, 0.0D, 0.0D, 0.0D);
|
||||
world.spawnParticle("flame", d0, d1 + d3, d2 + d4, 0.0D, 0.0D, 0.0D);
|
||||
} else {
|
||||
world.spawnParticle("smoke", d0, d1, d2, 0.0D, 0.0D, 0.0D);
|
||||
world.spawnParticle("flame", d0, d1, d2, 0.0D, 0.0D, 0.0D);
|
||||
}
|
||||
TileEntity tileEntity = world.getTileEntity(x, y, z);
|
||||
if (tileEntity instanceof TileCandle && ((TileCandle) tileEntity).isLit()) {
|
||||
super.randomDisplayTick(world, x, y, z, random);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean func_150108_b(World par1World, int par2, int par3, int par4, Block block) {
|
||||
if (this.func_150109_e(par1World, par2, par3, par4)) {
|
||||
int i1 = par1World.getBlockMetadata(par2, par3, par4) & 0x07;
|
||||
boolean flag = false;
|
||||
|
||||
if (!par1World.isSideSolid(par2 - 1, par3, par4, ForgeDirection.EAST, true) && i1 == 1) {
|
||||
flag = true;
|
||||
}
|
||||
|
||||
if (!par1World.isSideSolid(par2 + 1, par3, par4, ForgeDirection.WEST, true) && i1 == 2) {
|
||||
flag = true;
|
||||
}
|
||||
|
||||
if (!par1World.isSideSolid(par2, par3, par4 - 1, ForgeDirection.SOUTH, true) && i1 == 3) {
|
||||
flag = true;
|
||||
}
|
||||
|
||||
if (!par1World.isSideSolid(par2, par3, par4 + 1, ForgeDirection.NORTH, true) && i1 == 4) {
|
||||
flag = true;
|
||||
}
|
||||
|
||||
if (!this.canPlaceTorchOn(par1World, par2, par3 - 1, par4) && i1 == 5) {
|
||||
flag = true;
|
||||
}
|
||||
|
||||
if (flag) {
|
||||
this.dropBlockAsItem(par1World, par2, par3, par4, par1World.getBlockMetadata(par2, par3, par4), 0);
|
||||
par1World.setBlockToAir(par2, par3, par4);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Yes, function hiding. Go away.
|
||||
public boolean canPlaceTorchOn(World par1World, int par2, int par3, int par4) {
|
||||
if (World.doesBlockHaveSolidTopSurface(par1World, par2, par3, par4)) {
|
||||
return true;
|
||||
} else {
|
||||
Block block = par1World.getBlock(par2, par3, par4);
|
||||
return block.canPlaceTorchOnTop(par1World, par2, par3, par4);
|
||||
}
|
||||
}
|
||||
|
||||
protected int getColourValueFromItemStack(ItemStack itemStack) {
|
||||
protected static int getColourValueFromItemStack(ItemStack itemStack) {
|
||||
int value = 0xffffff; // default to white.
|
||||
if (itemStack.hasTagCompound()) {
|
||||
NBTTagCompound tag = itemStack.getTagCompound();
|
||||
@@ -364,18 +312,10 @@ public class BlockCandle extends BlockTorch {
|
||||
return value;
|
||||
}
|
||||
|
||||
public static boolean isLit(int meta) {
|
||||
return (meta & 0x08) > 0;
|
||||
}
|
||||
|
||||
public static boolean isLit(ItemStack itemStack) {
|
||||
return itemStack.getItemDamage() > 0;
|
||||
}
|
||||
|
||||
protected int toggleLitStatus(int meta) {
|
||||
return meta ^ 0x08;
|
||||
}
|
||||
|
||||
public void addItemToLightingList(Item item) {
|
||||
if (item == null) {
|
||||
throw new NullPointerException();
|
||||
|
||||
@@ -11,13 +11,14 @@
|
||||
package forestry.apiculture.gadgets;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
import forestry.apiculture.network.PacketUpdateCandle;
|
||||
|
||||
public class TileCandle extends TileEntity {
|
||||
private int colour;
|
||||
private boolean lit;
|
||||
|
||||
// This is a non-ticking Tile Entity.
|
||||
@Override
|
||||
@@ -27,48 +28,49 @@ public class TileCandle extends TileEntity {
|
||||
|
||||
@Override
|
||||
public Packet getDescriptionPacket() {
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
writeToNBT(nbt);
|
||||
|
||||
return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 0, nbt);
|
||||
PacketUpdateCandle updateCandle = new PacketUpdateCandle(this);
|
||||
return updateCandle.getPacket();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) {
|
||||
readFromNBT(pkt.func_148857_g());
|
||||
public void onPacketUpdate(PacketUpdateCandle updateCandle) {
|
||||
colour = updateCandle.getColour();
|
||||
lit = updateCandle.isLit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound tagRoot) {
|
||||
super.readFromNBT(tagRoot);
|
||||
this.setColour(tagRoot.getInteger("colour"));
|
||||
colour = tagRoot.getInteger("colour");
|
||||
lit = tagRoot.getBoolean("lit");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound tagRoot) {
|
||||
super.writeToNBT(tagRoot);
|
||||
tagRoot.setInteger("colour", this.colour);
|
||||
tagRoot.setBoolean("lit", this.lit);
|
||||
}
|
||||
|
||||
public boolean isLit() {
|
||||
return lit;
|
||||
}
|
||||
|
||||
public void setLit(boolean lit) {
|
||||
this.lit = lit;
|
||||
}
|
||||
|
||||
public int getColour() {
|
||||
return this.colour;
|
||||
return colour;
|
||||
}
|
||||
|
||||
public void setColour(int value) {
|
||||
this.colour = value;
|
||||
}
|
||||
|
||||
public void setColour(int red, int green, int blue) {
|
||||
this.colour = toIntColour(red, green, blue);
|
||||
}
|
||||
|
||||
/*public void setColour(int[] cs) {
|
||||
this.colour = toIntColour(cs[0], cs[1], cs[2]);
|
||||
}*/
|
||||
|
||||
public void addColour(int red, int green, int blue) {
|
||||
public void addColour(int colour2) {
|
||||
int[] myColour = fromIntColour(this.colour);
|
||||
this.colour = toIntColour((red + myColour[0]) / 2, (green + myColour[0]) / 2, (blue + myColour[2]) / 2);
|
||||
int[] addColour = fromIntColour(colour2);
|
||||
this.colour = toIntColour((addColour[0] + myColour[0]) / 2, (addColour[0] + myColour[0]) / 2, (addColour[2] + myColour[2]) / 2);
|
||||
}
|
||||
|
||||
private static int[] fromIntColour(int value) {
|
||||
|
||||
@@ -58,7 +58,7 @@ public class ItemCandleBlock extends ItemForestryBlock {
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public IIcon getIconFromDamageForRenderPass(int meta, int pass) {
|
||||
return ((BlockCandle) this.getBlock()).getTextureFromPassAndMeta((meta != 0) ? 8 : 0, pass);
|
||||
return this.getBlock().getIcon((meta != 0) ? 8 : 0, pass);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Executable → Regular
+21
-4
@@ -8,13 +8,15 @@
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.apiculture;
|
||||
package forestry.apiculture.network;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
import forestry.apiculture.gadgets.TileCandle;
|
||||
import forestry.apiculture.gui.ContainerImprinter;
|
||||
import forestry.core.interfaces.IPacketHandler;
|
||||
import forestry.core.network.PacketCoordinates;
|
||||
@@ -27,20 +29,28 @@ public class PacketHandlerApiculture implements IPacketHandler {
|
||||
public boolean onPacketData(int packetID, DataInputStream data, EntityPlayer player) throws IOException {
|
||||
|
||||
switch (packetID) {
|
||||
case PacketIds.HABITAT_BIOME_POINTER:
|
||||
case PacketIds.HABITAT_BIOME_POINTER: {
|
||||
PacketCoordinates packetC = new PacketCoordinates();
|
||||
packetC.readData(data);
|
||||
Proxies.common.setHabitatLocatorCoordinates(player, packetC.getCoordinates());
|
||||
return true;
|
||||
case PacketIds.IMPRINT_SELECTION_GET:
|
||||
}
|
||||
case PacketIds.IMPRINT_SELECTION_GET: {
|
||||
onImprintSelectionGet(player);
|
||||
return true;
|
||||
}
|
||||
case PacketIds.CANDLE: {
|
||||
PacketUpdateCandle updateCandle = new PacketUpdateCandle();
|
||||
updateCandle.readData(data);
|
||||
onCandleUpdate(updateCandle);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void onImprintSelectionGet(EntityPlayer playerEntity) {
|
||||
private static void onImprintSelectionGet(EntityPlayer playerEntity) {
|
||||
|
||||
if (!(playerEntity.openContainer instanceof ContainerImprinter)) {
|
||||
return;
|
||||
@@ -50,4 +60,11 @@ public class PacketHandlerApiculture implements IPacketHandler {
|
||||
|
||||
}
|
||||
|
||||
private static void onCandleUpdate(PacketUpdateCandle updateCandle) {
|
||||
TileEntity tileEntity = updateCandle.getTarget(Proxies.common.getRenderWorld());
|
||||
if (tileEntity instanceof TileCandle) {
|
||||
((TileCandle) tileEntity).onPacketUpdate(updateCandle);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package forestry.apiculture.network;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import forestry.apiculture.gadgets.TileCandle;
|
||||
import forestry.core.network.PacketCoordinates;
|
||||
import forestry.core.network.PacketIds;
|
||||
|
||||
public class PacketUpdateCandle extends PacketCoordinates {
|
||||
|
||||
private int colour;
|
||||
private boolean lit;
|
||||
|
||||
public PacketUpdateCandle() {
|
||||
|
||||
}
|
||||
|
||||
public PacketUpdateCandle(TileCandle tileCandle) {
|
||||
super(PacketIds.CANDLE, tileCandle);
|
||||
|
||||
colour = tileCandle.getColour();
|
||||
lit = tileCandle.isLit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeData(DataOutputStream data) throws IOException {
|
||||
super.writeData(data);
|
||||
data.writeInt(colour);
|
||||
data.writeBoolean(lit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(DataInputStream data) throws IOException {
|
||||
super.readData(data);
|
||||
colour = data.readInt();
|
||||
lit = data.readBoolean();
|
||||
}
|
||||
|
||||
public int getColour() {
|
||||
return colour;
|
||||
}
|
||||
|
||||
public boolean isLit() {
|
||||
return lit;
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,7 @@ package forestry.apiculture.render;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
|
||||
@@ -26,19 +27,13 @@ public class BlockCandleRenderer implements ISimpleBlockRenderingHandler {
|
||||
|
||||
@Override
|
||||
public void renderInventoryBlock(Block block, int metadata, int modelID, RenderBlocks renderer) {
|
||||
/*BlockCandle bc = (BlockCandle)block;
|
||||
Tessellator tessellator = Tessellator.instance;
|
||||
tessellator.startDrawingQuads();
|
||||
tessellator.setNormal(0.0F, -1.0F, 0.0F);
|
||||
IIcon iconA = (bc.isLit(meta)) ? bc.
|
||||
this.renderTorchAtAngle(block, -0.5D, -0.5D, -0.5D, 0.0D, 0.0D, 0);
|
||||
tessellator.draw();*/
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {
|
||||
if (block.getRenderType() == ForestryClient.candleRenderId) {
|
||||
this.renderBlockCandle(world, x, y, z, (BlockCandle) block, modelId, renderer);
|
||||
renderBlockCandle(world, x, y, z, (BlockCandle) block);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -53,13 +48,20 @@ public class BlockCandleRenderer implements ISimpleBlockRenderingHandler {
|
||||
return ForestryClient.candleRenderId;
|
||||
}
|
||||
|
||||
public boolean renderBlockCandle(IBlockAccess world, int x, int y, int z, BlockCandle block, int modelId, RenderBlocks renderer) {
|
||||
private static boolean renderBlockCandle(IBlockAccess world, int x, int y, int z, BlockCandle block) {
|
||||
int meta = world.getBlockMetadata(x, y, z);
|
||||
IIcon iconA = block.getTextureFromPassAndMeta(meta, 0);
|
||||
IIcon iconB = block.getTextureFromPassAndMeta(meta, 1);
|
||||
meta = meta & 0x7;
|
||||
TileCandle tc = (TileCandle) world.getTileEntity(x, y, z);
|
||||
int colour = tc.getColour();
|
||||
TileEntity tileEntity = world.getTileEntity(x, y, z);
|
||||
if (!(tileEntity instanceof TileCandle)) {
|
||||
return false;
|
||||
}
|
||||
TileCandle tileCandle = (TileCandle) tileEntity;
|
||||
|
||||
boolean isLit = tileCandle.isLit();
|
||||
|
||||
IIcon iconA = block.getTextureFromPassAndLit(0, isLit);
|
||||
IIcon iconB = block.getTextureFromPassAndLit(1, isLit);
|
||||
|
||||
int colour = tileCandle.getColour();
|
||||
Tessellator tessellator = Tessellator.instance;
|
||||
tessellator.setBrightness(world.getLightBrightnessForSkyBlocks(x, y, z, block.getLightValue(world, x, y, z)));
|
||||
tessellator.setColorOpaque_F(1.0F, 1.0F, 1.0F);
|
||||
@@ -68,26 +70,26 @@ public class BlockCandleRenderer implements ISimpleBlockRenderingHandler {
|
||||
double d2 = 0.20000000298023224D;
|
||||
|
||||
if (meta == 1) {
|
||||
this.renderCandleAtAngle(iconA, x - d1, y + d2, z, -d0, 0.0D, 0xffffff);
|
||||
this.renderCandleAtAngle(iconB, x - d1, y + d2, z, -d0, 0.0D, colour);
|
||||
renderCandleAtAngle(iconA, x - d1, y + d2, z, -d0, 0.0D, 0xffffff);
|
||||
renderCandleAtAngle(iconB, x - d1, y + d2, z, -d0, 0.0D, colour);
|
||||
} else if (meta == 2) {
|
||||
this.renderCandleAtAngle(iconA, x + d1, y + d2, z, d0, 0.0D, 0xffffff);
|
||||
this.renderCandleAtAngle(iconB, x + d1, y + d2, z, d0, 0.0D, colour);
|
||||
renderCandleAtAngle(iconA, x + d1, y + d2, z, d0, 0.0D, 0xffffff);
|
||||
renderCandleAtAngle(iconB, x + d1, y + d2, z, d0, 0.0D, colour);
|
||||
} else if (meta == 3) {
|
||||
this.renderCandleAtAngle(iconA, x, y + d2, z - d1, 0.0D, -d0, 0xffffff);
|
||||
this.renderCandleAtAngle(iconB, x, y + d2, z - d1, 0.0D, -d0, colour);
|
||||
renderCandleAtAngle(iconA, x, y + d2, z - d1, 0.0D, -d0, 0xffffff);
|
||||
renderCandleAtAngle(iconB, x, y + d2, z - d1, 0.0D, -d0, colour);
|
||||
} else if (meta == 4) {
|
||||
this.renderCandleAtAngle(iconA, x, y + d2, z + d1, 0.0D, d0, 0xffffff);
|
||||
this.renderCandleAtAngle(iconB, x, y + d2, z + d1, 0.0D, d0, colour);
|
||||
renderCandleAtAngle(iconA, x, y + d2, z + d1, 0.0D, d0, 0xffffff);
|
||||
renderCandleAtAngle(iconB, x, y + d2, z + d1, 0.0D, d0, colour);
|
||||
} else {
|
||||
this.renderCandleAtAngle(iconA, x, y, z, 0.0D, 0.0D, 0xffffff);
|
||||
this.renderCandleAtAngle(iconB, x, y, z, 0.0D, 0.0D, colour);
|
||||
renderCandleAtAngle(iconA, x, y, z, 0.0D, 0.0D, 0xffffff);
|
||||
renderCandleAtAngle(iconB, x, y, z, 0.0D, 0.0D, colour);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void renderCandleAtAngle(IIcon icon, double x, double y, double z, double par8, double par10, int colour) {
|
||||
private static void renderCandleAtAngle(IIcon icon, double x, double y, double z, double par8, double par10, int colour) {
|
||||
Tessellator tessellator = Tessellator.instance;
|
||||
double minU = icon.getMinU();
|
||||
double minV = icon.getMinV();
|
||||
|
||||
@@ -4,19 +4,14 @@ import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.arboriculture.ITree;
|
||||
import forestry.api.genetics.IAllele;
|
||||
import forestry.arboriculture.gadgets.TileTreeContainer;
|
||||
import forestry.core.network.ForestryPacket;
|
||||
import forestry.core.network.ILocatedPacket;
|
||||
import forestry.core.network.PacketCoordinates;
|
||||
import forestry.plugins.PluginArboriculture;
|
||||
|
||||
public class PacketTreeContainer extends ForestryPacket implements ILocatedPacket {
|
||||
public class PacketTreeContainer extends PacketCoordinates {
|
||||
|
||||
private int posX, posY, posZ;
|
||||
protected String speciesUID = "";
|
||||
|
||||
public PacketTreeContainer() {
|
||||
@@ -24,11 +19,7 @@ public class PacketTreeContainer extends ForestryPacket implements ILocatedPacke
|
||||
}
|
||||
|
||||
public PacketTreeContainer(int id, TileTreeContainer treeContainer) {
|
||||
super(id);
|
||||
|
||||
posX = treeContainer.xCoord;
|
||||
posY = treeContainer.yCoord;
|
||||
posZ = treeContainer.zCoord;
|
||||
super(id, treeContainer);
|
||||
|
||||
ITree tree = treeContainer.getTree();
|
||||
if (tree != null) {
|
||||
@@ -38,25 +29,16 @@ public class PacketTreeContainer extends ForestryPacket implements ILocatedPacke
|
||||
|
||||
@Override
|
||||
public void writeData(DataOutputStream data) throws IOException {
|
||||
data.writeShort(posX);
|
||||
data.writeShort(posY);
|
||||
data.writeShort(posZ);
|
||||
super.writeData(data);
|
||||
data.writeUTF(speciesUID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(DataInputStream data) throws IOException {
|
||||
posX = data.readShort();
|
||||
posY = data.readShort();
|
||||
posZ = data.readShort();
|
||||
super.readData(data);
|
||||
speciesUID = data.readUTF();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity getTarget(World world) {
|
||||
return world.getTileEntity(posX, posY, posZ);
|
||||
}
|
||||
|
||||
public boolean matchesTree(ITree tree) {
|
||||
if (tree == null) {
|
||||
return speciesUID.isEmpty();
|
||||
|
||||
@@ -144,7 +144,7 @@ public class LeavesRenderingHandler extends OverlayRenderingHandler implements I
|
||||
}
|
||||
}
|
||||
|
||||
private void renderItem(RenderBlocks renderer, ItemStack itemStack, float x, float y, float z) {
|
||||
private static void renderItem(RenderBlocks renderer, ItemStack itemStack, float x, float y, float z) {
|
||||
Tessellator tessellator = Tessellator.instance;
|
||||
Block block = StackUtils.getBlock(itemStack);
|
||||
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.core.network;
|
||||
|
||||
/**
|
||||
* Keeps track of the indices to use when writing data to payload arrays. Internal use only.
|
||||
*/
|
||||
public class IndexInPayload {
|
||||
public IndexInPayload(int intIndex, int floatIndex, int stringIndex) {
|
||||
this.intIndex = intIndex;
|
||||
this.floatIndex = floatIndex;
|
||||
this.stringIndex = stringIndex;
|
||||
}
|
||||
|
||||
public int intIndex = 0;
|
||||
public int floatIndex = 0;
|
||||
public int stringIndex = 0;
|
||||
}
|
||||
@@ -20,13 +20,17 @@ import net.minecraft.world.World;
|
||||
|
||||
public class PacketCoordinates extends ForestryPacket implements ILocatedPacket {
|
||||
|
||||
public int posX;
|
||||
public int posY;
|
||||
public int posZ;
|
||||
private int posX;
|
||||
private int posY;
|
||||
private int posZ;
|
||||
|
||||
public PacketCoordinates() {
|
||||
}
|
||||
|
||||
public PacketCoordinates(int id, TileEntity tileEntity) {
|
||||
this(id, tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord);
|
||||
}
|
||||
|
||||
public PacketCoordinates(int id, ChunkCoordinates coordinates) {
|
||||
this(id, coordinates.posX, coordinates.posY, coordinates.posZ);
|
||||
}
|
||||
@@ -60,6 +64,18 @@ public class PacketCoordinates extends ForestryPacket implements ILocatedPacket
|
||||
return new ChunkCoordinates(posX, posY, posZ);
|
||||
}
|
||||
|
||||
public int getPosX() {
|
||||
return posX;
|
||||
}
|
||||
|
||||
public int getPosY() {
|
||||
return posY;
|
||||
}
|
||||
|
||||
public int getPosZ() {
|
||||
return posZ;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity getTarget(World world) {
|
||||
return world.getTileEntity(posX, posY, posZ);
|
||||
|
||||
@@ -20,7 +20,7 @@ import cpw.mods.fml.common.registry.GameData;
|
||||
|
||||
import forestry.core.proxy.Proxies;
|
||||
|
||||
public class PacketFXSignal extends ForestryPacket {
|
||||
public class PacketFXSignal extends PacketCoordinates {
|
||||
|
||||
public enum VisualFXType {
|
||||
NONE, BLOCK_DESTROY, SAPLING_PLACE
|
||||
@@ -41,9 +41,6 @@ public class PacketFXSignal extends ForestryPacket {
|
||||
private VisualFXType visualFX;
|
||||
private SoundFXType soundFX;
|
||||
|
||||
private int xCoord;
|
||||
private int yCoord;
|
||||
private int zCoord;
|
||||
private Block block;
|
||||
private int meta;
|
||||
|
||||
@@ -59,49 +56,42 @@ public class PacketFXSignal extends ForestryPacket {
|
||||
}
|
||||
|
||||
public PacketFXSignal(VisualFXType visualFX, SoundFXType soundFX, int xCoord, int yCoord, int zCoord, Block block, int meta) {
|
||||
super(PacketIds.FX_SIGNAL);
|
||||
super(PacketIds.FX_SIGNAL, xCoord, yCoord, zCoord);
|
||||
this.visualFX = visualFX;
|
||||
this.soundFX = soundFX;
|
||||
this.xCoord = xCoord;
|
||||
this.yCoord = yCoord;
|
||||
this.zCoord = zCoord;
|
||||
this.block = block;
|
||||
this.meta = meta;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeData(DataOutputStream data) throws IOException {
|
||||
super.writeData(data);
|
||||
data.writeShort(visualFX.ordinal());
|
||||
data.writeShort(soundFX.ordinal());
|
||||
data.writeInt(xCoord);
|
||||
data.writeInt(yCoord);
|
||||
data.writeInt(zCoord);
|
||||
data.writeUTF(GameData.getBlockRegistry().getNameForObject(block));
|
||||
data.writeInt(meta);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(DataInputStream data) throws IOException {
|
||||
super.readData(data);
|
||||
this.visualFX = VisualFXType.values()[data.readShort()];
|
||||
this.soundFX = SoundFXType.values()[data.readShort()];
|
||||
this.xCoord = data.readInt();
|
||||
this.yCoord = data.readInt();
|
||||
this.zCoord = data.readInt();
|
||||
this.block = GameData.getBlockRegistry().getRaw(data.readUTF());
|
||||
this.meta = data.readInt();
|
||||
}
|
||||
|
||||
public void executeFX() {
|
||||
if (visualFX != VisualFXType.NONE) {
|
||||
Proxies.common.addBlockDestroyEffects(Proxies.common.getRenderWorld(), xCoord, yCoord, zCoord, block, meta);
|
||||
Proxies.common.addBlockDestroyEffects(Proxies.common.getRenderWorld(), getPosX(), getPosY(), getPosZ(), block, meta);
|
||||
}
|
||||
if (soundFX != SoundFXType.NONE) {
|
||||
if (soundFX == SoundFXType.BLOCK_DESTROY) {
|
||||
Proxies.common.playBlockBreakSoundFX(Proxies.common.getRenderWorld(), xCoord, yCoord, zCoord, block);
|
||||
Proxies.common.playBlockBreakSoundFX(Proxies.common.getRenderWorld(), getPosX(), getPosY(), getPosZ(), block);
|
||||
} else if (soundFX == SoundFXType.BLOCK_PLACE) {
|
||||
Proxies.common.playBlockPlaceSoundFX(Proxies.common.getRenderWorld(), xCoord, yCoord, zCoord, block);
|
||||
Proxies.common.playBlockPlaceSoundFX(Proxies.common.getRenderWorld(), getPosX(), getPosY(), getPosZ(), block);
|
||||
} else {
|
||||
Proxies.common.playSoundFX(Proxies.common.getRenderWorld(), xCoord, yCoord, zCoord, soundFX.soundFile, soundFX.volume, soundFX.pitch);
|
||||
Proxies.common.playSoundFX(Proxies.common.getRenderWorld(), getPosX(), getPosY(), getPosZ(), soundFX.soundFile, soundFX.volume, soundFX.pitch);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -213,7 +213,7 @@ public class PacketHandler {
|
||||
private void onSocketUpdate(PacketSocketUpdate packet) {
|
||||
assert FMLCommonHandler.instance().getEffectiveSide().isClient();
|
||||
|
||||
TileEntity tile = Proxies.common.getRenderWorld().getTileEntity(packet.posX, packet.posY, packet.posZ);
|
||||
TileEntity tile = packet.getTarget(Proxies.common.getRenderWorld());
|
||||
if (!(tile instanceof ISocketable)) {
|
||||
return;
|
||||
}
|
||||
@@ -235,7 +235,7 @@ public class PacketHandler {
|
||||
|
||||
private void onInventoryStack(PacketInventoryStack packet) {
|
||||
|
||||
TileEntity tile = Proxies.common.getRenderWorld().getTileEntity(packet.posX, packet.posY, packet.posZ);
|
||||
TileEntity tile = packet.getTarget(Proxies.common.getRenderWorld());
|
||||
if (tile == null) {
|
||||
return;
|
||||
}
|
||||
@@ -274,7 +274,7 @@ public class PacketHandler {
|
||||
private void onAccessSwitch(PacketCoordinates packet, EntityPlayer playerEntity) {
|
||||
assert FMLCommonHandler.instance().getEffectiveSide().isServer();
|
||||
|
||||
TileForestry tile = (TileForestry) playerEntity.worldObj.getTileEntity(packet.posX, packet.posY, packet.posZ);
|
||||
TileForestry tile = (TileForestry) packet.getTarget(playerEntity.worldObj);
|
||||
if (tile == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ public class PacketIds {
|
||||
public static final int TILE_NBT = 5;
|
||||
|
||||
public static final int HABITAT_BIOME_POINTER = 20;
|
||||
public static final int CANDLE = 21;
|
||||
|
||||
public static final int GUI_SELECTION_CHANGE = 30;
|
||||
public static final int IMPRINT_SELECTION_GET = 31;
|
||||
|
||||
@@ -60,15 +60,6 @@ public class PacketPayload {
|
||||
this.intPayload = Utils.concat(this.intPayload, other);
|
||||
}
|
||||
|
||||
/*
|
||||
* public void splitTail(IndexInPayload index) { PacketPayload payload = new PacketPayload(intPayload.length - index.intIndex, floatPayload.length -
|
||||
* index.floatIndex, stringPayload.length - index.stringIndex);
|
||||
*
|
||||
* if (intPayload.length > 0) { System.arraycopy(intPayload, index.intIndex, payload.intPayload, 0, payload.intPayload.length); } if (floatPayload.length >
|
||||
* 0) { System.arraycopy(floatPayload, index.floatIndex, payload.floatPayload, 0, payload.floatPayload.length); } if (stringPayload.length > 0) {
|
||||
* System.arraycopy(stringPayload, index.stringIndex, payload.stringPayload, 0, payload.stringPayload.length); } }
|
||||
*/
|
||||
|
||||
public boolean isEmpty() {
|
||||
return intPayload.length == 0 && shortPayload.length == 0 && floatPayload.length == 0 && stringPayload.length == 0;
|
||||
}
|
||||
|
||||
@@ -38,11 +38,7 @@ public class PacketTileUpdate extends PacketUpdate {
|
||||
}
|
||||
|
||||
public PacketTileUpdate(TileForestry tile) {
|
||||
super(PacketIds.TILE_FORESTRY_UPDATE, tile.getPacketPayload());
|
||||
|
||||
posX = tile.xCoord;
|
||||
posY = tile.yCoord;
|
||||
posZ = tile.zCoord;
|
||||
super(PacketIds.TILE_FORESTRY_UPDATE, tile);
|
||||
|
||||
orientation = tile.getOrientation();
|
||||
errorState = tile.getErrorState();
|
||||
|
||||
@@ -14,6 +14,8 @@ import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import forestry.core.gadgets.TileForestry;
|
||||
|
||||
public class PacketUpdate extends PacketCoordinates {
|
||||
|
||||
public PacketPayload payload;
|
||||
@@ -22,7 +24,12 @@ public class PacketUpdate extends PacketCoordinates {
|
||||
}
|
||||
|
||||
public PacketUpdate(int id) {
|
||||
this(id, null);
|
||||
this(id, 0, 0, 0, null);
|
||||
}
|
||||
|
||||
public PacketUpdate(int id, TileForestry tile) {
|
||||
super(id, tile);
|
||||
this.payload = tile.getPacketPayload();
|
||||
}
|
||||
|
||||
public PacketUpdate(int id, PacketPayload payload) {
|
||||
|
||||
@@ -30,13 +30,8 @@ import buildcraft.transport.TileGenericPipe;
|
||||
|
||||
public class PacketHandlerPipes implements IPacketHandler {
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private Pipe getPipe(World world, int x, int y, int z) {
|
||||
TileEntity tile = world.getTileEntity(x, y, z);
|
||||
if (tile == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static Pipe getPipe(World world, PacketCoordinates packet) {
|
||||
TileEntity tile = packet.getTarget(world);
|
||||
if (!(tile instanceof TileGenericPipe)) {
|
||||
return null;
|
||||
}
|
||||
@@ -81,7 +76,7 @@ public class PacketHandlerPipes implements IPacketHandler {
|
||||
return false;
|
||||
}
|
||||
|
||||
private void onFilterSet(PacketNBT packet) {
|
||||
private static void onFilterSet(PacketNBT packet) {
|
||||
Container container = Proxies.common.getClientInstance().thePlayer.openContainer;
|
||||
|
||||
if (container instanceof ContainerPropolisPipe) {
|
||||
@@ -90,10 +85,9 @@ public class PacketHandlerPipes implements IPacketHandler {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private void onTypeFilterChange(EntityPlayer player, PacketUpdate packet) {
|
||||
private static void onTypeFilterChange(EntityPlayer player, PacketUpdate packet) {
|
||||
|
||||
Pipe pipe = getPipe(player.worldObj, packet.posX, packet.posY, packet.posZ);
|
||||
Pipe pipe = getPipe(player.worldObj, packet);
|
||||
if (pipe == null) {
|
||||
return;
|
||||
}
|
||||
@@ -104,10 +98,9 @@ public class PacketHandlerPipes implements IPacketHandler {
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private void onGenomeFilterChange(EntityPlayer player, PacketUpdate packet) {
|
||||
private static void onGenomeFilterChange(EntityPlayer player, PacketUpdate packet) {
|
||||
|
||||
Pipe pipe = getPipe(player.worldObj, packet.posX, packet.posY, packet.posZ);
|
||||
Pipe pipe = getPipe(player.worldObj, packet);
|
||||
if (pipe == null) {
|
||||
return;
|
||||
}
|
||||
@@ -117,10 +110,9 @@ public class PacketHandlerPipes implements IPacketHandler {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private void onRequestFilterSet(EntityPlayer player, PacketCoordinates packet) {
|
||||
private static void onRequestFilterSet(EntityPlayer player, PacketCoordinates packet) {
|
||||
|
||||
Pipe pipe = getPipe(player.worldObj, packet.posX, packet.posY, packet.posZ);
|
||||
Pipe pipe = getPipe(player.worldObj, packet);
|
||||
if (pipe == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -65,7 +65,6 @@ import forestry.api.recipes.RecipeManagers;
|
||||
import forestry.api.storage.ICrateRegistry;
|
||||
import forestry.api.storage.StorageManager;
|
||||
import forestry.apiculture.GuiHandlerApiculture;
|
||||
import forestry.apiculture.PacketHandlerApiculture;
|
||||
import forestry.apiculture.SaveEventHandlerApiculture;
|
||||
import forestry.apiculture.VillageHandlerApiculture;
|
||||
import forestry.apiculture.commands.CommandBee;
|
||||
@@ -126,6 +125,7 @@ import forestry.apiculture.items.ItemHiveFrame;
|
||||
import forestry.apiculture.items.ItemHoneycomb;
|
||||
import forestry.apiculture.items.ItemImprinter;
|
||||
import forestry.apiculture.items.ItemWaxCast;
|
||||
import forestry.apiculture.network.PacketHandlerApiculture;
|
||||
import forestry.apiculture.proxy.ProxyApiculture;
|
||||
import forestry.apiculture.trigger.ApicultureTriggers;
|
||||
import forestry.apiculture.worldgen.HiveDecorator;
|
||||
|
||||
Reference in new issue
Block a user