From 0427ab89f1753a44b30cbc35ce021cbbdc845109 Mon Sep 17 00:00:00 2001 From: Foghrye4 Date: Thu, 10 Aug 2017 18:52:45 +0300 Subject: fix missing source folder --- src/main/java/ihl/utils/BlockItemRender.java | 218 +++++ .../java/ihl/utils/EntityDropEventHandler.java | 16 + src/main/java/ihl/utils/FluidDictionary.java | 42 + src/main/java/ihl/utils/GuiMultiTextureButton.java | 47 + src/main/java/ihl/utils/IHLFluidTank.java | 322 +++++++ src/main/java/ihl/utils/IHLInvSlotDischarge.java | 83 ++ src/main/java/ihl/utils/IHLItemRenderer.java | 297 +++++++ src/main/java/ihl/utils/IHLMathUtils.java | 103 +++ src/main/java/ihl/utils/IHLRenderUtils.java | 819 ++++++++++++++++++ src/main/java/ihl/utils/IHLUtils.java | 953 +++++++++++++++++++++ 10 files changed, 2900 insertions(+) create mode 100644 src/main/java/ihl/utils/BlockItemRender.java create mode 100644 src/main/java/ihl/utils/EntityDropEventHandler.java create mode 100644 src/main/java/ihl/utils/FluidDictionary.java create mode 100644 src/main/java/ihl/utils/GuiMultiTextureButton.java create mode 100644 src/main/java/ihl/utils/IHLFluidTank.java create mode 100644 src/main/java/ihl/utils/IHLInvSlotDischarge.java create mode 100644 src/main/java/ihl/utils/IHLItemRenderer.java create mode 100644 src/main/java/ihl/utils/IHLMathUtils.java create mode 100644 src/main/java/ihl/utils/IHLRenderUtils.java create mode 100644 src/main/java/ihl/utils/IHLUtils.java (limited to 'src/main/java/ihl/utils') diff --git a/src/main/java/ihl/utils/BlockItemRender.java b/src/main/java/ihl/utils/BlockItemRender.java new file mode 100644 index 0000000..34d1499 --- /dev/null +++ b/src/main/java/ihl/utils/BlockItemRender.java @@ -0,0 +1,218 @@ +package ihl.utils; + +import org.lwjgl.opengl.GL11; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import ic2.core.block.RenderBlockDefault; +import ihl.items_blocks.IHLItemBlock; +import ihl.model.IHLModelRenderer; +import net.minecraft.block.Block; +import net.minecraft.client.Minecraft; +import net.minecraft.client.entity.EntityClientPlayerMP; +import net.minecraft.client.model.ModelBase; +import net.minecraft.client.model.ModelRenderer; +import net.minecraft.client.renderer.RenderBlocks; +import net.minecraft.client.renderer.entity.RenderManager; +import net.minecraft.client.renderer.entity.RenderPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.client.IItemRenderer; + +@SideOnly(value = Side.CLIENT) +public class BlockItemRender implements IItemRenderer{ + private ModelBase model; + private ResourceLocation tex; + private int renderFrom=0; + private int renderTo=0; + private RenderBlockDefault rbd; + private float amendment=0.0F; + private float inventoryOffset=0.0F; + private boolean renderHand; + +public BlockItemRender() +{ + rbd=new RenderBlockDefault(); +} + +public BlockItemRender(ModelBase model1, ResourceLocation texture, int renderFrom1, int renderTo1, float amendment1, float inventoryOffset1) +{ + this.model=model1; + this.tex=texture; + this.renderFrom=renderFrom1; + this.renderTo=renderTo1; + this.amendment=amendment1; + this.inventoryOffset=inventoryOffset1; + this.renderHand=false; +} + +public BlockItemRender(ModelBase model1, ResourceLocation texture, int renderFrom1, int renderTo1, float amendment1, float inventoryOffset1, boolean renderHand1) +{ + this.model=model1; + this.tex=texture; + this.renderFrom=renderFrom1; + this.renderTo=renderTo1; + this.amendment=amendment1; + this.inventoryOffset=inventoryOffset1; + this.renderHand=renderHand1; +} + +@Override +public boolean handleRenderType(ItemStack item, ItemRenderType type) { + switch (type) { + case ENTITY: + return true; + case EQUIPPED: + return true; + case EQUIPPED_FIRST_PERSON: + return true; + case INVENTORY: + return true; + default: + return false; + } +} + +@Override +public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper) { + return true; +} + +@Override +public void renderItem(ItemRenderType type, ItemStack item, Object... data) { + if(tex!=null) + { + Minecraft.getMinecraft().renderEngine.bindTexture(tex); + } + GL11.glPushMatrix(); + GL11.glEnable(GL11.GL_BLEND); + GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + IHLItemBlock bItem =(IHLItemBlock) item.getItem(); + Block block = bItem.getBlockContained(); + GL11.glScalef(1F, -1F+amendment, -1F); + if(item.stackTagCompound!=null && item.stackTagCompound.hasKey("colour")){ + int colour = item.stackTagCompound.getInteger("colour"); + GL11.glColor4f((colour>>>16)/255f,((colour>>>8)&255)/255f, (colour&255)/255f,1f); + } + switch (type) { + case ENTITY: + GL11.glTranslatef(0,-1.5F,0); + if(model!=null) + { + for(int i = this.renderFrom;i>>16)/255f,((colour>>>8)&255)/255f, (colour&255)/255f,1f); + } + if(model!=null) + { + for(int i = this.renderFrom;i> nameToStack = new HashMap>(); + private Map fluidToName = new HashMap(); + public FluidDictionary(){} + + public List getFluids(String fdName) + { + return nameToStack.get(fdName); + } + + public void registerFluidStack(String fdName, FluidStack fstack) + { + if(nameToStack.containsKey(fdName)) + { + nameToStack.get(fdName).add(fstack); + } + else + { + List list = new ArrayList(); + list.add(fstack); + nameToStack.put(fdName, list); + } + fluidToName.put(fstack.getFluid(), fdName); + } + + public String getFluidName(Fluid f) + { + return fluidToName.get(f); + } + +} diff --git a/src/main/java/ihl/utils/GuiMultiTextureButton.java b/src/main/java/ihl/utils/GuiMultiTextureButton.java new file mode 100644 index 0000000..009c57f --- /dev/null +++ b/src/main/java/ihl/utils/GuiMultiTextureButton.java @@ -0,0 +1,47 @@ +package ihl.utils; + +import org.lwjgl.opengl.GL11; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.util.ResourceLocation; + +@SideOnly(value = Side.CLIENT) +public class GuiMultiTextureButton extends GuiButton { + + private ResourceLocation texture; + private int textureX; + private int textureY; + private int textureActiveX; + private int textureActiveY; + public boolean isActive=false; + + public GuiMultiTextureButton(int id1, int x, int y, int w, int h, + ResourceLocation texture1, int textureX1, int textureY1, int textureActiveX1, int textureActiveY1) { + super(id1, x, y, w, h, ""); + texture=texture1; + textureX=textureX1; + textureY=textureY1; + textureActiveX=textureActiveX1; + textureActiveY=textureActiveY1; + + } + + @Override + public void drawButton(Minecraft minecraft, int i, int j) + { + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + minecraft.getTextureManager().bindTexture(this.texture); + if(this.isActive) + { + this.drawTexturedModalRect(this.xPosition, this.yPosition, this.textureActiveX, this.textureActiveY, this.width, this.height); + } + else + { + this.drawTexturedModalRect(this.xPosition, this.yPosition, this.textureX, this.textureY, this.width, this.height); + } + } + +} diff --git a/src/main/java/ihl/utils/IHLFluidTank.java b/src/main/java/ihl/utils/IHLFluidTank.java new file mode 100644 index 0000000..67597e1 --- /dev/null +++ b/src/main/java/ihl/utils/IHLFluidTank.java @@ -0,0 +1,322 @@ +package ihl.utils; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import ihl.recipes.IRecipeInputFluid; +import ihl.worldgen.ores.IHLFluid; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraftforge.fluids.FluidRegistry; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidTankInfo; +import net.minecraftforge.fluids.IFluidTank; + +public class IHLFluidTank implements IFluidTank { + private final List fluidList = new ArrayList(); + private final int capacity; + + public IHLFluidTank(int capacity) { + this.capacity = capacity; + } + + public IHLFluidTank(int capacity, boolean isOpenVessel1) { + this.capacity = capacity; + } + + public IHLFluidTank readFromNBT(NBTTagCompound nbt) { + if (!nbt.hasKey("Empty")) { + NBTTagList fluidList1 = nbt.getTagList("fluids", 10); + for (int i = 0; i < fluidList1.tagCount(); i++) { + NBTTagCompound fluidNBT1 = fluidList1.getCompoundTagAt(i); + FluidStack fluid = FluidStack.loadFluidStackFromNBT(fluidNBT1); + if (fluid != null) { + fluidList.add(fluid); + } + } + } + return this; + } + + public NBTTagCompound writeToNBT(NBTTagCompound nbt) { + if (!fluidList.isEmpty()) { + NBTTagList fluids = new NBTTagList(); + Iterator fli = fluidList.iterator(); + while (fli.hasNext()) { + FluidStack fluid = fli.next(); + if (fluid != null) { + NBTTagCompound fluidNBT1 = new NBTTagCompound(); + fluid.writeToNBT(fluidNBT1); + fluids.appendTag(fluidNBT1); + } + } + nbt.setTag("fluids", fluids); + } else { + nbt.setString("Empty", ""); + } + return nbt; + } + + /* IFluidTank */ + @Override + public FluidStack getFluid() { + if (this.fluidList.isEmpty()) { + return null; + } + return this.fluidList.get(0); + } + + public FluidStack getLigthestFluid() { + if (this.fluidList.isEmpty()) { + return IHLUtils.getFluidStackWithSize("air", this.capacity); + } + return this.fluidList.get(this.fluidList.size() - 1); + } + + @Override + public int getFluidAmount() { + int amount = 0; + Iterator fli = fluidList.iterator(); + while (fli.hasNext()) { + FluidStack fluid = fli.next(); + if (fluid != null) { + amount += fluid.amount; + } + } + return amount; + } + + @Override + public int getCapacity() { + return capacity; + } + + @Override + public FluidTankInfo getInfo() { + return new FluidTankInfo(this); + } + + @Override + public int fill(FluidStack resource, boolean doFill) { + if (resource == null) + return 0; + int freeSpace = capacity - this.getFluidAmount(); + int amount1 = Math.min(freeSpace, resource.amount); + if (resource.getFluid() == null || amount1<=0) { + return 0; + } + if (!doFill) { + return amount1; + } + FluidStack fluid = getFluidStackWithSameFluid(resource); + if (fluid != null) { + fluid.amount += amount1; + return amount1; + } + fluid = copyWithSize(resource, amount1); + fluidList.add(fluid); + this.sortFluidsByDensity(); + return amount1; + } + + @Override + public FluidStack drain(int maxDrain, boolean doDrain) { + if (fluidList.isEmpty()) { + return null; + } + FluidStack fstack = this.getFluid().copy(); + fstack.amount = maxDrain; + return this.drain(fstack, doDrain); + } + + public FluidStack drainLightest(int maxDrain, boolean doDrain) { + if (fluidList.isEmpty()) { + return null; + } + FluidStack fstack = this.getLigthestFluid().copy(); + fstack.amount = maxDrain; + return this.drain(fstack, doDrain); + } + + public FluidStack drain(Object fluidStack, boolean doDrain) { + if (fluidList.isEmpty()) { + return null; + } + int drained = 0; + if (fluidStack instanceof FluidStack) { + drained = ((FluidStack) fluidStack).amount; + } else { + drained = ((IRecipeInputFluid) fluidStack).getAmount(); + } + FluidStack fluid = this.getFluidStackWithSameFluid(fluidStack); + if (fluid == null) { + return null; + } + if (fluid.amount < drained) { + drained = fluid.amount; + } + FluidStack stack = copyWithSize(fluid, drained); + if (doDrain) { + fluid.amount -= drained; + if (fluid.amount <= 0) { + this.fluidList.remove(fluid); + } + } + return stack; + } + + public FluidStack getFluidStackWithSameFluid(Object fluidStack) { + Iterator fli = fluidList.iterator(); + while (fli.hasNext()) { + FluidStack fluid = fli.next(); + if (fluid != null) { + if (fluidStack instanceof FluidStack) { + if (fluid.isFluidEqual((FluidStack) fluidStack)) { + return fluid; + } + } else { + if (((IRecipeInputFluid) fluidStack).matches(fluid)) { + return fluid; + } + } + } + } + return null; + } + + public int getNumberOfFluids() { + return this.fluidList.size(); + } + + public void setFluidAmount(int amount1, int index) { + if (this.fluidList.size() <= index) { + while (this.fluidList.size() <= index) { + this.fluidList.add(new FluidStack(FluidRegistry.WATER, 1)); + } + } + this.fluidList.get(index).amount = amount1; + } + + public int getFluidAmount(int index) { + if (this.fluidList.size() <= index || this.fluidList.get(index) == null) { + return 0; + } + return this.fluidList.get(index).amount; + } + + public int getFluidID(int i) { + if (this.fluidList.get(i) == null) { + return -1; + } + return this.fluidList.get(i).getFluid().getID(); + } + + public void sortFluidsByDensity() { + Map sortMap = new HashMap(); + int[] keysArray = new int[fluidList.size()]; + Iterator fli = fluidList.iterator(); + while (fli.hasNext()) { + FluidStack fluid = fli.next(); + if (fluid == null) { + return; + } + int key = Math.round(IHLFluid.getRealDensity(fluid.getFluid()) * 100F); + while (sortMap.containsKey(key)) { + key++; + } + sortMap.put(key, fluid); + keysArray[fluidList.indexOf(fluid)] = key; + } + Arrays.sort(keysArray); + ArrayList newFluidList = new ArrayList(); + for (int i = keysArray.length - 1; i >= 0; i--) { + newFluidList.add(sortMap.get(keysArray[i])); + } + this.fluidList.clear(); + this.fluidList.addAll(newFluidList); + } + + public FluidStack getFluid(int i) { + return this.fluidList.get(i); + } + + public void setTag(String string, int t1_1) { + if (this.getFluid().tag == null) { + this.getFluid().tag = new NBTTagCompound(); + } + this.getFluid().tag.setInteger(string, t1_1); + } + + public void setEmpty() { + this.fluidList.clear(); + } + + public List getFluidList() { + return this.fluidList; + } + + public void drain(List fluidInputs, boolean doDrain) { + if (fluidInputs != null && !fluidInputs.isEmpty()) { + Iterator fsi = fluidInputs.iterator(); + while (fsi.hasNext()) { + this.drain(fsi.next(), doDrain); + } + } + } + + public void fill(List fluidOutputs, boolean doFill) { + if (fluidOutputs != null && !fluidOutputs.isEmpty()) { + Iterator fsi = fluidOutputs.iterator(); + while (fsi.hasNext()) { + this.fill(fsi.next(), doFill); + } + } + } + + private FluidStack copyWithSize(FluidStack resource, int amount1) { + FluidStack fluid = resource.copy(); + fluid.amount = amount1; + if (resource.tag != null) { + fluid.tag = (NBTTagCompound) resource.tag.copy(); + } + return fluid; + } + + public FluidStack drain(IRecipeInputFluid fluidStack, int amount, boolean doDrain) { + if (fluidList.isEmpty()) { + return null; + } + int drained = amount; + FluidStack fluid = this.getFluidStackWithSameFluid(fluidStack); + if (fluid == null) { + return null; + } + if (fluid.amount < drained) { + drained = fluid.amount; + } + FluidStack stack = copyWithSize(fluid, drained); + if (doDrain) { + fluid.amount -= drained; + if (fluid.amount <= 0) { + this.fluidList.remove(fluid); + } + } + return stack; + } + + public void checkCorrectState() { + if (!this.fluidList.isEmpty()) { + Iterator fsi = this.fluidList.iterator(); + while (fsi.hasNext()) { + FluidStack fs = fsi.next(); + if (fs.amount <= 0) { + fsi.remove(); + } + } + } + } +} diff --git a/src/main/java/ihl/utils/IHLInvSlotDischarge.java b/src/main/java/ihl/utils/IHLInvSlotDischarge.java new file mode 100644 index 0000000..ffa4216 --- /dev/null +++ b/src/main/java/ihl/utils/IHLInvSlotDischarge.java @@ -0,0 +1,83 @@ +package ihl.utils; + +import ic2.api.info.Info; +import ic2.api.item.ElectricItem; +import ic2.core.block.TileEntityInventory; +import ic2.core.block.invslot.InvSlot; +import net.minecraft.init.Items; +import net.minecraft.item.ItemStack; + +public class IHLInvSlotDischarge extends InvSlot +{ + public int tier; + public boolean allowRedstoneDust; + + public IHLInvSlotDischarge(TileEntityInventory base, int oldStartIndex, InvSlot.Access access, int tier) + { + this(base, oldStartIndex, access, tier, InvSlot.InvSide.ANY); + } + + public IHLInvSlotDischarge(TileEntityInventory base, int oldStartIndex, InvSlot.Access access, int tier, InvSlot.InvSide preferredSide) + { + this(base, oldStartIndex, access, tier, true, preferredSide); + } + + public IHLInvSlotDischarge(TileEntityInventory base, int oldStartIndex, InvSlot.Access access, int tier, boolean allowRedstoneDust, InvSlot.InvSide preferredSide) + { + super(base, "discharge", oldStartIndex, access, 1, preferredSide); + this.allowRedstoneDust = true; + this.tier = tier; + this.allowRedstoneDust = allowRedstoneDust; + } + + @Override + public boolean accepts(ItemStack stack) + { + return stack == null ? false : (stack.getItem() == Items.redstone && !this.allowRedstoneDust ? false : Info.itemEnergy.getEnergyValue(stack) > 0.0D || ElectricItem.manager.discharge(stack, Double.POSITIVE_INFINITY, this.tier, true, true, true) > 0.0D); + } + + public double discharge(double amount, boolean ignoreLimit) + { + if (amount <= 0.0D) + { + throw new IllegalArgumentException("Amount must be > 0."); + } + else + { + ItemStack stack = this.get(0); + + if (stack == null) + { + return 0.0D; + } + else + { + double realAmount = ElectricItem.manager.discharge(stack, amount, this.tier, ignoreLimit, true, false); + + if (realAmount <= 0.0D) + { + realAmount = Info.itemEnergy.getEnergyValue(stack); + + if (realAmount <= 0.0D) + { + return 0.0D; + } + + --stack.stackSize; + + if (stack.stackSize <= 0) + { + this.put(0, (ItemStack)null); + } + } + + return realAmount; + } + } + } + + public void setTier(int tier1) + { + this.tier = tier1; + } +} \ No newline at end of file diff --git a/src/main/java/ihl/utils/IHLItemRenderer.java b/src/main/java/ihl/utils/IHLItemRenderer.java new file mode 100644 index 0000000..0191edb --- /dev/null +++ b/src/main/java/ihl/utils/IHLItemRenderer.java @@ -0,0 +1,297 @@ +package ihl.utils; + +import java.util.Random; + +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL12; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.block.Block; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.ItemRenderer; +import net.minecraft.client.renderer.OpenGlHelper; +import net.minecraft.client.renderer.RenderBlocks; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.entity.RenderManager; +import net.minecraft.client.renderer.texture.TextureManager; +import net.minecraft.client.renderer.texture.TextureMap; +import net.minecraft.item.ItemBlock; +import net.minecraft.item.ItemCloth; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.client.IItemRenderer; +import net.minecraftforge.client.IItemRenderer.ItemRenderType; +import net.minecraftforge.client.MinecraftForgeClient; + +@SideOnly(value = Side.CLIENT) +public class IHLItemRenderer { + private Random random = new Random(); + private RenderBlocks renderBlocks = new RenderBlocks(); + private boolean noRotation=false; + + public IHLItemRenderer(){} + + public IHLItemRenderer(boolean noRotation1) + { + noRotation=noRotation1; + } + + public void doRender(RenderManager renderManager, ItemStack stack, double x, double y, double z) + { + if(stack!=null) + { + if(stack.getItem().isFull3D()) + { + ItemRenderType type = ItemRenderType.ENTITY; + IItemRenderer itemRenderer = MinecraftForgeClient.getItemRenderer(stack, type); + if(itemRenderer!=null) + { + GL11.glPushMatrix(); + GL11.glTranslatef((float)x, (float)y-0.5F, (float)z); + GL11.glScalef(0.5F, 0.5F, 0.5F); + Object[] data={null,null}; + itemRenderer.renderItem(type, stack, data); + GL11.glPopMatrix(); + } + else + { + this.doRenderNative(renderManager, stack, x, y-0.1F, z); + } + } + else + { + this.doRenderNative(renderManager, stack, x, y-0.1F, z); + } + } + } + + public void doRenderNative(RenderManager renderManager, ItemStack var10, double par2, double par4, double par6) + { + float scale=0.8F; + if (var10.getItem() != null) + { + renderManager.renderEngine.bindTexture(renderManager.renderEngine.getResourceLocation(var10.getItemSpriteNumber())); + this.random.setSeed(187L); + GL11.glPushMatrix(); + byte var13 = 1; + + if (var10.stackSize > 1) + { + var13 = 2; + } + + if (var10.stackSize > 5) + { + var13 = 3; + } + + if (var10.stackSize > 20) + { + var13 = 4; + } + + if (var10.stackSize > 40) + { + var13 = 5; + } + + GL11.glTranslatef((float)par2, (float)par4, (float)par6); + + GL11.glEnable(GL12.GL_RESCALE_NORMAL); + float var19; + float var18; + int var24; + + if (var10.getItemSpriteNumber() == 0 && var10.getItem() instanceof ItemBlock && RenderBlocks.renderItemIn3d(Block.getBlockFromItem(var10.getItem()).getRenderType())) + { + Block var21 = Block.getBlockFromItem(var10.getItem()); + + float var25 = 0.25F*scale; + var24 = var21.getRenderType(); + + if (var24 == 1 || var24 == 19 || var24 == 12 || var24 == 2) + { + var25 = 0.5F*scale; + } + + if (var21.getRenderBlockPass() > 0) + { + GL11.glAlphaFunc(GL11.GL_GREATER, 0.1F); + GL11.glEnable(GL11.GL_BLEND); + OpenGlHelper.glBlendFunc(770, 771, 1, 0); + } + + GL11.glScalef(var25, var25, var25); + + for (int var26 = 0; var26 < var13; ++var26) + { + GL11.glPushMatrix(); + + if (var26 > 0) + { + var18 = (this.random.nextFloat() * 2.0F - 1.0F) * 0.2F / var25; + var19 = (this.random.nextFloat() * 2.0F - 1.0F) * 0.2F / var25; + float var20 = (this.random.nextFloat() * 2.0F - 1.0F) * 0.2F / var25; + GL11.glTranslatef(var18, var19, var20); + } + + this.renderBlocks.renderBlockAsItem(var21, var10.getItemDamage(), 1.0F); + GL11.glPopMatrix(); + } + + if (var21.getRenderBlockPass() > 0) + { + GL11.glDisable(GL11.GL_BLEND); + } + } + else + { + float var17; + + if (var10.getItemSpriteNumber() == 1 && var10.getItem().requiresMultipleRenderPasses()) + { + GL11.glScalef(0.5F*scale, 0.5F*scale, 0.5F*scale); + + for (int var23 = 0; var23 <= 1; ++var23) + { + this.random.setSeed(187L); + IIcon var22 = var10.getItem().getIconFromDamageForRenderPass(var10.getItemDamage(), var23); + var24 = var10.getItem().getColorFromItemStack(var10, var23); + var17 = (var24 >> 16 & 255) / 255.0F; + var18 = (var24 >> 8 & 255) / 255.0F; + var19 = (var24 & 255) / 255.0F; + GL11.glColor4f(var17, var18, var19, 1.0F); + this.renderDroppedItem(renderManager, var10, var22, var13, var17, var18, var19); + + } + } + else + { + if (var10 != null && var10.getItem() instanceof ItemCloth) + { + GL11.glAlphaFunc(GL11.GL_GREATER, 0.1F); + GL11.glEnable(GL11.GL_BLEND); + OpenGlHelper.glBlendFunc(770, 771, 1, 0); + } + GL11.glScalef(0.5F*scale, 0.5F*scale, 0.5F*scale); + IIcon var14 = var10.getIconIndex(); + int var15 = var10.getItem().getColorFromItemStack(var10, 0); + float var16 = (var15 >> 16 & 255) / 255.0F; + var17 = (var15 >> 8 & 255) / 255.0F; + var18 = (var15 & 255) / 255.0F; + this.renderDroppedItem(renderManager, var10, var14, var13, var16, var17, var18); + if (var10 != null && var10.getItem() instanceof ItemCloth) + { + GL11.glDisable(GL11.GL_BLEND); + } + } + } + + GL11.glDisable(GL12.GL_RESCALE_NORMAL); + GL11.glPopMatrix(); + } + } + + private void renderDroppedItem(RenderManager renderManager, ItemStack stack, IIcon par2Icon, int par3, float par5, float par6, float par7) + { + Tessellator var8 = Tessellator.instance; + + if (par2Icon == null) + { + TextureManager var9 = Minecraft.getMinecraft().getTextureManager(); + ResourceLocation var10 = var9.getResourceLocation(stack.getItemSpriteNumber()); + par2Icon = ((TextureMap)var9.getTexture(var10)).getAtlasSprite("missingno"); + } + + float var25 = par2Icon.getMinU(); + float var26 = par2Icon.getMaxU(); + float var11 = par2Icon.getMinV(); + float var12 = par2Icon.getMaxV(); + float var13 = 1.0F; + float var14 = 0.5F; + float var15 = 0.25F; + float var17; + + if (renderManager.options.fancyGraphics) + { + GL11.glPushMatrix(); + + //GL11.glRotatef((this.random .nextFloat() * 2.0F - 1.0F) * (180F / (float)Math.PI), 0.0F, 1.0F, 0.0F); + + float var16 = 0.0625F; + var17 = 0.021875F; + ItemStack var18 = stack; + int var19 = var18.stackSize; + byte var24; + + if (var19 < 2) + { + var24 = 1; + } + else if (var19 < 16) + { + var24 = 2; + } + else if (var19 < 32) + { + var24 = 3; + } + else + { + var24 = 4; + } + + GL11.glTranslatef(-var14, -var15, -((var16 + var17) * var24 / 2.0F)); + + for (int var20 = 0; var20 < var24; ++var20) + { + GL11.glTranslatef(0.0F, 0.0F, var16 + var17); + + if (var18.getItemSpriteNumber() == 0) + { + renderManager.renderEngine.bindTexture(TextureMap.locationBlocksTexture); + } + else + { + renderManager.renderEngine.bindTexture(TextureMap.locationItemsTexture); + } + + GL11.glColor4f(par5, par6, par7, 1.0F); + ItemRenderer.renderItemIn2D(var8, var26, var11, var25, var12, par2Icon.getIconWidth(), par2Icon.getIconHeight(), var16); + } + + GL11.glPopMatrix(); + } + else + { + for (int var27 = 0; var27 < par3; ++var27) + { + GL11.glPushMatrix(); + + if (var27 > 0) + { + var17 = (this.random.nextFloat() * 2.0F - 1.0F) * 0.3F; + float var29 = (this.random.nextFloat() * 2.0F - 1.0F) * 0.3F; + float var28 = (this.random.nextFloat() * 2.0F - 1.0F) * 0.3F; + GL11.glTranslatef(var17, var29, var28); + } + if(!noRotation) + { + GL11.glRotatef(180.0F - renderManager.playerViewY, 0.0F, 1.0F, 0.0F); + } + GL11.glColor4f(par5, par6, par7, 1.0F); + var8.startDrawingQuads(); + var8.setNormal(0.0F, 1.0F, 0.0F); + var8.addVertexWithUV(0.0F - var14, 0.0F - var15, 0.0D, var25, var12); + var8.addVertexWithUV(var13 - var14, 0.0F - var15, 0.0D, var26, var12); + var8.addVertexWithUV(var13 - var14, 1.0F - var15, 0.0D, var26, var11); + var8.addVertexWithUV(0.0F - var14, 1.0F - var15, 0.0D, var25, var11); + var8.draw(); + GL11.glPopMatrix(); + } + } + } + +} diff --git a/src/main/java/ihl/utils/IHLMathUtils.java b/src/main/java/ihl/utils/IHLMathUtils.java new file mode 100644 index 0000000..8cab3c9 --- /dev/null +++ b/src/main/java/ihl/utils/IHLMathUtils.java @@ -0,0 +1,103 @@ +package ihl.utils; + +public class IHLMathUtils { + private final static int accuracy_level = 1024; + private final static float[] sqrt_table = new float[accuracy_level]; + + public static float sqrt(float value) { + float value1 = value; + int multiplier = 1; + while (value1 >= 1.0f) { + multiplier=multiplier<<2; + value1 = value / (multiplier * multiplier); + } + return multiplier * sqrt_table[(int) (value1 * accuracy_level)]; + } + + public static float[] vector_vector_multiply(float[] v1, float[] v2) { + float c_x = v1[1] * v2[2] - v2[1] * v1[2]; + float c_y = v2[0] * v1[2] - v1[0] * v2[2]; + float c_z = v1[0] * v2[1] - v2[0] * v1[1]; + return new float[] { c_x, c_y, c_z }; + } + + public static void normalize_vector(float[] v1) { + float d = (float) Math.sqrt(v1[0] * v1[0] + v1[1] * v1[1] + v1[2] * v1[2]); + if (d == 0) { // Nothing can we do. Create new vector towards up + // direction. + v1[0] = 0; + v1[1] = 1; + v1[2] = 0; + } else { + v1[0] /= d; + v1[1] /= d; + v1[2] /= d; + } + } + + public static void scale_vector_to_value(float[] v1, float v2) { + float d = (float) Math.sqrt(v1[0] * v1[0] + v1[1] * v1[1] + v1[2] * v1[2]); + if (d == 0) { // Nothing can we do. Create new vector towards up + // direction. + v1[0] = 0; + v1[1] = v2; + v1[2] = 0; + } else { + v1[0] = v1[0] * v2 / d; + v1[1] = v1[1] * v2 / d; + v1[2] = v1[2] * v2 / d; + } + } + + public static void vector_add(float[] fs, float x, float y, float z) { + fs[0] += x; + fs[1] += y; + fs[2] += z; + } + + static { + for (int i = 0; i < accuracy_level; i++) { + sqrt_table[i] = (float) Math.sqrt((double) i / accuracy_level); + } + } + + public static float[] vector_return_difference(double[] v1, double[] v2) { + return new float[] { (float) (v1[0] - v2[0]), (float) (v1[1] - v2[1]), (float) (v1[2] - v2[2]) }; + } + + public static float[] vector_return_difference(float[] v1, double[] v2) { + return new float[] { (float) (v1[0] - v2[0]), (float) (v1[1] - v2[1]), (float) (v1[2] - v2[2]) }; + } + + public static float[] vector_return_difference(int[] v1, double[] v2) { + return new float[] { (float) (v1[0] - v2[0]), (float) (v1[1] - v2[1]), (float) (v1[2] - v2[2]) }; + } + + public static void multiply_vector_to_value(float[] v1, float v2) { + v1[0] *= v2; + v1[1] *= v2; + v1[2] *= v2; + } + + public static void vector_add(double[] v1, float[] v2) { + v1[0] += v2[0]; + v1[1] += v2[1]; + v1[2] += v2[2]; + } + + public static float[] get_triangle_normal(double[][] triangle1) { + float[] v1 = vector_return_difference(triangle1[1], triangle1[0]); + float[] v2 = vector_return_difference(triangle1[2], triangle1[0]); + return vector_vector_multiply(v1, v2); + } + + public static int sign(int value) { + if (value > 0) + return 1; + else if (value < 0) + return -1; + else + return 0; + } + +} diff --git a/src/main/java/ihl/utils/IHLRenderUtils.java b/src/main/java/ihl/utils/IHLRenderUtils.java new file mode 100644 index 0000000..d0d13f4 --- /dev/null +++ b/src/main/java/ihl/utils/IHLRenderUtils.java @@ -0,0 +1,819 @@ +package ihl.utils; + +import java.nio.FloatBuffer; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.lwjgl.opengl.GL11; + +import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import ic2.core.util.DrawUtil; +import ihl.IHLMod; +import net.minecraft.block.Block; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.ScaledResolution; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.client.multiplayer.WorldClient; +import net.minecraft.client.renderer.GLAllocation; +import net.minecraft.client.renderer.RenderBlocks; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.texture.TextureMap; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.IIcon; +import net.minecraft.util.MovingObjectPosition; +import net.minecraft.util.StatCollector; +import net.minecraftforge.client.event.DrawBlockHighlightEvent; +import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidStack; + +@SideOnly(value = Side.CLIENT) +public class IHLRenderUtils +{ + private FloatBuffer colorBuffer; + private Map frameTooltipMap; + private int displayScaledWidth=-1; + private int displayScaledHeight=-1; + private int guiXPos=-1; + private int guiYPos=-1; + private int prevDisplayWidth=-1; + private int prevDisplayHeight=-1; + private final int guiContainerWidth = 166; + private final int guiContainerHeight = 176; + private float lastPlayerYaw; + private float lastPlayerPitch; + public double renderMinX=0d; + public double renderMaxX=1d; + public double renderMinY=0d; + public double renderMaxY=1d; + public double renderMinZ=0d; + public double renderMaxZ=1d; + public boolean renderFromInside=false; + private float rotationPointX; + private float rotationPointY; + private float rotationPointZ; + private double renderPositionX; + private double renderPositionY; + private double renderPositionZ; + private float rotationX; + private float rotationY; + private float rotationZ; + private float scale=1/16f; + public boolean swapXandZ=false; + public boolean swapXandY=false; + public boolean swapYandZ=false; + public boolean swapRenderBoundsX=false; + public boolean swapRenderBoundsY=false; + public boolean swapRenderBoundsZ=false; + public int scaleFactor=1; + public static IHLRenderUtils instance; + + public IHLRenderUtils() + { + instance=this; + colorBuffer = GLAllocation.createDirectFloatBuffer(16); + frameTooltipMap = new HashMap(); + } + + public void renderIHLFluidTank(IHLFluidTank fluidTank, int x1, int y1, int x2, int y2, float zLevel, int par1, int par2, int xOffset, int yOffset) + { + int liquidHeight = 0; + int prevLiquidHeight = 0; + int i = y2-y1; + Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.locationBlocksTexture); + GL11.glEnable(GL11.GL_BLEND); + GL11.glColor4f(1f, 1f, 1f, 1f); + for(int i2 = 0;i2 fli = fluidTank.getFluidList(); + for(int i=fli.size()-1;i>=0;i--) + { + FluidStack fluidStack = fli.get(i); + fluidListNames+=StatCollector.translateToLocal(fluidStack.getUnlocalizedName())+": "+fluidStack.amount+"mB /n "; + } + drawTooltip(par1,par2,x2-x1,y2-y1,x1,y1,fluidListNames); + } + + public boolean drawTooltip(int cursorPosX, int cursorPosY, int width, int height, int xPos, int yPos, String text) + { + updateScreenSize(); + long key = xPos+yPos*1024; + Integer frame=0; + if(frameTooltipMap.containsKey(key)) + { + frame=frameTooltipMap.get(key); + } + boolean showString=true; + if(cursorPosXxPos+width|| + cursorPosYyPos+height) + { + if(frame>0) + { + frame-=20; + frameTooltipMap.put(key, frame); + } + showString=false; + } + else + { + frame+=10; + frameTooltipMap.put(key, frame); + } + if(frame>0) + { + int strokeHeight=15; + int i,x1,x2,y1,y2,tooltipWidth,tooltipHeight; + tooltipWidth=tooltipHeight=0; + String[] splittedText = text.split(" /n "); + for(i=0;itooltipWidth) + { + tooltipWidth=Math.min(frame,Minecraft.getMinecraft().fontRenderer.getStringWidth(splittedText[i])+8); + } + } + tooltipHeight=Math.min(Math.max(frame-tooltipWidth,strokeHeight),strokeHeight*splittedText.length); + x1=cursorPosX-xPos; + x2=x1+tooltipWidth; + y1=cursorPosY-guiYPos+18; + y2=y1+tooltipHeight; + GL11.glPushAttrib(16704); + GL11.glDisable(GL11.GL_DEPTH_TEST); + GL11.glDisable(GL11.GL_TEXTURE_2D); + GL11.glEnable(GL11.GL_BLEND); + GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + if(showString) + { + drawRectangle(Tessellator.instance, x1,y1,x2,y2,128); + GL11.glEnable(GL11.GL_TEXTURE_2D); + for(i=0;i>> 24 & 255, color >>> 16 & 255, color >>> 8 & 255, color & 255); + tessellator.addVertex(x2, y1, 300.0D); + tessellator.addVertex(x1, y1, 300.0D); + tessellator.addVertex(x1, y2, 300.0D); + tessellator.addVertex(x2, y2, 300.0D); + tessellator.draw(); + } + + public void drawThermometerTemperature(long temperature, boolean show) + { + updateScreenSize(); + long key = 0; + int frame=0; + if(frameTooltipMap.containsKey(key)) + { + frame=frameTooltipMap.get(key); + } + if(frame<=0) + { + updatePlayerView(); + } + boolean showString=true; + if(show && frame<=122) + { + frame+=1; + frameTooltipMap.put(key, frame); + } + else + { + if(frame>0) + { + frame-=2; + frameTooltipMap.put(key, frame); + } + showString=false; + } + if(frame>0) + { + int width=Math.min(frame, 122); + int height=Math.min(frame, 48); + int xShift = Math.round(displayScaledWidth/100*(lastPlayerYaw - Minecraft.getMinecraft().renderViewEntity.prevRotationYaw)); + int yShift = Math.round(displayScaledHeight/64*(lastPlayerPitch - Minecraft.getMinecraft().renderViewEntity.prevRotationPitch)); + int xPos = displayScaledWidth/2+xShift; + int yPos = displayScaledHeight/2-48+yShift; + GL11.glEnable(GL11.GL_BLEND); + GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + drawTexturedModalRect(xPos,yPos,0,0,width,height); + GL11.glDisable(GL11.GL_DEPTH_TEST); + if(showString) + { + Minecraft.getMinecraft().fontRenderer.drawStringWithShadow(temperature+"\u00B0K", xPos+35, yPos+3, 16768125); + } + GL11.glEnable(GL11.GL_DEPTH_TEST); + GL11.glDisable(GL11.GL_BLEND); + } + } + + public void drawTexturedModalRect(int x1, int y1, int u, int v, int x2, int y2) { + float f = 0.00390625F; + float f1 = 0.00390625F; + Tessellator tessellator = Tessellator.instance; + tessellator.startDrawingQuads(); + tessellator.setColorRGBA_F(1f, 1f, 1f, 0.5f); + tessellator.addVertexWithUV(x1 + 0, y1 + y2, 300D, (u + 0) * f, (v + y2) * f1); + tessellator.addVertexWithUV(x1 + x2, y1 + y2, 300D, (u + x2) * f, (v + y2) * f1); + tessellator.addVertexWithUV(x1 + x2, y1 + 0, 300D, (u + x2) * f, (v + 0) * f1); + tessellator.addVertexWithUV(x1 + 0, y1 + 0, 300D, (u + 0) * f, (v + 0) * f1); + tessellator.draw(); + } + + + public void updateScreenSize() + { + if(prevDisplayHeight!=Minecraft.getMinecraft().displayHeight || prevDisplayWidth!=Minecraft.getMinecraft().displayWidth) + { + ScaledResolution var2 = new ScaledResolution(Minecraft.getMinecraft(), Minecraft.getMinecraft().displayWidth, Minecraft.getMinecraft().displayHeight); + displayScaledWidth = var2.getScaledWidth(); + displayScaledHeight = var2.getScaledHeight(); + scaleFactor=var2.getScaleFactor(); + guiXPos = (displayScaledWidth - guiContainerWidth)/2; + guiYPos = (displayScaledHeight - guiContainerHeight)/2; + prevDisplayWidth=Minecraft.getMinecraft().displayWidth; + prevDisplayHeight=Minecraft.getMinecraft().displayHeight; + } + } + + public void updatePlayerView() + { + lastPlayerYaw = Minecraft.getMinecraft().renderViewEntity.prevRotationYaw; + lastPlayerPitch = Minecraft.getMinecraft().renderViewEntity.prevRotationPitch; + } + + public void drawKnee(double xPos, double yPos, double zPos, ForgeDirection direction12, ForgeDirection direction22, double radius1, double radius2, IIcon icon) + { + ForgeDirection direction1=direction12; + ForgeDirection direction2=direction22; + if(this.swapRenderBoundsX) + { + if(direction1.offsetX!=0) + { + direction1=direction1.getOpposite(); + } + if(direction2.offsetX!=0) + { + direction2=direction2.getOpposite(); + } + } + if(this.swapRenderBoundsY) + { + if(direction1.offsetY!=0) + { + direction1=direction1.getOpposite(); + } + if(direction2.offsetY!=0) + { + direction2=direction2.getOpposite(); + } + } + if(this.swapRenderBoundsZ) + { + if(direction1.offsetZ!=0) + { + direction1=direction1.getOpposite(); + } + if(direction2.offsetZ!=0) + { + direction2=direction2.getOpposite(); + } + } + double[][] outervertexes1 = new double[8][3]; + double[][] innervertexes1 = new double[8][3]; + double[][] outervertexes2 = new double[8][3]; + double[][] innervertexes2 = new double[8][3]; + int i=0; + for(i=0;i<8;i++) + { + if(direction1.equals(direction2)) + { + switch(direction1) + { + case UP: + outervertexes1[i] = new double[] {0.5F+0.5F*(float)Math.cos(2D*Math.PI/8D*i), 0d, 0.5F+0.5F*(float)Math.sin(2D*Math.PI/8D*i)}; + innervertexes1[i] = new double[] {0.5F+radius1*0.5F*(float)Math.cos(2D*Math.PI/8D*i), 0d, 0.5F+0.5F*radius1*(float)Math.sin(2D*Math.PI/8D*i)}; + outervertexes2[i] = new double[] {0.5F+0.5F*radius2*(float)Math.cos(2D*Math.PI/8D*i), 1d, 0.5F+0.5F*radius2*(float)Math.sin(2D*Math.PI/8D*i)}; + innervertexes2[i] = new double[] {0.5F+radius1*radius2*0.5F*(float)Math.cos(2D*Math.PI/8D*i), 1d, 0.5F+0.5F*radius2*radius1*(float)Math.sin(2D*Math.PI/8D*i)}; + break; + case DOWN: + outervertexes1[i] = new double[] {0.5F+0.5F*radius2*(float)Math.cos(2D*Math.PI/8D*i), 0d, 0.5F+0.5F*radius2*(float)Math.sin(2D*Math.PI/8D*i)}; + innervertexes1[i] = new double[] {0.5F+radius1*radius2*0.5F*(float)Math.cos(2D*Math.PI/8D*i), 0d, 0.5F+0.5F*radius1*radius2*(float)Math.sin(2D*Math.PI/8D*i)}; + outervertexes2[i] = new double[] {0.5F+0.5F*(float)Math.cos(2D*Math.PI/8D*i), 1d, 0.5F+0.5F*(float)Math.sin(2D*Math.PI/8D*i)}; + innervertexes2[i] = new double[] {0.5F+radius1*0.5F*(float)Math.cos(2D*Math.PI/8D*i), 1d, 0.5F+0.5F*radius1*(float)Math.sin(2D*Math.PI/8D*i)}; + break; + case SOUTH: + outervertexes1[i] = new double[] {0.5F+0.5F*(float)Math.cos(2D*Math.PI/8D*i), 0.5F+0.5F*(float)Math.sin(2D*Math.PI/8D*i), 1d}; + innervertexes1[i] = new double[] {0.5F+radius1*0.5F*(float)Math.cos(2D*Math.PI/8D*i), 0.5F+0.5F*radius1*(float)Math.sin(2D*Math.PI/8D*i), 1d}; + outervertexes2[i] = new double[] {0.5F+0.5F*radius2*(float)Math.cos(2D*Math.PI/8D*i), 0.5F+0.5F*radius2*(float)Math.sin(2D*Math.PI/8D*i), 0d}; + innervertexes2[i] = new double[] {0.5F+radius1*radius2*0.5F*(float)Math.cos(2D*Math.PI/8D*i), 0.5F+0.5F*radius1*radius2*(float)Math.sin(2D*Math.PI/8D*i), 0d}; + break; + case NORTH: + outervertexes1[i] = new double[] {0.5F+0.5F*radius2*(float)Math.cos(2D*Math.PI/8D*i), 0.5F+0.5F*radius2*(float)Math.sin(2D*Math.PI/8D*i), 1d}; + innervertexes1[i] = new double[] {0.5F+radius1*radius2*0.5F*(float)Math.cos(2D*Math.PI/8D*i), 0.5F+0.5F*radius1*radius2*(float)Math.sin(2D*Math.PI/8D*i), 1d}; + outervertexes2[i] = new double[] {0.5F+0.5F*(float)Math.cos(2D*Math.PI/8D*i), 0.5F+0.5F*(float)Math.sin(2D*Math.PI/8D*i), 0d}; + innervertexes2[i] = new double[] {0.5F+radius1*0.5F*(float)Math.cos(2D*Math.PI/8D*i), 0.5F+0.5F*radius1*(float)Math.sin(2D*Math.PI/8D*i), 0d}; + break; + case EAST: + outervertexes1[i] = new double[] {0d, 0.5F+0.5F*(float)Math.sin(2D*Math.PI/8D*i), 0.5F+0.5F*(float)Math.cos(2D*Math.PI/8D*i)}; + innervertexes1[i] = new double[] {0d, 0.5F+0.5F*radius1*(float)Math.sin(2D*Math.PI/8D*i), 0.5F+radius1*0.5F*(float)Math.cos(2D*Math.PI/8D*i)}; + outervertexes2[i] = new double[] {1d, 0.5F+0.5F*radius2*(float)Math.sin(2D*Math.PI/8D*i), 0.5F+0.5F*radius2*(float)Math.cos(2D*Math.PI/8D*i)}; + innervertexes2[i] = new double[] {1d, 0.5F+0.5F*radius1*radius2*(float)Math.sin(2D*Math.PI/8D*i), 0.5F+radius1*radius2*0.5F*(float)Math.cos(2D*Math.PI/8D*i)}; + break; + case WEST: + outervertexes1[i] = new double[] {0d, 0.5F+0.5F*radius2*(float)Math.sin(2D*Math.PI/8D*i), 0.5F+0.5F*radius2*(float)Math.cos(2D*Math.PI/8D*i)}; + innervertexes1[i] = new double[] {0d, 0.5F+0.5F*radius2*radius1*(float)Math.sin(2D*Math.PI/8D*i), 0.5F+radius1*0.5F*radius2*(float)Math.cos(2D*Math.PI/8D*i)}; + outervertexes2[i] = new double[] {1d, 0.5F+0.5F*(float)Math.sin(2D*Math.PI/8D*i), 0.5F+0.5F*(float)Math.cos(2D*Math.PI/8D*i)}; + innervertexes2[i] = new double[] {1d, 0.5F+0.5F*radius1*(float)Math.sin(2D*Math.PI/8D*i), 0.5F+radius1*0.5F*(float)Math.cos(2D*Math.PI/8D*i)}; + break; + default: + outervertexes1[i] = new double[] {0.5F+0.5F*(float)Math.cos(2D*Math.PI/8D*i), 0d, 0.5F+0.5F*(float)Math.sin(2D*Math.PI/8D*i)}; + innervertexes1[i] = new double[] {0.5F+radius1*0.5F*(float)Math.cos(2D*Math.PI/8D*i), 0d, 0.5F+0.5F*radius1*(float)Math.sin(2D*Math.PI/8D*i)}; + outervertexes2[i] = new double[] {0.5F+0.5F*radius2*(float)Math.cos(2D*Math.PI/8D*i), 1d, 0.5F+0.5F*radius2*(float)Math.sin(2D*Math.PI/8D*i)}; + innervertexes2[i] = new double[] {0.5F+radius1*radius2*0.5F*(float)Math.cos(2D*Math.PI/8D*i), 1d, 0.5F+0.5F*radius2*radius1*(float)Math.sin(2D*Math.PI/8D*i)}; + break; + } + + } + else + { + switch(direction1) + { + case UP: + outervertexes1[i] = new double[] {0.5F+0.25F*radius2*(float)Math.cos(2D*Math.PI/8D*i+Math.PI), 1d, 0.5F-0.25F*radius2*(float)Math.sin(2D*Math.PI/8D*i+Math.PI)}; + innervertexes1[i] = new double[] {0.5F+radius1*radius2*0.25F*(float)Math.cos(2D*Math.PI/8D*i+Math.PI), 1d, 0.5F-0.25F*radius1*radius2*(float)Math.sin(2D*Math.PI/8D*i+Math.PI)}; + break; + case DOWN: + outervertexes1[i] = new double[] {0.5F+0.25F*(float)Math.cos(2D*Math.PI/8D*i), 0d, 0.5F+0.25F*(float)Math.sin(2D*Math.PI/8D*i)}; + innervertexes1[i] = new double[] {0.5F+radius1*0.25F*(float)Math.cos(2D*Math.PI/8D*i), 0d, 0.5F+0.25F*radius1*(float)Math.sin(2D*Math.PI/8D*i)}; + break; + case SOUTH: + outervertexes1[i] = new double[] {0.5F+0.25F*(float)Math.cos(2D*Math.PI/8D*i), 0.5F+0.25F*(float)Math.sin(2D*Math.PI/8D*i), 1d}; + innervertexes1[i] = new double[] {0.5F+radius1*0.25F*(float)Math.cos(2D*Math.PI/8D*i), 0.5F+0.25F*radius1*(float)Math.sin(2D*Math.PI/8D*i), 1d}; + break; + case NORTH: + outervertexes1[i] = new double[] {0.5F+0.25F*radius2*(float)Math.cos(2D*Math.PI/8D*i), 0.5F+0.25F*radius2*(float)Math.sin(2D*Math.PI/8D*i), 1d}; + innervertexes1[i] = new double[] {0.5F+radius1*radius2*0.25F*(float)Math.cos(2D*Math.PI/8D*i), 0.5F+0.25F*radius1*radius2*(float)Math.sin(2D*Math.PI/8D*i), 1d}; + break; + case EAST: + outervertexes1[i] = new double[] {0d, 0.5F+0.25F*(float)Math.sin(2D*Math.PI/8D*i), 0.5F+0.25F*(float)Math.cos(2D*Math.PI/8D*i)}; + innervertexes1[i] = new double[] {0d, 0.5F+0.25F*radius1*(float)Math.sin(2D*Math.PI/8D*i), 0.5F+radius1*0.25F*(float)Math.cos(2D*Math.PI/8D*i)}; + break; + case WEST: + outervertexes1[i] = new double[] {0d, 0.5F+0.25F*radius2*(float)Math.sin(2D*Math.PI/8D*i), 0.5F+0.52F*radius2*(float)Math.cos(2D*Math.PI/8D*i)}; + innervertexes1[i] = new double[] {0d, 0.5F+0.25F*radius2*radius1*(float)Math.sin(2D*Math.PI/8D*i), 0.5F+radius1*0.25F*radius2*(float)Math.cos(2D*Math.PI/8D*i)}; + break; + default: + outervertexes1[i] = new double[] {0d, 0.5F+0.25F*radius2*(float)Math.sin(2D*Math.PI/8D*i), 0.5F+0.52F*radius2*(float)Math.cos(2D*Math.PI/8D*i)}; + innervertexes1[i] = new double[] {0d, 0.5F+0.25F*radius2*radius1*(float)Math.sin(2D*Math.PI/8D*i), 0.5F+radius1*0.25F*radius2*(float)Math.cos(2D*Math.PI/8D*i)}; + break; + } + + switch(direction2) + { + case UP: + outervertexes2[i] = new double[] {0.5F+0.5F*radius2*(float)Math.cos(2D*Math.PI/8D*i), 1d, 0.5F+0.5F*radius2*(float)Math.sin(2D*Math.PI/8D*i)}; + innervertexes2[i] = new double[] {0.5F+radius1*radius2*0.5F*(float)Math.cos(2D*Math.PI/8D*i), 1d, 0.5F+0.5F*radius2*radius1*(float)Math.sin(2D*Math.PI/8D*i)}; + break; + case DOWN: + outervertexes2[i] = new double[] {0.5F+0.5F*(float)Math.cos(2D*Math.PI/8D*i), 1d, 0.5F+0.5F*(float)Math.sin(2D*Math.PI/8D*i)}; + innervertexes2[i] = new double[] {0.5F+radius1*0.5F*(float)Math.cos(2D*Math.PI/8D*i), 1d, 0.5F+0.5F*radius1*(float)Math.sin(2D*Math.PI/8D*i)}; + break; + case WEST: + outervertexes2[i] = new double[] {1d, 0.5F+0.25F*(float)Math.cos(2D*Math.PI/8D*i), 0.5F-0.25F*(float)Math.sin(2D*Math.PI/8D*i)}; + innervertexes2[i] = new double[] {1d, 0.5F+radius1*0.25F*(float)Math.cos(2D*Math.PI/8D*i), 0.5F-0.25F*radius1*(float)Math.sin(2D*Math.PI/8D*i)}; + break; + case EAST: + outervertexes2[i] = new double[] {0d, 0.5F+0.25F*(float)Math.cos(2D*Math.PI/8D*i), 0.5F+0.25F*(float)Math.sin(2D*Math.PI/8D*i)}; + innervertexes2[i] = new double[] {0d, 0.5F+radius1*0.25F*(float)Math.cos(2D*Math.PI/8D*i), 0.5F+0.25F*radius1*(float)Math.sin(2D*Math.PI/8D*i)}; + break; + case NORTH: + outervertexes2[i] = new double[] {0.5F+0.25F*(float)Math.cos(2D*Math.PI/8D*i), 1d-0.5F-0.25F*(float)Math.sin(2D*Math.PI/8D*i), 1d}; + innervertexes2[i] = new double[] {0.5F+radius1*0.25F*(float)Math.cos(2D*Math.PI/8D*i), 1d-0.5F-0.25F*radius1*(float)Math.sin(2D*Math.PI/8D*i), 1d}; + break; + case SOUTH: + outervertexes2[i] = new double[] {0.5F+0.25F*(float)Math.cos(2D*Math.PI/8D*i), 0.5F+0.25F*(float)Math.sin(2D*Math.PI/8D*i), 0d}; + innervertexes2[i] = new double[] {0.5F+radius1*0.25F*(float)Math.cos(2D*Math.PI/8D*i), 0.5F+0.25F*radius1*(float)Math.sin(2D*Math.PI/8D*i), 0d}; + break; + default: + outervertexes2[i] = new double[] {0.5F+0.5F*radius2*(float)Math.cos(2D*Math.PI/8D*i), 1d, 0.5F+0.5F*radius2*(float)Math.sin(2D*Math.PI/8D*i)}; + innervertexes2[i] = new double[] {0.5F+radius1*radius2*0.5F*(float)Math.cos(2D*Math.PI/8D*i), 1d, 0.5F+0.5F*radius2*radius1*(float)Math.sin(2D*Math.PI/8D*i)}; + break; + } + + } + } + double[][][] quadList = new double[32][4][3]; + for(i=0;i<32;i++) + { + if(i<7) + { + quadList[i]=new double[][] {outervertexes1[i],outervertexes1[i+1],innervertexes1[i+1],innervertexes1[i]}; + } + else if(i==7) + { + quadList[i]=new double[][] {outervertexes1[i],outervertexes1[0],innervertexes1[0],innervertexes1[i]}; + } + else if(i<15) + { + quadList[i]=new double[][] {innervertexes2[i-8],innervertexes2[i+1-8],outervertexes2[i+1-8],outervertexes2[i-8]}; + } + else if(i==15) + { + quadList[i]=new double[][] {innervertexes2[i-8],innervertexes2[0],outervertexes2[0],outervertexes2[i-8]}; + } + else if(i<23) + { + quadList[i]=new double[][] {outervertexes1[i-16],outervertexes2[i-16],outervertexes2[i-16+1],outervertexes1[i-16+1]}; + } + else if(i==23) + { + quadList[i]=new double[][] {outervertexes1[i-16],outervertexes2[i-16],outervertexes2[0],outervertexes1[0]}; + } + else if(i<31) + { + quadList[i]=new double[][] {innervertexes1[i-24+1],innervertexes2[i-24+1], innervertexes2[i-24], innervertexes1[i-24]}; + } + else if(i==31) + { + quadList[i]=new double[][] {innervertexes1[0],innervertexes2[0],innervertexes2[i-24],innervertexes1[i-24]}; + } + } + for(i=0;i<32;i++) + { + this.drawSquare(xPos, yPos, zPos, quadList[i], icon); + } + + + } + public void drawPipe(double xPos, double yPos, double zPos, ForgeDirection direction1, double radius1, double radius2, IIcon icon) + { + this.drawKnee(xPos, yPos, zPos, direction1, direction1, radius1, radius2, icon); + } + + public void drawSquare(double xPos, double yPos, double zPos, double[][] vertexes, IIcon icon) + { + double u1 = icon.getInterpolatedU(this.renderMinZ * 16.0D); + double u2 = icon.getInterpolatedU(this.renderMaxZ * 16.0D); + double v2 = icon.getInterpolatedV(16.0D - this.renderMaxY * 16.0D); + double v1 = icon.getInterpolatedV(16.0D - this.renderMinY * 16.0D); + if (this.renderMinZ < 0.0D || this.renderMaxZ > 1.0D) + { + u1 = icon.getMinU(); + u2 = icon.getMaxU(); + } + if (this.renderMinY < 0.0D || this.renderMaxY > 1.0D) + { + v2 = icon.getMinV(); + v1 = icon.getMaxV(); + } + this.drawSquare(xPos, yPos, zPos, u1, u2, v1, v2, vertexes); + } + + + public void drawSquare(double xPos, double yPos, double zPos, double u1, double u2, double v1, double v2, double[][] vertexes) + { + Tessellator var9 = Tessellator.instance; + double[] us = new double[]{u1,u1,u2,u2}; + double[] vs = new double[]{v1,v2,v2,v1}; + double xDelta=this.renderMaxX-this.renderMinX; + double yDelta=this.renderMaxY-this.renderMinY; + double zDelta=this.renderMaxZ-this.renderMinZ; + int startFrom=0; + int endTo=vertexes.length-1; + if(this.renderFromInside) + { + startFrom=vertexes.length-1; + endTo=0; + } + for(int i=startFrom;(i<=endTo&&!this.renderFromInside)||(i>=endTo&&this.renderFromInside);i+=(endTo-startFrom)/3) + { + double vX=vertexes[i][0]*xDelta+this.renderMinX; + double vY=vertexes[i][1]*yDelta+this.renderMinY; + double vZ=vertexes[i][2]*zDelta+this.renderMinZ; + double[] vYZ=null; + double[] vXZ=null; + double[] vXY=null; + if(this.rotationX!=0) + { + vYZ = this.rotateCoordinateByAngle(vY-(this.rotationPointY-8f)*scale, vZ-(this.rotationPointZ+8f)*scale, this.rotationX); + vY=vYZ[0]+(this.rotationPointY-8f)*scale; + vZ=vYZ[1]+(this.rotationPointZ+8f)*scale; + } + if(this.rotationY!=0) + { + vXZ = this.rotateCoordinateByAngle(vX-(this.rotationPointX+8f)*scale, vZ-(this.rotationPointZ+8f)*scale, this.rotationY); + vX=vXZ[0]+(this.rotationPointX+8f)*scale; + vZ=vXZ[1]-(this.rotationPointZ+8f)*scale; + } + if(this.rotationZ!=0) + { + vXY = this.rotateCoordinateByAngle(vX-(this.rotationPointX+8f)*scale, vY-(this.rotationPointY-8f)*scale, this.rotationZ); + vX=vXY[0]+(this.rotationPointX+8f)*scale; + vY=vXY[1]+(this.rotationPointY-8f)*scale; + if(swappingAxisOrBoundsAffectRotationOnAxisZ()) + { + vY-=(this.renderMaxZ-(this.rotationPointZ+8f))*scale*Math.sin(this.rotationZ); + } + } + if(this.swapXandY) + { + double var0 = vX; + vX=vY; + vY=var0; + } + if(this.swapXandZ) + { + double var0 = vX; + vX=vZ; + vZ=var0; + } + if(this.swapYandZ) + { + double var0 = vY; + vY=vZ; + vZ=var0; + } + var9.addVertexWithUV(xPos+vX, yPos+vY, zPos+vZ, us[i], vs[i]); + } + } + + + public void setRenderBounds(double minX, double minY, double minZ, double maxX, double maxY, double maxZ) + { + if(this.swapRenderBoundsX) + { + this.renderMinX = 1-maxX; + this.renderMaxX = 1-minX; + } + else + { + this.renderMinX = minX; + this.renderMaxX = maxX; + } + if(this.swapRenderBoundsY) + { + this.renderMinY = 1-maxY; + this.renderMaxY = 1-minY; + } + else + { + this.renderMinY = minY; + this.renderMaxY = maxY; + } + if(this.swapRenderBoundsZ) + { + this.renderMinZ = 1-maxZ; + this.renderMaxZ = 1-minZ; + } + else + { + this.renderMinZ = minZ; + this.renderMaxZ = maxZ; + } + } + + public void setRotationPoint(float rX, float rY, float rZ) + { + this.rotationPointX=rX; + this.rotationPointY=rY; + this.rotationPointZ=rZ; + } + + public void setPosition(double xPos, double yPos, double zPos) + { + this.renderPositionX=xPos; + this.renderPositionY=yPos; + this.renderPositionZ=zPos; + } + + public void drawPipe(float fx,float fy,float fz, int xSize,int ySize,int zSize, float radius1, float radius2, ForgeDirection direction, IIcon icon) + { + this.setRenderBoundsFromModel(fx, fy, fz, xSize, ySize, zSize); + this.drawPipe(renderPositionX,renderPositionY, renderPositionZ, direction, radius1, radius2, icon); + } + + public void drawKnee(float fx,float fy,float fz, int xSize,int ySize,int zSize, float radius1, float radius2, ForgeDirection direction1, ForgeDirection direction2, IIcon icon) + { + this.setRenderBoundsFromModel(fx, fy, fz, xSize, ySize, zSize); + this.drawKnee(renderPositionX,renderPositionY, renderPositionZ, direction1, direction2, radius1, radius2, icon); + } + + public void drawBox(float fx,float fy,float fz, int xSize,int ySize,int zSize, Block block, int meta, RenderBlocks blockRenderer) + { + this.setRenderBoundsFromModel(fx, fy, fz, xSize, ySize, zSize); + blockRenderer.renderStandardBlock(block, (int)this.renderPositionX, (int)this.renderPositionY, (int)this.renderPositionZ); + } + + public void setRenderBoundsFromModel(float fx,float fy,float fz, int xSize,int ySize,int zSize) + { + float boundMinX=(-this.rotationPointX+8f-fx-xSize)*scale; + float boundMaxX=(-this.rotationPointX+8f-fx)*scale; + float boundMinZ=(-this.rotationPointZ+8f-fz-zSize)*scale; + float boundMaxZ=(-this.rotationPointZ+8f-fz)*scale; + float boundMinY=(this.rotationPointY-8f-fy-ySize)*scale; + float boundMaxY=(this.rotationPointY-8f-fy)*scale; + this.setRenderBounds(boundMinX, boundMinY, boundMinZ, boundMaxX, boundMaxY, boundMaxZ); + } + + public double[] rotateCoordinateByAngle(double coord1, double coord2, double angle) + { + double r = Math.sqrt(coord2*coord2+coord1*coord1); + double alpha0=Math.asin(coord2/r); + if(coord1<0d) + { + alpha0=Math.PI-Math.asin(coord2/r); + } + double alpha2=alpha0+angle; + double coord21=Math.sin(alpha2)*r; + double coord11=Math.cos(alpha2)*r; + return new double[]{coord11,coord21}; + } + + public void setRotation(float rotationX1, float rotationY1, float rotationZ1) + { + if(this.swapRenderBoundsX) + { + this.rotationX=-rotationX1; + } + else + { + this.rotationX=rotationX1; + } + if(this.swapRenderBoundsY) + { + this.rotationY=-rotationY1; + } + else + { + this.rotationY=rotationY1; + } + if(swappingAxisOrBoundsAffectRotationOnAxisZ()) + { + this.rotationZ=-rotationZ1; + } + else + { + this.rotationZ=rotationZ1; + } + } + + public void reset() + { + this.renderFromInside=false; + this.swapXandZ=false; + this.swapXandY=false; + this.swapYandZ=false; + this.swapRenderBoundsX=false; + this.swapRenderBoundsY=false; + this.swapRenderBoundsZ=false; + this.setRotation(0f, 0f, 0f); + this.setRotationPoint(0f, 0f, 0f); + } + + private boolean swappingAxisOrBoundsAffectRotationOnAxisZ() + { + return (this.swapRenderBoundsZ && !this.swapXandZ && !this.swapYandZ)|| + (this.swapRenderBoundsX && this.swapXandZ) || + (this.swapRenderBoundsY && this.swapYandZ); + } + + public List splitStringByWidth(String string, int stringWidth) + { + List output = new ArrayList(); + StringBuffer sb = new StringBuffer(); + String[] splittedBySpaces = string.split(" "); + for(String word:splittedBySpaces) + { + if(!word.contains("/n") && getStringWidth(sb)+getStringWidth(word) ihlItemStackRegistry = new HashMap(); + private static final String Digits = "(\\p{Digit}+)"; + private static final String HexDigits = "(\\p{XDigit}+)"; + private static final String Exp = "[eE][+-]?" + Digits; + private static final String fpRegex = ("[\\x00-\\x20]*" + // Optional + // leading + // "whitespace" + "[+-]?(" + // Optional sign character + "NaN|" + // "NaN" string + "Infinity|" + // "Infinity" string + "(((" + Digits + "(\\.)?(" + Digits + "?)(" + Exp + ")?)|" + "(\\.(" + Digits + ")(" + Exp + ")?)|" + "((" + + "(0[xX]" + HexDigits + "(\\.)?)|" + "(0[xX]" + HexDigits + "?(\\.)" + HexDigits + ")" + ")[pP][+-]?" + + Digits + "))" + "[fFdD]?))" + "[\\x00-\\x20]*");// Optional + // trailing + // "whitespace" + + public static void registerLocally(String name, ItemStack stack) { + ihlItemStackRegistry.put(name, stack); + } + + public static ItemStack getOreDictItemStack(String name) { + ItemStack ore = OreDictionary.getOres(name).get(0); + if (ore == null) + return null; + ItemStack orecopy = ore.copy(); + orecopy.stackSize = 1; + return orecopy; + } + + public static boolean hasOreDictionaryEntry(String name) { + return !OreDictionary.getOres(name).isEmpty(); + } + + public static Item getOreDictItem(String name) { + return OreDictionary.getOres(name).get(0).getItem(); + } + + public static Block getOreDictBlock(String name) { + return Block.getBlockFromItem(OreDictionary.getOres(name).get(0).getItem()); + } + + public static ItemStack getOreDictItemStackWithSize(String name, int size) { + ItemStack ore = OreDictionary.getOres(name).get(0); + if (ore == null) + return null; + ItemStack orecopy = ore.copy(); + orecopy.stackSize = size; + return orecopy; + } + + public static String getFirstOreDictName(ItemStack stack) { + int[] arrayIDs = OreDictionary.getOreIDs(stack); + if (arrayIDs.length > 0) { + return OreDictionary.getOreName(arrayIDs[0]); + } + return ""; + } + + public static ItemStack getThisModItemStack(String name) { + if (ihlItemStackRegistry.get(name) != null) { + return ihlItemStackRegistry.get(name).copy(); + } + if (GameRegistry.findItem("ihl", name) != null) { + return new ItemStack(GameRegistry.findItem("ihl", name)); + } else if (GameRegistry.findBlock("ihl", name) == null) { + throw new IllegalArgumentException("No such item in item registry: ihl:" + name); + } else { + return new ItemStack(GameRegistry.findBlock("ihl", name)); + } + } + + public static ItemStack getThisModItemStackWithSize(String name, int i) { + if (ihlItemStackRegistry.get(name) != null) { + ItemStack stack = ihlItemStackRegistry.get(name).copy(); + stack.stackSize = i; + return stack; + } + if (GameRegistry.findItem("ihl", name) != null) { + return new ItemStack(GameRegistry.findItem("ihl", name), i); + } else if (GameRegistry.findBlock("ihl", name) == null) { + throw new IllegalArgumentException("No such item in item registry: ihl:" + name); + } else { + return new ItemStack(GameRegistry.findBlock("ihl", name), i); + } + } + + public static ItemStack getOtherModItemStackWithDamage(String modname, String name, int damage, int quantity) { + if (GameRegistry.findItem(modname, name) != null) { + return new ItemStack(GameRegistry.findItem(modname, name), quantity, damage); + } else if (GameRegistry.findBlock(modname, name) == null) { + return null; + } else { + return new ItemStack(GameRegistry.findBlock(modname, name), quantity, damage); + } + } + + public static Item getThisModItem(String name) { + if (GameRegistry.findItem("ihl", name) != null) { + return GameRegistry.findItem("ihl", name); + } else if (GameRegistry.findBlock("ihl", name) == null) { + throw new IllegalArgumentException("No such item in item registry: ihl:" + name); + } else { + return Item.getItemFromBlock(GameRegistry.findBlock("ihl", name)); + } + } + + public static FluidStack getFluidStackWithSize(String name, int i) { + if (FluidRegistry.isFluidRegistered(name)) { + return FluidRegistry.getFluidStack(name, i); + } else { + throw new IllegalArgumentException("No such fluid: " + name); + } + } + + public static Block getThisModBlock(String name) { + if (GameRegistry.findBlock("ihl", name) == null) { + throw new IllegalArgumentException("No such block in item registry: ihl:" + name); + } else { + return GameRegistry.findBlock("ihl", name); + } + } + + public static ItemStack getThisModItemStackWithDamage(String name, int value) { + ItemStack stack = getThisModItemStack(name); + stack.setItemDamage(value); + return stack; + } + + public static boolean adjustWireLength(ItemStack stack, int adjustBy) { + int length = getWireLength(stack); + if (length <= 0) { + return true; + } else { + int newLength = Math.max(length + adjustBy, 0); + stack.stackTagCompound.setInteger(((IWire) stack.getItem()).getTag(), newLength); + stack.stackTagCompound.setInteger(((IWire) stack.getItem()).getTagSecondary(), newLength); + if (newLength == 0) { + return true; + } + return false; + } + } + + public static int getWireLength(ItemStack itemStack) { + return itemStack.stackTagCompound.getInteger(((IWire) itemStack.getItem()).getTag()); + } + + public static ItemStack getThisModWireItemStackWithLength(String name, int i) { + if (getThisModItemStack(name) != null) { + ItemStack stack = getThisModItemStack(name); + if (stack.getItem() instanceof IWire) { + stack.stackTagCompound = new NBTTagCompound(); + stack.stackTagCompound.setInteger(((IWire) stack.getItem()).getTag(), i); + stack.stackTagCompound.setInteger(((IWire) stack.getItem()).getTagSecondary(), i); + return stack; + } else { + throw new IllegalArgumentException("ihl:" + name + " is not an instance of IWire."); + } + } else { + throw new IllegalArgumentException("No such item in item registry: ihl:" + name); + } + } + + public static ItemStack getThisModWireItemStackWithLength(ItemStack stack1, int i) { + ItemStack stack = stack1.copy(); + if (stack1.getItem() instanceof IWire) { + stack.stackTagCompound = new NBTTagCompound(); + stack.stackTagCompound.setInteger(((IWire) stack.getItem()).getTag(), i); + stack.stackTagCompound.setInteger(((IWire) stack.getItem()).getTagSecondary(), i); + return stack; + } else { + throw new IllegalArgumentException(stack1.getUnlocalizedName() + " is not an instance of IWire."); + } + } + + public static boolean isItemsHaveSameOreDictionaryEntry(ItemStack is, ItemStack is1) { + int[] odids1 = OreDictionary.getOreIDs(is); + int[] odids2 = OreDictionary.getOreIDs(is1); + if (odids1 != null && odids1.length > 0 && odids2 != null && odids2.length > 0) { + for (int i1 = 0; i1 < odids1.length; i1++) { + for (int i2 = 0; i2 < odids2.length; i2++) { + if (!OreDictionary.getOreName(odids1[i1]).contains("Any") && odids1[i1] == odids2[i2]) { + return true; + } + } + } + } + return false; + } + + public static List getEntryListForOre(String name) { + ArrayList outputList = new ArrayList(); + ArrayList oreList = OreDictionary.getOres(name); + Iterator oreListIterator = oreList.iterator(); + while (oreListIterator.hasNext()) { + outputList.add(oreListIterator.next().copy()); + } + return outputList; + } + + public static ItemStack getItemStackIfExist(String name) { + if (hasOreDictionaryEntry(name)) { + return getOreDictItemStack(name); + } else { + if (ihlItemStackRegistry.get(name) != null) { + return ihlItemStackRegistry.get(name).copy(); + } + if (GameRegistry.findItem("ihl", name) != null) { + return new ItemStack(GameRegistry.findItem("ihl", name)); + } else if (GameRegistry.findBlock("ihl", name) == null) { + return null; + } else { + return new ItemStack(GameRegistry.findBlock("ihl", name)); + } + } + } + + public static FluidStack getFluidStackIfExist(String string, int meltingFluidAmount) { + if (FluidRegistry.isFluidRegistered(string)) { + return getFluidStackWithSize(string, meltingFluidAmount); + } + return null; + } + + public static boolean addItemStackToInventory(EntityPlayer player, ItemStack stack) { + ItemStack[] inv = player.inventory.mainInventory; + for (int i = 0; i <= 35; i++) { + if (inv[i] != null) { + if (inv[i].getItem() == stack.getItem()) { + if (inv[i].getItemDamage() == stack.getItemDamage() + && inv[i].stackSize < inv[i].getMaxStackSize()) { + inv[i].stackSize += stack.stackSize; + if (inv[i].stackSize > inv[i].getMaxStackSize()) { + stack.stackSize = inv[i].stackSize - inv[i].getMaxStackSize(); + } else { + return true; + } + } + } + } else { + inv[i] = stack; + return true; + } + } + return false; + } + + public static FluidStack getFluidStackWithSizeChemicallyPure(String name, int amount) { + FluidStack fstack = getFluidStackWithSize(name, amount); + fstack.tag = new NBTTagCompound(); + fstack.tag.setBoolean("chemicallyPure", true); + return fstack; + } + + public static void removeItemStackFromOreDictionaryEntry(String orename, ItemStack itemStack) { + ArrayList orelist = OreDictionary.getOres(orename); + Iterator oreListIterator = orelist.iterator(); + ItemStack odstack = null; + while (oreListIterator.hasNext()) { + odstack = oreListIterator.next(); + if (odstack.getItem() == itemStack.getItem()) { + break; + } else { + odstack = null; + } + } + if (odstack != null) { + orelist.remove(odstack); + IHLMod.log.debug("Stack " + odstack.getDisplayName() + " (" + odstack.toString() + ")" + + " removed from ore entry '" + orename + "'"); + } + } + + public static void addIC2MaceratorRecipe(String input, ItemStack output) { + if (Recipes.macerator.getOutputFor(getOreDictItemStack(input), false) == null) { + ((BasicMachineRecipeManager) Recipes.macerator).addRecipe(new RecipeInputOreDict(input), + new NBTTagCompound(), true, output); + } else { + // IHLMod.log.info("IC2 macerator recipe for "+input+" already + // exist. Skipped."); + } + } + + public static void addIC2MaceratorRecipe(String input, int stacksize, ItemStack output) { + if (Recipes.macerator.getOutputFor(getOreDictItemStackWithSize(input, stacksize), false) == null) { + ((BasicMachineRecipeManager) Recipes.macerator).addRecipe(new RecipeInputOreDict(input, stacksize), + new NBTTagCompound(), true, output); + } else { + // IHLMod.log.info("IC2 macerator recipe for "+input+" already + // exist. Skipped."); + } + } + + public static void addIC2MaceratorRecipe(ItemStack input, ItemStack output) { + if (Recipes.macerator.getOutputFor(input, false) == null) { + NBTTagCompound tag = new NBTTagCompound(); + Recipes.macerator.addRecipe(new RecipeInputItemStack(input), tag, output); + } else { + // IHLMod.log.info("IC2 macerator recipe for + // "+input.getDisplayName()+" already exist. Skipped."); + } + } + + public static void addIC2RollingRecipe(ItemStack input, ItemStack output) { + if (Recipes.metalformerRolling.getOutputFor(input, false) == null) { + NBTTagCompound tag = new NBTTagCompound(); + Recipes.metalformerRolling.addRecipe(new RecipeInputItemStack(input), tag, output); + } else { + // IHLMod.log.info("IC2 metal former (rolling) recipe for + // "+input.getDisplayName()+" already exist. Skipped."); + } + } + + public static void addIC2RollingRecipe(String input, ItemStack output) { + if (Recipes.metalformerRolling.getOutputFor(getThisModItemStack(input), false) == null) { + NBTTagCompound tag = new NBTTagCompound(); + Recipes.metalformerRolling.addRecipe(new RecipeInputOreDict(input), tag, output); + } else { + // IHLMod.log.info("IC2 metal former (rolling) recipe for "+input+" + // already exist. Skipped."); + } + } + + public static void addIC2ExtrudingRecipe(ItemStack input, ItemStack output) { + if (Recipes.metalformerExtruding.getOutputFor(input, false) == null) { + NBTTagCompound tag = new NBTTagCompound(); + Recipes.metalformerExtruding.addRecipe(new RecipeInputItemStack(input), tag, output); + } else { + // IHLMod.log.info("IC2 metal former (rolling) recipe for "+input+" + // already exist. Skipped."); + } + } + + public static void addIC2CentrifugeRecipe(String input, ItemStack output, ItemStack output2) { + if (Recipes.centrifuge.getOutputFor(getOreDictItemStack(input), false) == null) { + NBTTagCompound tag = new NBTTagCompound(); + tag.setInteger("minHeat", 2000); + Recipes.centrifuge.addRecipe(new RecipeInputOreDict(input), tag, new ItemStack[] { output, output2 }); + } else { + // IHLMod.log.info("IC2 centrifuge recipe for "+input+" already + // exist. Skipped."); + } + } + + public static void damageItemViaNBTTag(ItemStack stack, int amount) { + NBTTagCompound gtTagCompound; + if (stack.stackTagCompound.hasKey("GT.ToolStats")) { + gtTagCompound = stack.stackTagCompound.getCompoundTag("GT.ToolStats"); + } else { + stack.stackSize--; + return; + } + int damage = 0; + int maxDamage = 0; + if (gtTagCompound.hasKey("MaxDamage")) { + maxDamage = gtTagCompound.getInteger("MaxDamage"); + } else { + stack.stackSize--; + return; + } + + if (gtTagCompound.hasKey("Damage")) { + damage = gtTagCompound.getInteger("Damage"); + } + if (damage < maxDamage - amount) { + damage += amount; + gtTagCompound.setInteger("Damage", damage); + gtTagCompound.setInteger("MaxDamage", maxDamage); + stack.stackTagCompound.setTag("GT.ToolStats", gtTagCompound); + } else { + stack.stackSize--; + } + } + + public static int getDamageValueViaNBTTag(ItemStack stack) { + NBTTagCompound gtTagCompound = null; + if (stack != null && stack.stackTagCompound != null && stack.stackTagCompound.hasKey("GT.ToolStats")) { + gtTagCompound = stack.stackTagCompound.getCompoundTag("GT.ToolStats"); + } else { + return 0; + } + if (gtTagCompound != null && gtTagCompound.hasKey("Damage")) { + return gtTagCompound.getInteger("Damage"); + } else { + return 0; + } + } + + public static int getMaxDamageValueViaNBTTag(ItemStack stack) { + NBTTagCompound gtTagCompound = null; + if (stack != null && stack.stackTagCompound != null && stack.stackTagCompound.hasKey("GT.ToolStats")) { + gtTagCompound = stack.stackTagCompound.getCompoundTag("GT.ToolStats"); + } else { + return 0; + } + if (gtTagCompound != null && gtTagCompound.hasKey("MaxDamage")) { + return gtTagCompound.getInteger("MaxDamage"); + } else { + return 0; + } + } + + public static boolean isItemStacksIsEqual(ItemStack stack1, ItemStack stack2, boolean useOreDictionary) { + if(stack2==null && stack1==null){ + return true; + } + else if(stack2==null || stack1==null){ + return false; + } + if (useOreDictionary && isItemsHaveSameOreDictionaryEntry(stack1, stack2)) { + return true; + } else { + if (stack1.getItemDamage() == OreDictionary.WILDCARD_VALUE + || stack2.getItemDamage() == OreDictionary.WILDCARD_VALUE) { + return stack1.getItem() == stack2.getItem(); + } else { + return stack1.getItem() == stack2.getItem() && stack1.getItemDamage() == stack2.getItemDamage(); + } + } + } + + public static boolean isItemStacksIsEqual(ItemStack stack1, String stack2name, boolean useOreDictionary) { + return isItemStacksIsEqual(stack1, getThisModItemStack(stack2name), useOreDictionary); + } + + public static boolean isIRecipeInputMatchesWithAmount(IRecipeInput input, ItemStack stack) { + if (input.matches(stack)) { + if (stack.getItem() instanceof IWire) { + return getWireLength(stack) >= input.getAmount(); + } else { + return stack.stackSize >= input.getAmount(); + } + } + return false; + } + + public static boolean reduceItemStackAmountUsingIRecipeInput(IRecipeInput input, ItemStack stack, int multiplier) { + if (stack.getItem() instanceof IWire) { + return adjustWireLength(stack, -input.getAmount()*multiplier); + } else { + stack.stackSize -= input.getAmount()*multiplier; + return stack.stackSize <= 0; + } + } + + public static String getFirstOreDictNameExcludingTagAny(ItemStack stack) { + int[] arrayIDs = OreDictionary.getOreIDs(stack); + for (int i = 0; i < arrayIDs.length; i++) { + if (!OreDictionary.getOreName(arrayIDs[i]).contains("Any")) { + return OreDictionary.getOreName(arrayIDs[i]); + } + } + return ""; + } + + public static void handleFluidSlotsBehaviour(InvSlotConsumableLiquidIHL fillInputSlot, + InvSlotConsumableLiquidIHL drainInputSlot, InvSlotOutput emptyFluidItemsSlot, IFluidTank fluidTank) { + MutableObject output; + if (drainInputSlot != null && !drainInputSlot.isEmpty()) { + output = new MutableObject(); + if (fluidTank + .fill(drainInputSlot.drain(null, fluidTank.getCapacity() - fluidTank.getFluidAmount(), output, + true), false) > 0 + && (output.getValue() == null || emptyFluidItemsSlot.canAdd(output.getValue()))) { + fluidTank.fill( + drainInputSlot.drain(null, fluidTank.getCapacity() - fluidTank.getFluidAmount(), output, false), + true); + if (output.getValue() != null) { + emptyFluidItemsSlot.add(output.getValue()); + } + } + } + if (fillInputSlot != null && !fillInputSlot.isEmpty()) { + output = new MutableObject(); + if (fillInputSlot.transferFromTank(fluidTank, output, true) + && (output.getValue() == null || emptyFluidItemsSlot.canAdd(output.getValue()))) { + fillInputSlot.transferFromTank(fluidTank, output, false); + if (output.getValue() != null) { + emptyFluidItemsSlot.add(output.getValue()); + } + } + } + } + + public static double[] tracePlayerView(EntityLivingBase player) { + float f1 = player.rotationPitch; + float f2 = player.rotationYaw; + double x = player.posX; + double y = player.posY; + double z = player.posZ; + if (IC2.platform.isSimulating()) { + y += player.getEyeHeight(); + } + float f3 = MathHelper.cos(-f2 * 0.01745329F - (float) Math.PI); + float f4 = MathHelper.sin(-f2 * 0.01745329F - (float) Math.PI); + float f5 = -MathHelper.cos(-f1 * 0.01745329F); + float f6 = MathHelper.sin(-f1 * 0.01745329F); + float f7 = f4 * f5; + float f9 = f3 * f5; + double d3 = 1.0D; + return new double[] { x + f7 * d3, y + f6 * d3, z + f9 * d3 }; + } + + public static MovingObjectPosition returnMOPFromPlayer(EntityPlayer entityplayer, World world) { + float f1 = entityplayer.rotationPitch; + float f2 = entityplayer.rotationYaw; + double x = entityplayer.posX; + double y = entityplayer.posY + entityplayer.getEyeHeight(); + + if (world.isRemote) { + y -= entityplayer.getDefaultEyeHeight(); + } + + double z = entityplayer.posZ; + Vec3 vec3d = Vec3.createVectorHelper(x, y, z); + float f3 = MathHelper.cos(-f2 * 0.01745329F - (float) Math.PI); + float f4 = MathHelper.sin(-f2 * 0.01745329F - (float) Math.PI); + float f5 = -MathHelper.cos(-f1 * 0.01745329F); + float f6 = MathHelper.sin(-f1 * 0.01745329F); + float f7 = f4 * f5; + float f9 = f3 * f5; + double d3 = 5.0D; + Vec3 vec3d1 = vec3d.addVector(f7 * d3, f6 * d3, f9 * d3); + MovingObjectPosition movingobjectposition = world.rayTraceBlocks(vec3d, vec3d1, true); + + if (movingobjectposition == null) { + return null; + } + + if (movingobjectposition.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) { + return movingobjectposition; + } + return null; + } + + public static short getFacingFromPlayerView(EntityLivingBase player, boolean ignoreSneaking) { + int var6 = MathHelper.floor_double(player.rotationPitch * 4.0F / 360.0F + 0.5D) & 3; + int var7 = MathHelper.floor_double(player.rotationYaw * 4.0F / 360.0F + 0.5D) & 3; + { + if (var6 == 1) { + return 1; + } else if (var6 == 3) { + return 0; + } else { + if (player.isSneaking() && !ignoreSneaking) { + switch (var7) { + case 0: + return 3; + case 1: + return 4; + case 2: + return 2; + case 3: + return 5; + default: + break; + } + } else { + switch (var7) { + case 0: + return 2; + case 1: + return 5; + case 2: + return 3; + case 3: + return 4; + default: + break; + } + } + } + } + return 3; + } + + public static int getChainID(ItemStack itemStack) { + if (itemStack != null && itemStack.stackTagCompound != null && itemStack.stackTagCompound.hasKey("chainUID")) { + return itemStack.stackTagCompound.getInteger("chainUID"); + } + return -1; + } + + public static List convertRecipeInputToItemStackList(List input) { + Iterator irii = input.iterator(); + List output = new ArrayList(); + while (irii.hasNext()) { + IRecipeInput iri = irii.next(); + ItemStack stack = iri.getInputs().get(0); + stack.stackSize = iri.getAmount(); + output.add(stack); + } + return output; + } + + public static List convertRecipeInputToFluidStackList(List input) { + Iterator irii = input.iterator(); + List output = new ArrayList(); + while (irii.hasNext()) { + IRecipeInputFluid iri = irii.next(); + FluidStack stack = iri.getInputs().get(0); + stack.amount = iri.getAmount(); + output.add(stack); + } + return output; + } + + public static String trim(String str) { + int len = str.length(); + int start; + char c; + for (start = 0; start < len; ++start) { + c = str.charAt(start); + if (c > 32 && c != 65279) { + break; + } + } + int end; + for (end = len - 1; end >= start; --end) { + c = str.charAt(end); + if (c > 32 && c != 65279) { + break; + } + } + return start <= 0 && end >= len - 1 ? str : str.substring(start, end + 1); + } + + public static int getAmountOf(ItemStack is) { + if (is.getItem() instanceof IWire) { + return getWireLength(is); + } else { + return is.stackSize; + } + } + + public static ItemStack getWireItemStackCopyWithLengthMultiplied(ItemStack stack, int multiplier) { + ItemStack out = stack.copy(); + adjustWireLength(out, getWireLength(stack) * (multiplier - 1)); + return out; + } + + public static ItemStack getUninsulatedWire(String material, int length, int transverseSection) { + ItemStack is = getThisModItemStack("copperWire"); + is.stackTagCompound = new NBTTagCompound(); + is.stackTagCompound.setBoolean("firstConnection", false); + is.stackTagCompound.setInteger("fullLength", length); + is.stackTagCompound.setInteger("length", length); + is.stackTagCompound.setString("material", material); + is.stackTagCompound.setInteger("transverseSection", transverseSection); + return is; + } + + public static ItemStack getInsulatedWire(String material, int length, int transverseSection, + String insulationMaterial, int insulationThickness) { + ItemStack is = getUninsulatedWire(material, length, transverseSection); + is.stackTagCompound.setString("insulationMaterial", insulationMaterial); + is.stackTagCompound.setInteger("insulationThickness", insulationThickness); + is.stackTagCompound.setInteger("maxVoltage", getInsulationMaxVoltage(insulationMaterial, insulationThickness)); + return is; + } + + public static long getResistance(NBTTagCompound cable) { + String material = cable.getString("material"); + int transverseSection = cable.getInteger("transverseSection"); + return ElectricConductor.getResistivity(material) * 100L / transverseSection; + } + + public static int getInsulationMaxVoltage(String insulationMaterial, int insulationThickness) { + return Math.min(Insulation.getMaxVoltagePermm(insulationMaterial) * insulationThickness / 10, + Insulation.getMaxVoltageCap(insulationMaterial)); + } + + public static ItemStack getItemStackWithTag(String unLocalizedName, String tag, int tagValue) { + ItemStack stack = IHLUtils.getThisModItemStack(unLocalizedName); + if (stack.stackTagCompound == null) { + stack.stackTagCompound = new NBTTagCompound(); + } + stack.stackTagCompound.setInteger(tag, tagValue); + return stack; + } + + public static boolean isSegmentInsideAABB(AxisAlignedBB collisionBox, double posX, double posY, double posZ, + double posX2, double posY2, double posZ2) { + if (isInsideofBoundingBox(collisionBox, (float) posX, (float) posY, (float) posZ) + || isInsideofBoundingBox(collisionBox, (float) posX2, (float) posY2, (float) posZ2)) { + return true; + } else { + double minX = Math.min(posX, posX2); + double maxX = Math.max(posX, posX2); + double minY = Math.min(posY, posY2); + double maxY = Math.max(posY, posY2); + double minZ = Math.min(posZ, posZ2); + double maxZ = Math.max(posZ, posZ2); + return !(maxX < collisionBox.minX || minX > collisionBox.maxX || maxY < collisionBox.minY + || minY > collisionBox.maxY || maxZ < collisionBox.minZ || minZ > collisionBox.maxZ); + } + } + + public static boolean isInsideofBoundingBox(AxisAlignedBB bb, float xi, float yi, float zi) { + return bb.maxX > xi && bb.minX < xi && bb.maxY > yi && bb.minY < yi && bb.maxZ > zi && bb.minZ < zi; + } + + public static boolean isBlockCanBeReplaced(World world, int x, int y, int z) { + Block block = world.getBlock(x, y, z); + if (block == Blocks.air || block.isAir(world, x, y, z) || block == Blocks.vine || block == Blocks.tallgrass + || block == Blocks.deadbush || block == Blocks.snow_layer || block == Blocks.snow) { + return true; + } + return false; + } + + public static void removeChains(IEnergyNetNode te, World world) { + Set cableList = te.getCableList(); + Iterator cli = cableList.iterator(); + while (cli.hasNext()) { + IHLCable c = cli.next(); + cli.remove(); + IHLMod.enet.removeCableEntities(c); + ItemStack is = IHLUtils.getThisModItemStack("copperWire"); + is.stackTagCompound = c.toNBT(); + double[] pps = te.getPortPos(null); + EntityItem eitem = new EntityItem(world, pps[0], pps[1], pps[2], is); + world.spawnEntityInWorld(eitem); + removeChain(c, null); + } + if (te.getGridID() != -1) { + IHLMod.enet.splitGrids(te.getGridID(), te); + } + cableList.clear(); + } + + public static void removeChain(IHLCable cable, IEnergyNetNode excludeNode) { + int x = cable.connectorX1; + int y = cable.connectorY1; + int z = cable.connectorZ1; + int t2DimensionId = cable.connectorDimensionId1; + short facing2 = cable.connectorFacing1; + TileEntity t2 = MinecraftServer.getServer().worldServerForDimension(t2DimensionId).getTileEntity(x, y, z); + IEnergyNetNode te2; + if (t2 instanceof IMultiPowerCableHolder) { + te2 = ((IMultiPowerCableHolder) t2).getEnergyNetNode(facing2); + } else if (t2 instanceof IEnergyNetNode) { + te2 = (IEnergyNetNode) t2; + } else { + return; + } + if (excludeNode != te2) { + te2.remove(cable); + } + x = cable.connectorX; + y = cable.connectorY; + z = cable.connectorZ; + t2DimensionId = cable.connectorDimensionId; + facing2 = cable.connectorFacing; + t2 = MinecraftServer.getServer().worldServerForDimension(t2DimensionId).getTileEntity(x, y, z); + if (t2 instanceof IMultiPowerCableHolder) { + te2 = ((IMultiPowerCableHolder) t2).getEnergyNetNode(facing2); + } else if (t2 instanceof IEnergyNetNode) { + te2 = (IEnergyNetNode) t2; + } else { + return; + } + if (excludeNode != te2) { + te2.remove(cable); + } + } + + public static boolean isPlayerLookingAt(EntityLivingBase player, AxisAlignedBB aabb) { + double[] pView = tracePlayerView(player); + double x = player.posX; + double y = player.posY; + double z = player.posZ; + if (IC2.platform.isSimulating()) { + y += player.getEyeHeight(); + } + if (isLineSegmentInterseptRectangle(x, y, pView[0], pView[1], aabb.minX, aabb.minY, aabb.maxX, aabb.maxY) + && isLineSegmentInterseptRectangle(x, z, pView[0], pView[2], aabb.minX, aabb.minZ, aabb.maxX, aabb.maxZ) + && isLineSegmentInterseptRectangle(z, y, pView[2], pView[1], aabb.minZ, aabb.minY, aabb.maxZ, + aabb.maxY)) { + return true; + } + return false; + } + + public static boolean isLineSegmentInterseptRectangle(double sx0_1, double sy0_1, double sx1_1, double sy1_1, + double rx0_1, double ry0_1, double rx1_1, double ry1_1) { + double sx0 = sx0_1; + double sy0 = sy0_1; + double sx1 = sx1_1; + double sy1 = sy1_1; + double rx0 = rx0_1; + double ry0 = ry0_1; + double rx1 = rx1_1; + double ry1 = ry1_1; + if (sx1_1 < sx0_1) { + sx0 = sx1_1; + sy0 = sy1_1; + sx1 = sx0_1; + sy1 = sy0_1; + } + if (rx1_1 < rx0_1) { + rx0 = rx1_1; + ry0 = ry1_1; + rx1 = rx0_1; + ry1 = ry0_1; + } + double ay = (sy1 - sy0) / (sx1 - sx0); + double by = sy1 - ay * sx1; + + double ax = (sx1 - sx0) / (sy1 - sy0); + double bx = sx1 - ax * sy1; + + double maxx0 = Math.max(sx0, rx0); + double minx1 = Math.min(sx1, rx1); + double maxy0 = Math.max(sy0, ry0); + double miny1 = Math.min(sy1, ry1); + double y0 = ay * maxx0 + by; + double y1 = ay * minx1 + by; + + double x0 = ax * maxy0 + bx; + double x1 = ax * miny1 + bx; + return (ry0 <= y0 && ry1 >= y0) || (ry0 <= y1 && ry1 >= y1) || (rx0 <= x0 && rx1 >= x0) + || (rx0 <= x1 && rx1 >= x1); + } + + public static float parseFloatSafe(String string, float useSafeValue) { + if (Pattern.matches(fpRegex, string)) + return Float.valueOf(string); + else { + return useSafeValue; + } + } + + public static int parseIntSafe(String string, int useSafeValue) { + if (Pattern.matches(fpRegex, string)) + return Integer.valueOf(string); + else { + return useSafeValue; + } + } + + public static boolean isBlockRegisteredInOreDictionaryAs(Block block, String string) { + Iterator isoi = OreDictionary.getOres(string).iterator(); + while (isoi.hasNext()) { + if (Block.getBlockFromItem(isoi.next().getItem()) == block) { + return true; + } + } + return false; + } + + public static void setBlockAndTileEntityRaw(World world, int x, int y, int z, Block block, TileEntity te) { + Chunk chunk = world.getChunkProvider().provideChunk(x >> 4, z >> 4); + ExtendedBlockStorage[] ebsA = chunk.getBlockStorageArray(); + ExtendedBlockStorage ebs = ebsA[y >> 4]; + if (ebs == null) { + ebs = new ExtendedBlockStorage(y, true); + ebsA[y >> 4] = ebs; + } + setBlockRaw(ebs, x & 15, y & 15, z & 15, block); + te.xCoord = x; + te.yCoord = y; + te.zCoord = z; + te.setWorldObj(world); + chunk.addTileEntity(te); + } + + public static void setBlockRaw(ExtendedBlockStorage ebs, int x, int y, int z, Block block) { + int l = ebs.blockLSBArray[y << 8 | z << 4 | x] & 255; + + if (ebs.blockMSBArray != null) { + l |= ebs.blockMSBArray.get(x, y, z) << 8; + } + + Block block1 = Block.getBlockById(l); + + if (block1 != Blocks.air) { + --ebs.blockRefCount; + } + + if (block != Blocks.air) { + ++ebs.blockRefCount; + } + + int i1 = Block.getIdFromBlock(block); + ebs.blockLSBArray[y << 8 | z << 4 | x] = (byte) (i1 & 255); + + if (i1 > 255) { + if (ebs.blockMSBArray == null) { + ebs.blockMSBArray = new NibbleArray(ebs.blockLSBArray.length, 4); + } + + ebs.blockMSBArray.set(x, y, z, (i1 & 3840) >> 8); + } else if (ebs.blockMSBArray != null) { + ebs.blockMSBArray.set(x, y, z, 0); + } + } + + +} -- cgit v1.2.3