v5.5.5 Beta #2

*Added Dynamic Tanks.
*Added Dynamic Valves.
*Added Dynamic Glass.
*Added Wind Turbines.
*Factories can change recipe type.
*Events for liquid and energy transfer.
*Fixed console spam.
*Fixed major lag with Universal Cable and lava-carrying Mechanical
Pipes.
*Liquid now renders with correct transparency.
*Fixed bad packets with Mechanical Pipe.
*Fixed NPE with null array in liquid transfer.
*Sounds now load if the sound system changes state in-game.
*Sounds now pause when the game pauses.
*Other enhancements and fixes.
This commit is contained in:
Aidan Brady 2013-04-28 15:23:08 -04:00
parent 557d12bc0c
commit 05a8ea03e9
60 changed files with 3446 additions and 260 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.7 KiB

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.6 KiB

After

Width:  |  Height:  |  Size: 5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.7 KiB

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

View file

@ -0,0 +1,111 @@
package mekanism.client;
import mekanism.common.Mekanism;
import mekanism.common.TileEntityDynamicTank;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.world.IBlockAccess;
import org.lwjgl.opengl.GL11;
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class BasicRenderingHandler implements ISimpleBlockRenderingHandler
{
@Override
public void renderInventoryBlock(Block block, int metadata, int modelID, RenderBlocks renderer)
{
GL11.glPushMatrix();
GL11.glRotatef(90F, 0.0F, 1.0F, 0.0F);
if(block.blockID == Mekanism.basicBlockID)
{
renderItem(renderer, metadata, block);
}
GL11.glPopMatrix();
}
@Override
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer)
{
if(block.blockID == Mekanism.basicBlockID)
{
int metadata = world.getBlockMetadata(x, y, z);
renderer.renderStandardBlock(block, x, y, z);
renderer.setRenderBoundsFromBlock(block);
return true;
}
return false;
}
@Override
public boolean shouldRender3DInInventory()
{
return true;
}
@Override
public int getRenderId()
{
return ClientProxy.BASIC_RENDER_ID;
}
/**
* Cleaned-up snip of RenderBlocks.renderBlockAsItem() -- used for rendering an item as an entity,
* in a player's inventory, and in a player's hand.
* @param renderer - RenderBlocks renderer to render the item with
* @param metadata - block/item metadata
* @param block - block to render
*/
public void renderItem(RenderBlocks renderer, int metadata, Block block)
{
block.setBlockBoundsForItemRender();
renderer.setRenderBoundsFromBlock(block);
if(renderer.useInventoryTint)
{
int renderColor = block.getRenderColor(metadata);
float red = (float)(renderColor >> 16 & 255) / 255.0F;
float green = (float)(renderColor >> 8 & 255) / 255.0F;
float blue = (float)(renderColor & 255) / 255.0F;
GL11.glColor4f(red, green, blue, 1.0F);
}
GL11.glTranslatef(-0.5F, -0.5F, -0.5F);
Tessellator tessellator = Tessellator.instance;
tessellator.startDrawingQuads();
tessellator.setNormal(0.0F, -1.0F, 0.0F);
renderer.renderBottomFace(block, 0.0D, 0.0D, 0.0D, block.getIcon(0, metadata));
tessellator.draw();
tessellator.startDrawingQuads();
tessellator.setNormal(0.0F, 1.0F, 0.0F);
renderer.renderTopFace(block, 0.0D, 0.0D, 0.0D, block.getIcon(1, metadata));
tessellator.draw();
tessellator.startDrawingQuads();
tessellator.setNormal(0.0F, 0.0F, -1.0F);
renderer.renderEastFace(block, 0.0D, 0.0D, 0.0D, block.getIcon(2, metadata));
tessellator.draw();
tessellator.startDrawingQuads();
tessellator.setNormal(0.0F, 0.0F, 1.0F);
renderer.renderWestFace(block, 0.0D, 0.0D, 0.0D, block.getIcon(3, metadata));
tessellator.draw();
tessellator.startDrawingQuads();
tessellator.setNormal(-1.0F, 0.0F, 0.0F);
renderer.renderNorthFace(block, 0.0D, 0.0D, 0.0D, block.getIcon(4, metadata));
tessellator.draw();
tessellator.startDrawingQuads();
tessellator.setNormal(1.0F, 0.0F, 0.0F);
renderer.renderSouthFace(block, 0.0D, 0.0D, 0.0D, block.getIcon(5, metadata));
tessellator.draw();
GL11.glTranslatef(0.5F, 0.5F, 0.5F);
}
}

View file

@ -98,7 +98,7 @@ public class BlockRenderingHandler implements ISimpleBlockRenderingHandler
@Override @Override
public int getRenderId() public int getRenderId()
{ {
return ClientProxy.RENDER_ID; return ClientProxy.MACHINE_RENDER_ID;
} }
/** /**

View file

@ -11,6 +11,8 @@ import mekanism.common.ItemPortableTeleporter;
import mekanism.common.Mekanism; import mekanism.common.Mekanism;
import mekanism.common.TileEntityAdvancedElectricMachine; import mekanism.common.TileEntityAdvancedElectricMachine;
import mekanism.common.TileEntityControlPanel; import mekanism.common.TileEntityControlPanel;
import mekanism.common.TileEntityDynamicTank;
import mekanism.common.TileEntityDynamicValve;
import mekanism.common.TileEntityElectricChest; import mekanism.common.TileEntityElectricChest;
import mekanism.common.TileEntityElectricMachine; import mekanism.common.TileEntityElectricMachine;
import mekanism.common.TileEntityElectricPump; import mekanism.common.TileEntityElectricPump;
@ -46,8 +48,9 @@ import cpw.mods.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public class ClientProxy extends CommonProxy public class ClientProxy extends CommonProxy
{ {
public static int RENDER_ID = RenderingRegistry.getNextAvailableRenderId(); public static int MACHINE_RENDER_ID = RenderingRegistry.getNextAvailableRenderId();
public static int TRANSMITTER_RENDER_ID = RenderingRegistry.getNextAvailableRenderId(); public static int TRANSMITTER_RENDER_ID = RenderingRegistry.getNextAvailableRenderId();
public static int BASIC_RENDER_ID = RenderingRegistry.getNextAvailableRenderId();
@Override @Override
public void loadConfiguration() public void loadConfiguration()
@ -68,20 +71,26 @@ public class ClientProxy extends CommonProxy
@Override @Override
public void registerSound(TileEntity tileEntity) public void registerSound(TileEntity tileEntity)
{ {
synchronized(Mekanism.audioHandler.sounds) if(Mekanism.enableSounds && FMLClientHandler.instance().getClient().sndManager.sndSystem != null)
{ {
Mekanism.audioHandler.register(tileEntity); synchronized(Mekanism.audioHandler.sounds)
{
Mekanism.audioHandler.register(tileEntity);
}
} }
} }
@Override @Override
public void unregisterSound(TileEntity tileEntity) public void unregisterSound(TileEntity tileEntity)
{ {
synchronized(Mekanism.audioHandler.sounds) if(Mekanism.enableSounds && FMLClientHandler.instance().getClient().sndManager.sndSystem != null)
{ {
if(Mekanism.audioHandler.getFrom(tileEntity) != null) synchronized(Mekanism.audioHandler.sounds)
{ {
Mekanism.audioHandler.getFrom(tileEntity).remove(); if(Mekanism.audioHandler.getFrom(tileEntity) != null)
{
Mekanism.audioHandler.getFrom(tileEntity).remove();
}
} }
} }
} }
@ -150,6 +159,8 @@ public class ClientProxy extends CommonProxy
ClientRegistry.registerTileEntity(TileEntityElectricPump.class, "ElectricPump", new RenderElectricPump()); ClientRegistry.registerTileEntity(TileEntityElectricPump.class, "ElectricPump", new RenderElectricPump());
ClientRegistry.registerTileEntity(TileEntityElectricChest.class, "ElectricChest", new RenderElectricChest()); ClientRegistry.registerTileEntity(TileEntityElectricChest.class, "ElectricChest", new RenderElectricChest());
ClientRegistry.registerTileEntity(TileEntityMechanicalPipe.class, "MechanicalPipe", new RenderMechanicalPipe()); ClientRegistry.registerTileEntity(TileEntityMechanicalPipe.class, "MechanicalPipe", new RenderMechanicalPipe());
ClientRegistry.registerTileEntity(TileEntityDynamicTank.class, "DynamicTank", new RenderDynamicTank());
ClientRegistry.registerTileEntity(TileEntityDynamicValve.class, "DynamicValve", new RenderDynamicTank());
} }
@Override @Override
@ -165,6 +176,7 @@ public class ClientProxy extends CommonProxy
//Register block handlers //Register block handlers
RenderingRegistry.registerBlockHandler(new BlockRenderingHandler()); RenderingRegistry.registerBlockHandler(new BlockRenderingHandler());
RenderingRegistry.registerBlockHandler(new TransmitterRenderer()); RenderingRegistry.registerBlockHandler(new TransmitterRenderer());
RenderingRegistry.registerBlockHandler(new BasicRenderingHandler());
System.out.println("[Mekanism] Render registrations complete."); System.out.println("[Mekanism] Render registrations complete.");
} }
@ -216,6 +228,8 @@ public class ClientProxy extends CommonProxy
return new GuiEnergizedSmelter(player.inventory, (TileEntityElectricMachine)tileEntity); return new GuiEnergizedSmelter(player.inventory, (TileEntityElectricMachine)tileEntity);
case 17: case 17:
return new GuiElectricPump(player.inventory, (TileEntityElectricPump)tileEntity); return new GuiElectricPump(player.inventory, (TileEntityElectricPump)tileEntity);
case 18:
return new GuiDynamicTank(player.inventory, (TileEntityDynamicTank)tileEntity);
case 19: case 19:
return new GuiPasswordEnter((TileEntityElectricChest)tileEntity); return new GuiPasswordEnter((TileEntityElectricChest)tileEntity);
case 20: case 20:
@ -247,18 +261,40 @@ public class ClientProxy extends CommonProxy
@Override @Override
public void unloadSoundHandler() public void unloadSoundHandler()
{ {
if(Mekanism.audioHandler != null) if(Mekanism.enableSounds)
{ {
synchronized(Mekanism.audioHandler.sounds) if(Mekanism.audioHandler != null)
{ {
HashMap<TileEntity, Sound> sounds = new HashMap<TileEntity, Sound>(); synchronized(Mekanism.audioHandler.sounds)
sounds.putAll(Mekanism.audioHandler.sounds);
for(Sound sound : sounds.values())
{ {
sound.remove(); HashMap<TileEntity, Sound> sounds = new HashMap<TileEntity, Sound>();
sounds.putAll(Mekanism.audioHandler.sounds);
for(Sound sound : sounds.values())
{
sound.remove();
}
} }
} }
} }
} }
@Override
public boolean isPaused()
{
if(FMLClientHandler.instance().getClient().isSingleplayer() && !FMLClientHandler.instance().getClient().getIntegratedServer().getPublic())
{
GuiScreen screen = FMLClientHandler.instance().getClient().currentScreen;
if(screen != null)
{
if(screen.doesGuiPauseGame())
{
return true;
}
}
}
return false;
}
} }

View file

@ -0,0 +1,103 @@
package mekanism.client;
import mekanism.common.ContainerDynamicTank;
import mekanism.common.TileEntityDynamicTank;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraftforge.liquids.LiquidDictionary;
import net.minecraftforge.liquids.LiquidStack;
import org.lwjgl.opengl.GL11;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class GuiDynamicTank extends GuiContainer
{
public TileEntityDynamicTank tileEntity;
private int guiWidth;
private int guiHeight;
public GuiDynamicTank(InventoryPlayer inventory, TileEntityDynamicTank tentity)
{
super(new ContainerDynamicTank(inventory, tentity));
tileEntity = tentity;
}
@Override
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY)
{
int xAxis = (mouseX - (width - xSize) / 2);
int yAxis = (mouseY - (height - ySize) / 2);
fontRenderer.drawString(tileEntity.fullName, 45, 6, 0x404040);
fontRenderer.drawString("Inventory", 8, (ySize - 94) + 2, 0x404040);
fontRenderer.drawString("Volume: " + tileEntity.clientCapacity/16000, 53, 26, 0x00CD00);
fontRenderer.drawString(tileEntity.structure.liquidStored != null ? LiquidDictionary.findLiquidName(tileEntity.structure.liquidStored) + ": " + tileEntity.structure.liquidStored.amount : "No liquid.", 53, 35, 0x00CD00);
if(xAxis >= 7 && xAxis <= 39 && yAxis >= 14 && yAxis <= 72)
{
drawCreativeTabHoveringText(tileEntity.structure.liquidStored != null ? LiquidDictionary.findLiquidName(tileEntity.structure.liquidStored) + ": " + tileEntity.structure.liquidStored.amount + "mB" : "Empty", xAxis, yAxis);
}
}
@Override
protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3)
{
mc.renderEngine.bindTexture("/mods/mekanism/gui/GuiDynamicTank.png");
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
guiWidth = (width - xSize) / 2;
guiHeight = (height - ySize) / 2;
drawTexturedModalRect(guiWidth, guiHeight, 0, 0, xSize, ySize);
if(tileEntity.getScaledLiquidLevel(58) > 0)
{
displayGauge(guiWidth, guiHeight, 7, 14, tileEntity.getScaledLiquidLevel(58), tileEntity.structure.liquidStored, 0);
displayGauge(guiWidth, guiHeight, 23, 14, tileEntity.getScaledLiquidLevel(58), tileEntity.structure.liquidStored, 1);
}
}
/*
* Credit to BuildCraft for both the gauge texture and parts of the code.
*/
public void displayGauge(int width, int height, int xPos, int yPos, int scale, LiquidStack liquid, int side /*0-left, 1-right*/)
{
if(liquid == null)
{
return;
}
int start = 0;
while(true)
{
int renderRemaining = 0;
if(scale > 16)
{
renderRemaining = 16;
scale -= 16;
}
else {
renderRemaining = scale;
scale = 0;
}
mc.renderEngine.bindTexture(liquid.canonical().getTextureSheet());
drawTexturedModelRectFromIcon(width + xPos, height + yPos + 58 - renderRemaining - start, liquid.canonical().getRenderingIcon(), 16, 16 - (16 - renderRemaining));
start+=16;
if(renderRemaining == 0 || scale == 0)
{
break;
}
}
mc.renderEngine.bindTexture("/mods/mekanism/gui/GuiDynamicTank.png");
drawTexturedModalRect(width + xPos, height + yPos, 176, side == 0 ? 0 : 54, 16, 54);
}
}

View file

@ -51,6 +51,9 @@ public class GuiFactory extends GuiContainer
displayInt = tileEntity.getScaledUpgradeProgress(14); displayInt = tileEntity.getScaledUpgradeProgress(14);
drawTexturedModalRect(guiWidth + 180, guiHeight + 30, 176 + 26, 72, 10, displayInt); drawTexturedModalRect(guiWidth + 180, guiHeight + 30, 176 + 26, 72, 10, displayInt);
displayInt = tileEntity.getScaledRecipeProgress(15);
drawTexturedModalRect(guiWidth + 181, guiHeight + 94, 176 + 26, 86, 10, displayInt);
if(tileEntity.tier == FactoryTier.BASIC) if(tileEntity.tier == FactoryTier.BASIC)
{ {
for(int i = 0; i < tileEntity.tier.processes; i++) for(int i = 0; i < tileEntity.tier.processes; i++)

View file

@ -67,7 +67,7 @@ public class ItemRenderingHandler implements IItemRenderer
electricChest.renderAll(); electricChest.renderAll();
} }
else { else {
RenderingRegistry.instance().renderInventoryBlock((RenderBlocks)data[0], Block.blocksList[Mekanism.machineBlockID], item.getItemDamage(), ClientProxy.RENDER_ID); RenderingRegistry.instance().renderInventoryBlock((RenderBlocks)data[0], Block.blocksList[Mekanism.machineBlockID], item.getItemDamage(), ClientProxy.MACHINE_RENDER_ID);
} }
} }

View file

@ -0,0 +1,357 @@
package mekanism.client;
import java.util.HashMap;
import java.util.Map;
import mekanism.api.Object3D;
import mekanism.client.ObjectRenderer.Model3D;
import mekanism.common.SynchronizedTankData.ValveData;
import mekanism.common.TileEntityDynamicTank;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.GLAllocation;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.tileentity.TileEntityRenderer;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.liquids.LiquidStack;
import org.lwjgl.opengl.GL11;
public class RenderDynamicTank extends TileEntitySpecialRenderer
{
private static RenderBlocks renderBlocks = new RenderBlocks();
private static Map<RenderData, HashMap<LiquidStack, int[]>> cachedCenterLiquids = new HashMap<RenderData, HashMap<LiquidStack, int[]>>();
private static Map<ValveRenderData, HashMap<LiquidStack, ValveDisplayInteger>> cachedValveLiquids = new HashMap<ValveRenderData, HashMap<LiquidStack, ValveDisplayInteger>>();
@Override
public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float partialTick)
{
renderAModelAt((TileEntityDynamicTank)tileEntity, x, y, z, partialTick);
}
public void renderAModelAt(TileEntityDynamicTank tileEntity, double x, double y, double z, float partialTick)
{
if(tileEntity.clientHasStructure && tileEntity.isRendering && tileEntity.structure != null && tileEntity.structure.liquidStored != null && tileEntity.structure.liquidStored.amount != 0)
{
RenderData data = new RenderData();
data.location = tileEntity.structure.renderLocation;
data.height = tileEntity.structure.volHeight;
data.length = tileEntity.structure.volLength;
data.width = tileEntity.structure.volWidth;
bindTextureByName(tileEntity.structure.liquidStored.canonical().getTextureSheet());
if(data.location != null && data.height > 0)
{
push();
GL11.glTranslated(getX(data.location.xCoord), getY(data.location.yCoord), getZ(data.location.zCoord));
int[] displayList = getListAndRender(data, tileEntity.structure.liquidStored.canonical(), tileEntity.worldObj);
GL11.glCallList(displayList[(int)(((float)tileEntity.structure.liquidStored.amount/(float)tileEntity.clientCapacity)*((float)getStages(data.height)-1))]);
pop();
for(ValveData valveData : tileEntity.valveViewing.keySet())
{
if(tileEntity.valveViewing.get(valveData) > 0)
{
push();
GL11.glTranslated(getX(valveData.location.xCoord), getY(valveData.location.yCoord), getZ(valveData.location.zCoord));
int display = getValveDisplay(ValveRenderData.get(data, valveData), tileEntity.structure.liquidStored, tileEntity.worldObj).display;
GL11.glCallList(display);
pop();
}
}
}
}
}
private void pop()
{
GL11.glPopAttrib();
GL11.glPopMatrix();
}
private void push()
{
GL11.glPushMatrix();
GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
GL11.glEnable(GL11.GL_CULL_FACE);
GL11.glEnable(GL11.GL_BLEND);
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
}
private int[] getListAndRender(RenderData data, LiquidStack stack, World world)
{
if(cachedCenterLiquids.containsKey(data) && cachedCenterLiquids.get(data).containsKey(stack))
{
return cachedCenterLiquids.get(data).get(stack);
}
Model3D toReturn = new Model3D();
toReturn.baseBlock = Block.waterStill;
toReturn.texture = stack.getRenderingIcon();
if(stack.itemID < Block.blocksList.length && Block.blocksList[stack.itemID] != null)
{
toReturn.baseBlock = Block.blocksList[stack.itemID];
}
final int stages = getStages(data.height);
int[] displays = new int[stages];
if(cachedCenterLiquids.containsKey(data))
{
cachedCenterLiquids.get(data).put(stack, displays);
}
else {
HashMap<LiquidStack, int[]> map = new HashMap<LiquidStack, int[]>();
map.put(stack, displays);
cachedCenterLiquids.put(data, map);
}
for(int i = 0; i < stages; i++)
{
displays[i] = GLAllocation.generateDisplayLists(1);
GL11.glNewList(displays[i], 4864);
toReturn.minX = 0 + .01;
toReturn.minY = 0 + .01;
toReturn.minZ = 0 + .01;
toReturn.maxX = data.length-2 - .01;
toReturn.maxY = ((float)i/(float)stages)*(data.height-2) - .01;
toReturn.maxZ = data.width-2 - .01;
ObjectRenderer.renderObject(toReturn, world, 0, 0, 0, false, true);
GL11.glEndList();
}
return displays;
}
private ValveDisplayInteger getValveDisplay(ValveRenderData data, LiquidStack stack, World world)
{
if(cachedValveLiquids.containsKey(data) && cachedValveLiquids.get(data).containsKey(stack))
{
return cachedValveLiquids.get(data).get(stack);
}
Model3D toReturn = new Model3D();
toReturn.baseBlock = Block.waterStill;
toReturn.texture = stack.getRenderingIcon();
if(stack.itemID < Block.blocksList.length && Block.blocksList[stack.itemID] != null)
{
toReturn.baseBlock = Block.blocksList[stack.itemID];
}
ValveDisplayInteger display = new ValveDisplayInteger();
if(cachedValveLiquids.containsKey(data))
{
cachedValveLiquids.get(data).put(stack, display);
}
else {
HashMap<LiquidStack, ValveDisplayInteger> map = new HashMap<LiquidStack, ValveDisplayInteger>();
map.put(stack, display);
cachedValveLiquids.put(data, map);
}
display.display = GLAllocation.generateDisplayLists(1);
GL11.glNewList(display.display, 4864);
switch(data.side)
{
case DOWN:
{
toReturn.minX = .3;
toReturn.minY = 1 + .01;
toReturn.minZ = .3;
toReturn.maxX = .7;
toReturn.maxY = 1.4 + .1;
toReturn.maxZ = .7;
break;
}
case UP:
{
toReturn.minX = .3;
toReturn.minY = -(data.height-2) - .01;
toReturn.minZ = .3;
toReturn.maxX = .7;
toReturn.maxY = -.01;
toReturn.maxZ = .7;
break;
}
case NORTH:
{
toReturn.minX = .3;
toReturn.minY = -(getValveLiquidHeight(data)) + .01;
toReturn.minZ = 1 + .02;
toReturn.maxX = .7;
toReturn.maxY = .7;
toReturn.maxZ = 1.4;
break;
}
case SOUTH:
{
toReturn.minX = .3;
toReturn.minY = -(getValveLiquidHeight(data)) + .01;
toReturn.minZ = -.4;
toReturn.maxX = .7;
toReturn.maxY = .7;
toReturn.maxZ = -.02;
break;
}
case WEST:
{
toReturn.minX = 1 + .02;
toReturn.minY = -(getValveLiquidHeight(data)) + .01;
toReturn.minZ = .3;
toReturn.maxX = 1.4;
toReturn.maxY = .7;
toReturn.maxZ = .7;
break;
}
case EAST:
{
toReturn.minX = -.4;
toReturn.minY = -(getValveLiquidHeight(data)) + .01;
toReturn.minZ = .3;
toReturn.maxX = -.02;
toReturn.maxY = .7;
toReturn.maxZ = .7;
break;
}
default:
{
break;
}
}
ObjectRenderer.renderObject(toReturn, world, 0, 0, 0, false, true);
GL11.glEndList();
return display;
}
private int getValveLiquidHeight(ValveRenderData data)
{
return data.valveLocation.yCoord - data.location.yCoord;
}
private int getStages(int height)
{
return (height-2)*1000;
}
private double getX(int x)
{
return x - TileEntityRenderer.staticPlayerX;
}
private double getY(int y)
{
return y - TileEntityRenderer.staticPlayerY;
}
private double getZ(int z)
{
return z - TileEntityRenderer.staticPlayerZ;
}
public static class RenderData
{
public Object3D location;
public int height;
public int length;
public int width;
@Override
public int hashCode()
{
int code = 1;
code = 31 * code + location.hashCode();
code = 31 * code + height;
code = 31 * code + length;
code = 31 * code + width;
return code;
}
@Override
public boolean equals(Object data)
{
return data instanceof RenderData && ((RenderData)data).location.equals(location) && ((RenderData)data).height == height;
}
}
public static class ValveRenderData extends RenderData
{
public ForgeDirection side;
public Object3D valveLocation;
public static ValveRenderData get(RenderData renderData, ValveData valveData)
{
ValveRenderData data = new ValveRenderData();
data.location = renderData.location;
data.height = renderData.height;
data.length = renderData.length;
data.width = renderData.width;
data.side = valveData.side;
data.valveLocation = valveData.location;
return data;
}
@Override
public boolean equals(Object data)
{
return data instanceof ValveRenderData && super.equals(data) && ((ValveRenderData)data).side.equals(side);
}
@Override
public int hashCode()
{
int code = 1;
code = 31 * code + super.hashCode();
code = 31 * code + side.ordinal();
code = 31 * code + valveLocation.hashCode();
return code;
}
}
public static class ValveDisplayInteger
{
public int display;
@Override
public int hashCode()
{
int code = 1;
code = 31 * code + display;
return code;
}
@Override
public boolean equals(Object obj)
{
return obj instanceof ValveDisplayInteger && ((ValveDisplayInteger)obj).display == display;
}
}
}

View file

@ -58,7 +58,7 @@ public class RenderMechanicalPipe extends TileEntitySpecialRenderer
{ {
int side = Arrays.asList(connectedAcceptors).indexOf(container); int side = Arrays.asList(connectedAcceptors).indexOf(container);
if(container.getTanks(ForgeDirection.getOrientation(side).getOpposite()).length != 0) if(container.getTanks(ForgeDirection.getOrientation(side).getOpposite()) != null && container.getTanks(ForgeDirection.getOrientation(side).getOpposite()).length != 0)
{ {
connectable[side] = true; connectable[side] = true;
} }
@ -92,8 +92,8 @@ public class RenderMechanicalPipe extends TileEntitySpecialRenderer
if(tileEntity.liquidScale > 0 && tileEntity.refLiquid != null) if(tileEntity.liquidScale > 0 && tileEntity.refLiquid != null)
{ {
GL11.glPushMatrix(); push();
GL11.glDisable(2896);
bindTextureByName(tileEntity.refLiquid.getTextureSheet()); bindTextureByName(tileEntity.refLiquid.getTextureSheet());
GL11.glTranslatef((float)x, (float)y, (float)z); GL11.glTranslatef((float)x, (float)y, (float)z);
@ -109,11 +109,26 @@ public class RenderMechanicalPipe extends TileEntitySpecialRenderer
int[] displayList = getListAndRender(ForgeDirection.UNKNOWN, tileEntity.refLiquid, tileEntity.worldObj); int[] displayList = getListAndRender(ForgeDirection.UNKNOWN, tileEntity.refLiquid, tileEntity.worldObj);
GL11.glCallList(displayList[Math.max(3, (int)((float)tileEntity.liquidScale*(stages-1)))]); GL11.glCallList(displayList[Math.max(3, (int)((float)tileEntity.liquidScale*(stages-1)))]);
GL11.glEnable(2896); pop();
GL11.glPopMatrix();
} }
} }
private void pop()
{
GL11.glPopAttrib();
GL11.glPopMatrix();
}
private void push()
{
GL11.glPushMatrix();
GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
GL11.glEnable(GL11.GL_CULL_FACE);
GL11.glEnable(GL11.GL_BLEND);
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
}
private int[] getListAndRender(ForgeDirection side, LiquidStack stack, World world) private int[] getListAndRender(ForgeDirection side, LiquidStack stack, World world)
{ {
if(cachedLiquids.containsKey(side) && cachedLiquids.get(side).containsKey(stack)) if(cachedLiquids.containsKey(side) && cachedLiquids.get(side).containsKey(stack))

View file

@ -96,6 +96,7 @@ public class RenderUniversalCable extends TileEntitySpecialRenderer
{ {
GL11.glPushMatrix(); GL11.glPushMatrix();
GL11.glDisable(2896); GL11.glDisable(2896);
bindTextureByName("/mods/mekanism/textures/items/LiquidEnergy.png"); bindTextureByName("/mods/mekanism/textures/items/LiquidEnergy.png");
GL11.glTranslatef((float)x, (float)y, (float)z); GL11.glTranslatef((float)x, (float)y, (float)z);

View file

@ -7,6 +7,7 @@ import java.util.Map;
import java.util.Random; import java.util.Random;
import mekanism.common.IActiveState; import mekanism.common.IActiveState;
import mekanism.common.Mekanism;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
@ -40,12 +41,9 @@ public class SoundHandler
*/ */
public SoundHandler() public SoundHandler()
{ {
if(soundSystem == null) soundSystem = FMLClientHandler.instance().instance().getClient().sndManager.sndSystem;
{ MinecraftForge.EVENT_BUS.register(this);
soundSystem = FMLClientHandler.instance().instance().getClient().sndManager.sndSystem; System.out.println("[Mekanism] Successfully set up SoundHandler.");
MinecraftForge.EVENT_BUS.register(this);
System.out.println("[Mekanism] Successfully set up SoundHandler.");
}
} }
/** /**
@ -55,59 +53,82 @@ public class SoundHandler
{ {
synchronized(sounds) synchronized(sounds)
{ {
ArrayList<Sound> soundsToRemove = new ArrayList<Sound>(); if(soundSystem == null)
World world = FMLClientHandler.instance().getClient().theWorld;
for(Sound sound : sounds.values())
{ {
if(FMLClientHandler.instance().getClient().thePlayer != null && world != null) soundSystem = FMLClientHandler.instance().instance().getClient().sndManager.sndSystem;
}
if(soundSystem != null)
{
if(!Mekanism.proxy.isPaused())
{ {
if(sound.tileEntity == null || !(sound.tileEntity instanceof IHasSound)) ArrayList<Sound> soundsToRemove = new ArrayList<Sound>();
World world = FMLClientHandler.instance().getClient().theWorld;
for(Sound sound : sounds.values())
{ {
soundsToRemove.add(sound); if(FMLClientHandler.instance().getClient().thePlayer != null && world != null)
continue;
}
else if(world.getBlockTileEntity(sound.tileEntity.xCoord, sound.tileEntity.yCoord, sound.tileEntity.zCoord) == null)
{
soundsToRemove.add(sound);
continue;
}
else if(world.getBlockTileEntity(sound.tileEntity.xCoord, sound.tileEntity.yCoord, sound.tileEntity.zCoord) != sound.tileEntity)
{
soundsToRemove.add(sound);
continue;
}
else if(((IHasSound)sound.tileEntity).getSoundPath() != sound.soundPath)
{
soundsToRemove.add(sound);
continue;
}
else if(sound.tileEntity instanceof IActiveState)
{
if(((IActiveState)sound.tileEntity).getActive() != sound.isPlaying)
{ {
if(((IActiveState)sound.tileEntity).getActive()) if(sound.tileEntity == null || !(sound.tileEntity instanceof IHasSound))
{ {
sound.play(); soundsToRemove.add(sound);
continue;
} }
else { else if(world.getBlockTileEntity(sound.tileEntity.xCoord, sound.tileEntity.yCoord, sound.tileEntity.zCoord) == null)
sound.stopLoop(); {
soundsToRemove.add(sound);
continue;
}
else if(world.getBlockTileEntity(sound.tileEntity.xCoord, sound.tileEntity.yCoord, sound.tileEntity.zCoord) != sound.tileEntity)
{
soundsToRemove.add(sound);
continue;
}
else if(((IHasSound)sound.tileEntity).getSoundPath() != sound.soundPath)
{
soundsToRemove.add(sound);
continue;
}
else if(sound.tileEntity instanceof IActiveState)
{
if(((IActiveState)sound.tileEntity).getActive() != sound.isPlaying)
{
if(((IActiveState)sound.tileEntity).getActive())
{
sound.play();
}
else {
sound.stopLoop();
}
}
}
if(sound.isPlaying)
{
sound.updateVolume(FMLClientHandler.instance().getClient().thePlayer);
} }
} }
} }
if(sound.isPlaying) for(Sound sound : soundsToRemove)
{ {
sound.updateVolume(FMLClientHandler.instance().getClient().thePlayer); sound.remove();
}
masterVolume = FMLClientHandler.instance().getClient().gameSettings.soundVolume;
}
else {
for(Sound sound : sounds.values())
{
if(sound.isPlaying)
{
sound.stopLoop();
}
} }
} }
} }
else {
for(Sound sound : soundsToRemove) Mekanism.proxy.unloadSoundHandler();
{
sound.remove();
} }
masterVolume = FMLClientHandler.instance().getClient().gameSettings.soundVolume;
} }
} }

View file

@ -1,24 +1,32 @@
package mekanism.common; package mekanism.common;
import static net.minecraftforge.common.ForgeDirection.UP;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Random;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import mekanism.api.Object3D;
import mekanism.client.ClientProxy;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockStairs;
import net.minecraft.block.BlockStep;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs; import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLiving; import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.EnumCreatureType;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Icon; import net.minecraft.util.Icon;
import net.minecraft.world.IBlockAccess; import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.liquids.LiquidContainerRegistry;
import net.minecraftforge.liquids.LiquidStack;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
/** /**
* Block class for handling multiple metal block IDs. * Block class for handling multiple metal block IDs.
@ -31,12 +39,16 @@ import net.minecraft.world.World;
* 6: Control Panel * 6: Control Panel
* 7: Teleporter Frame * 7: Teleporter Frame
* 8: Steel Casing * 8: Steel Casing
* 9: Dynamic Tank
* 10: Dynamic Glass
* 11: Dynamic Valve
* @author AidanBrady * @author AidanBrady
* *
*/ */
public class BlockBasic extends Block public class BlockBasic extends Block
{ {
public Icon[] icons = new Icon[256]; public Icon[] icons = new Icon[256];
public BlockBasic(int id) public BlockBasic(int id)
{ {
super(id, Material.iron); super(id, Material.iron);
@ -45,6 +57,20 @@ public class BlockBasic extends Block
setCreativeTab(Mekanism.tabMekanism); setCreativeTab(Mekanism.tabMekanism);
} }
@Override
public void onNeighborBlockChange(World world, int x, int y, int z, int id)
{
if(!world.isRemote)
{
if(world.getBlockTileEntity(x, y, z) instanceof TileEntityDynamicTank)
{
TileEntityDynamicTank dynamicTank = (TileEntityDynamicTank)world.getBlockTileEntity(x, y, z);
dynamicTank.update();
}
}
}
@Override @Override
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public void registerIcons(IconRegister register) public void registerIcons(IconRegister register)
@ -58,6 +84,9 @@ public class BlockBasic extends Block
icons[6] = register.registerIcon("mekanism:ControlPanel"); icons[6] = register.registerIcon("mekanism:ControlPanel");
icons[7] = register.registerIcon("mekanism:TeleporterFrame"); icons[7] = register.registerIcon("mekanism:TeleporterFrame");
icons[8] = register.registerIcon("mekanism:SteelCasing"); icons[8] = register.registerIcon("mekanism:SteelCasing");
icons[9] = register.registerIcon("mekanism:DynamicTank");
icons[10] = register.registerIcon("mekanism:DynamicGlass");
icons[11] = register.registerIcon("mekanism:DynamicValve");
} }
@Override @Override
@ -86,11 +115,49 @@ public class BlockBasic extends Block
//list.add(new ItemStack(i, 1, 6)); //list.add(new ItemStack(i, 1, 6));
list.add(new ItemStack(i, 1, 7)); list.add(new ItemStack(i, 1, 7));
list.add(new ItemStack(i, 1, 8)); list.add(new ItemStack(i, 1, 8));
list.add(new ItemStack(i, 1, 9));
list.add(new ItemStack(i, 1, 10));
list.add(new ItemStack(i, 1, 11));
} }
@Override
public boolean canCreatureSpawn(EnumCreatureType type, World world, int x, int y, int z)
{
int meta = world.getBlockMetadata(x, y, z);
if(meta == 9 || meta == 10 || meta == 11)
{
TileEntityDynamicTank tileEntity = (TileEntityDynamicTank)world.getBlockTileEntity(x, y, z);
if(tileEntity != null)
{
if(!world.isRemote)
{
if(tileEntity.structure != null)
{
return false;
}
}
else {
if(tileEntity.clientHasStructure)
{
return false;
}
}
}
}
return super.canCreatureSpawn(type, world, x, y, z);
}
@Override @Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityplayer, int i1, float f1, float f2, float f3) public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityplayer, int i1, float f1, float f2, float f3)
{ {
if(world.isRemote)
{
return true;
}
int metadata = world.getBlockMetadata(x, y, z); int metadata = world.getBlockMetadata(x, y, z);
if(metadata == 2) if(metadata == 2)
@ -109,8 +176,159 @@ public class BlockBasic extends Block
return true; return true;
} }
} }
else if(metadata == 9 || metadata == 10 || metadata == 11)
{
if(!entityplayer.isSneaking() && ((TileEntityDynamicTank)world.getBlockTileEntity(x, y, z)).structure != null)
{
TileEntityDynamicTank tileEntity = (TileEntityDynamicTank)world.getBlockTileEntity(x, y, z);
if(!manageInventory(entityplayer, tileEntity))
{
entityplayer.openGui(Mekanism.instance, 18, world, x, y, z);
}
else {
tileEntity.sendPacketToRenderer();
}
return true;
}
}
return false; return false;
} }
public boolean manageInventory(EntityPlayer player, TileEntityDynamicTank tileEntity)
{
ItemStack itemStack = player.getCurrentEquippedItem();
if(itemStack != null && tileEntity.structure != null)
{
if(LiquidContainerRegistry.isEmptyContainer(itemStack))
{
if(tileEntity.structure.liquidStored != null && tileEntity.structure.liquidStored.amount >= LiquidContainerRegistry.BUCKET_VOLUME)
{
ItemStack filled = LiquidContainerRegistry.fillLiquidContainer(tileEntity.structure.liquidStored, itemStack);
if(filled != null)
{
if(itemStack.stackSize > 1)
{
boolean didMove = false;
for(int i = 0; i < player.inventory.mainInventory.length; i++)
{
if(player.inventory.mainInventory[i] == null)
{
player.inventory.mainInventory[i] = filled;
itemStack.stackSize--;
tileEntity.structure.liquidStored.amount -= LiquidContainerRegistry.getLiquidForFilledItem(filled).amount;
if(tileEntity.structure.liquidStored.amount == 0)
{
tileEntity.structure.liquidStored = null;
}
return true;
}
else if(player.inventory.mainInventory[i].isItemEqual(filled))
{
if(filled.getMaxStackSize() > player.inventory.mainInventory[i].stackSize)
{
player.inventory.mainInventory[i].stackSize++;
itemStack.stackSize--;
tileEntity.structure.liquidStored.amount -= LiquidContainerRegistry.getLiquidForFilledItem(filled).amount;
if(tileEntity.structure.liquidStored.amount == 0)
{
tileEntity.structure.liquidStored = null;
}
return true;
}
}
}
}
else if(itemStack.stackSize == 1)
{
player.setCurrentItemOrArmor(0, filled);
tileEntity.structure.liquidStored.amount -= LiquidContainerRegistry.getLiquidForFilledItem(filled).amount;
if(tileEntity.structure.liquidStored.amount == 0)
{
tileEntity.structure.liquidStored = null;
}
return true;
}
}
}
}
else if(LiquidContainerRegistry.isFilledContainer(itemStack))
{
LiquidStack itemLiquid = LiquidContainerRegistry.getLiquidForFilledItem(itemStack);
int max = tileEntity.structure.volume*16000;
if(tileEntity.structure.liquidStored == null || (tileEntity.structure.liquidStored.amount+itemLiquid.amount <= max))
{
if(LiquidContainerRegistry.isBucket(itemStack))
{
if(tileEntity.structure.liquidStored == null)
{
tileEntity.structure.liquidStored = itemLiquid;
}
else {
tileEntity.structure.liquidStored.amount += itemLiquid.amount;
}
player.setCurrentItemOrArmor(0, new ItemStack(Item.bucketEmpty));
return true;
}
else {
itemStack.stackSize--;
if(itemStack.stackSize == 0)
{
player.setCurrentItemOrArmor(0, null);
}
if(tileEntity.structure.liquidStored == null)
{
tileEntity.structure.liquidStored = itemLiquid;
}
else {
tileEntity.structure.liquidStored.amount += itemLiquid.amount;
}
return true;
}
}
}
}
return false;
}
@Override
public boolean renderAsNormalBlock()
{
return false;
}
@Override
public boolean isOpaqueCube()
{
return false;
}
@Override
@SideOnly(Side.CLIENT)
public int getRenderType()
{
return ClientProxy.BASIC_RENDER_ID;
}
@Override @Override
public int getLightValue(IBlockAccess world, int x, int y, int z) public int getLightValue(IBlockAccess world, int x, int y, int z)
@ -131,7 +349,7 @@ public class BlockBasic extends Block
@Override @Override
public boolean hasTileEntity(int metadata) public boolean hasTileEntity(int metadata)
{ {
return metadata == 6; return metadata == 6 || metadata == 9 || metadata == 10 || metadata == 11;
} }
@Override @Override
@ -141,7 +359,14 @@ public class BlockBasic extends Block
{ {
case 6: case 6:
return new TileEntityControlPanel(); return new TileEntityControlPanel();
case 9:
return new TileEntityDynamicTank();
case 10:
return new TileEntityDynamicTank();
case 11:
return new TileEntityDynamicValve();
} }
return null; return null;
} }
@ -150,5 +375,15 @@ public class BlockBasic extends Block
{ {
world.markBlockForRenderUpdate(x, y, z); world.markBlockForRenderUpdate(x, y, z);
world.updateAllLightTypes(x, y, z); world.updateAllLightTypes(x, y, z);
if(world.getBlockTileEntity(x, y, z) != null && !world.isRemote)
{
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
if(tileEntity instanceof TileEntityDynamicTank)
{
((TileEntityDynamicTank)tileEntity).update();
}
}
} }
} }

View file

@ -1,12 +1,15 @@
package mekanism.common; package mekanism.common;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
import mekanism.api.IEnergizedItem; import mekanism.api.IEnergizedItem;
import mekanism.api.IUpgradeManagement; import mekanism.api.IUpgradeManagement;
import mekanism.api.Object3D;
import mekanism.client.ClientProxy; import mekanism.client.ClientProxy;
import mekanism.common.IFactory.RecipeType; import mekanism.common.IFactory.RecipeType;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer; import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.client.renderer.texture.IconRegister;
@ -105,7 +108,7 @@ public class BlockMachine extends BlockContainer
@Override @Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLiving entityliving, ItemStack itemstack) public void onBlockPlacedBy(World world, int x, int y, int z, EntityLiving entityliving, ItemStack itemstack)
{ {
TileEntityElectricBlock tileEntity = (TileEntityElectricBlock)world.getBlockTileEntity(x, y, z); TileEntityBasicBlock tileEntity = (TileEntityBasicBlock)world.getBlockTileEntity(x, y, z);
int side = MathHelper.floor_double((double)(entityliving.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3; int side = MathHelper.floor_double((double)(entityliving.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
int change = 3; int change = 3;
@ -129,8 +132,8 @@ public class BlockMachine extends BlockContainer
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public void randomDisplayTick(World world, int x, int y, int z, Random random) public void randomDisplayTick(World world, int x, int y, int z, Random random)
{ {
TileEntityElectricBlock tileEntity = (TileEntityElectricBlock)world.getBlockTileEntity(x, y, z); TileEntityBasicBlock tileEntity = (TileEntityBasicBlock)world.getBlockTileEntity(x, y, z);
if(MekanismUtils.isActive(world, x, y, z) && !(tileEntity instanceof TileEntityElectricPump)) if(MekanismUtils.isActive(world, x, y, z))
{ {
float xRandom = (float)x + 0.5F; float xRandom = (float)x + 0.5F;
float yRandom = (float)y + 0.0F + random.nextFloat() * 6.0F / 16.0F; float yRandom = (float)y + 0.0F + random.nextFloat() * 6.0F / 16.0F;
@ -314,7 +317,7 @@ public class BlockMachine extends BlockContainer
public Icon getBlockTexture(IBlockAccess world, int x, int y, int z, int side) public Icon getBlockTexture(IBlockAccess world, int x, int y, int z, int side)
{ {
int metadata = world.getBlockMetadata(x, y, z); int metadata = world.getBlockMetadata(x, y, z);
TileEntityElectricBlock tileEntity = (TileEntityElectricBlock)world.getBlockTileEntity(x, y, z); TileEntityBasicBlock tileEntity = (TileEntityBasicBlock)world.getBlockTileEntity(x, y, z);
if(metadata == 0) if(metadata == 0)
{ {
@ -492,7 +495,7 @@ public class BlockMachine extends BlockContainer
return true; return true;
} }
TileEntityElectricBlock tileEntity = (TileEntityElectricBlock)world.getBlockTileEntity(x, y, z); TileEntityBasicBlock tileEntity = (TileEntityBasicBlock)world.getBlockTileEntity(x, y, z);
int metadata = world.getBlockMetadata(x, y, z); int metadata = world.getBlockMetadata(x, y, z);
if(entityplayer.getCurrentEquippedItem() != null) if(entityplayer.getCurrentEquippedItem() != null)
@ -635,7 +638,7 @@ public class BlockMachine extends BlockContainer
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public int getRenderType() public int getRenderType()
{ {
return ClientProxy.RENDER_ID; return ClientProxy.MACHINE_RENDER_ID;
} }
@Override @Override
@ -656,7 +659,7 @@ public class BlockMachine extends BlockContainer
{ {
if(!player.capabilities.isCreativeMode && !world.isRemote && canHarvestBlock(player, world.getBlockMetadata(x, y, z))) if(!player.capabilities.isCreativeMode && !world.isRemote && canHarvestBlock(player, world.getBlockMetadata(x, y, z)))
{ {
TileEntityElectricBlock tileEntity = (TileEntityElectricBlock)world.getBlockTileEntity(x, y, z); TileEntityBasicBlock tileEntity = (TileEntityBasicBlock)world.getBlockTileEntity(x, y, z);
float motion = 0.7F; float motion = 0.7F;
double motionX = (world.rand.nextFloat() * motion) + (1.0F - motion) * 0.5D; double motionX = (world.rand.nextFloat() * motion) + (1.0F - motion) * 0.5D;
@ -680,7 +683,7 @@ public class BlockMachine extends BlockContainer
@Override @Override
public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z) public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z)
{ {
TileEntityElectricBlock tileEntity = (TileEntityElectricBlock)world.getBlockTileEntity(x, y, z); TileEntityBasicBlock tileEntity = (TileEntityBasicBlock)world.getBlockTileEntity(x, y, z);
ItemStack itemStack = new ItemStack(Mekanism.MachineBlock, 1, world.getBlockMetadata(x, y, z)); ItemStack itemStack = new ItemStack(Mekanism.MachineBlock, 1, world.getBlockMetadata(x, y, z));
if(((IUpgradeManagement)itemStack.getItem()).supportsUpgrades(itemStack)) if(((IUpgradeManagement)itemStack.getItem()).supportsUpgrades(itemStack))
@ -690,8 +693,11 @@ public class BlockMachine extends BlockContainer
upgrade.setSpeedMultiplier(((IUpgradeManagement)tileEntity).getSpeedMultiplier(), itemStack); upgrade.setSpeedMultiplier(((IUpgradeManagement)tileEntity).getSpeedMultiplier(), itemStack);
} }
IEnergizedItem energizedItem = (IEnergizedItem)itemStack.getItem(); if(tileEntity instanceof TileEntityElectricBlock)
energizedItem.setEnergy(itemStack, tileEntity.electricityStored); {
IEnergizedItem energizedItem = (IEnergizedItem)itemStack.getItem();
energizedItem.setEnergy(itemStack, ((TileEntityElectricBlock)tileEntity).electricityStored);
}
ISustainedInventory inventory = (ISustainedInventory)itemStack.getItem(); ISustainedInventory inventory = (ISustainedInventory)itemStack.getItem();
inventory.setInventory(((ISustainedInventory)tileEntity).getInventory(), itemStack); inventory.setInventory(((ISustainedInventory)tileEntity).getInventory(), itemStack);

View file

@ -152,7 +152,7 @@ public class BlockTransmitter extends Block
{ {
int side = Arrays.asList(connectedAcceptors).indexOf(container); int side = Arrays.asList(connectedAcceptors).indexOf(container);
if(container.getTanks(ForgeDirection.getOrientation(side).getOpposite()).length != 0) if(container.getTanks(ForgeDirection.getOrientation(side).getOpposite()) != null && container.getTanks(ForgeDirection.getOrientation(side).getOpposite()).length != 0)
{ {
connectable[side] = true; connectable[side] = true;
} }

View file

@ -28,6 +28,8 @@ public class CommonProxy
GameRegistry.registerTileEntity(TileEntityElectricPump.class, "ElectricPump"); GameRegistry.registerTileEntity(TileEntityElectricPump.class, "ElectricPump");
GameRegistry.registerTileEntity(TileEntityElectricChest.class, "ElectricChest"); GameRegistry.registerTileEntity(TileEntityElectricChest.class, "ElectricChest");
GameRegistry.registerTileEntity(TileEntityMechanicalPipe.class, "MechanicalPipe"); GameRegistry.registerTileEntity(TileEntityMechanicalPipe.class, "MechanicalPipe");
GameRegistry.registerTileEntity(TileEntityDynamicTank.class, "DynamicTank");
GameRegistry.registerTileEntity(TileEntityDynamicValve.class, "DynamicValve");
} }
/** /**
@ -118,6 +120,12 @@ public class CommonProxy
*/ */
public void unloadSoundHandler() {} public void unloadSoundHandler() {}
/** Whether or not the game is paused. */
public boolean isPaused()
{
return false;
}
/** /**
* Get the actual interface for a GUI. Client-only. * Get the actual interface for a GUI. Client-only.
* @param ID - gui ID * @param ID - gui ID
@ -175,6 +183,8 @@ public class CommonProxy
return new ContainerElectricMachine(player.inventory, (TileEntityElectricMachine)tileEntity); return new ContainerElectricMachine(player.inventory, (TileEntityElectricMachine)tileEntity);
case 17: case 17:
return new ContainerElectricPump(player.inventory, (TileEntityElectricPump)tileEntity); return new ContainerElectricPump(player.inventory, (TileEntityElectricPump)tileEntity);
case 18:
return new ContainerDynamicTank(player.inventory, (TileEntityDynamicTank)tileEntity);
} }
return null; return null;
} }

View file

@ -1,9 +1,15 @@
package mekanism.common; package mekanism.common;
import java.util.ArrayList;
import java.util.EnumSet; import java.util.EnumSet;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import mekanism.api.Object3D;
import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World; import net.minecraft.world.World;
import cpw.mods.fml.common.ITickHandler; import cpw.mods.fml.common.ITickHandler;
import cpw.mods.fml.common.TickType; import cpw.mods.fml.common.TickType;
@ -21,8 +27,68 @@ public class CommonWorldTickHandler implements ITickHandler
{ {
if(tickData[0] instanceof World) if(tickData[0] instanceof World)
{ {
ArrayList<Integer> idsToKill = new ArrayList<Integer>();
HashMap<Integer, HashSet<Object3D>> tilesToKill = new HashMap<Integer, HashSet<Object3D>>();
World world = (World)tickData[0]; World world = (World)tickData[0];
if(!world.isRemote)
{
for(Map.Entry<Integer, HashSet<Object3D>> entry : Mekanism.inventoryLocations.entrySet())
{
int inventoryID = entry.getKey();
for(Object3D obj : entry.getValue())
{
if(obj.dimensionId == world.provider.dimensionId)
{
TileEntityDynamicTank tileEntity = (TileEntityDynamicTank)obj.getTileEntity(world);
if(tileEntity == null || tileEntity.inventoryID != inventoryID)
{
if(!tilesToKill.containsKey(inventoryID))
{
tilesToKill.put(inventoryID, new HashSet<Object3D>());
}
tilesToKill.get(inventoryID).add(obj);
}
}
}
if(entry.getValue().isEmpty())
{
idsToKill.add(inventoryID);
}
}
for(Map.Entry<Integer, HashSet<Object3D>> entry : tilesToKill.entrySet())
{
for(Object3D obj : entry.getValue())
{
Mekanism.inventoryLocations.get(entry.getKey()).remove(obj);
}
}
for(int inventoryID : idsToKill)
{
for(Object3D obj : Mekanism.inventoryLocations.get(inventoryID))
{
TileEntityDynamicTank dynamicTank = (TileEntityDynamicTank)obj.getTileEntity(world);
if(dynamicTank != null)
{
dynamicTank.cachedLiquid = null;
dynamicTank.inventory = new ItemStack[2];
dynamicTank.inventoryID = -1;
}
}
Mekanism.inventoryLocations.remove(inventoryID);
Mekanism.dynamicInventories.remove(inventoryID);
}
}
for(Object obj : world.loadedEntityList) for(Object obj : world.loadedEntityList)
{ {
if(obj instanceof EntityItem) if(obj instanceof EntityItem)

View file

@ -0,0 +1,141 @@
package mekanism.common;
import ic2.api.IElectricItem;
import mekanism.common.SlotEnergy.SlotDischarge;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.liquids.LiquidContainerRegistry;
import universalelectricity.core.item.IItemElectric;
public class ContainerDynamicTank extends Container
{
private TileEntityDynamicTank tileEntity;
public ContainerDynamicTank(InventoryPlayer inventory, TileEntityDynamicTank tentity)
{
tileEntity = tentity;
addSlotToContainer(new Slot(tentity, 0, 146, 20));
addSlotToContainer(new SlotOutput(tentity, 1, 146, 51));
int slotX;
for(slotX = 0; slotX < 3; ++slotX)
{
for(int slotY = 0; slotY < 9; ++slotY)
{
addSlotToContainer(new Slot(inventory, slotY + slotX * 9 + 9, 8 + slotY * 18, 84 + slotX * 18));
}
}
for(slotX = 0; slotX < 9; ++slotX)
{
addSlotToContainer(new Slot(inventory, slotX, 8 + slotX * 18, 142));
}
tileEntity.playersUsing.add(inventory.player);
tileEntity.openChest();
}
@Override
public void onCraftGuiClosed(EntityPlayer entityplayer)
{
super.onCraftGuiClosed(entityplayer);
tileEntity.playersUsing.remove(entityplayer);
tileEntity.closeChest();
}
@Override
public boolean canInteractWith(EntityPlayer par1EntityPlayer)
{
return tileEntity.isUseableByPlayer(par1EntityPlayer);
}
@Override
public ItemStack transferStackInSlot(EntityPlayer player, int slotID)
{
ItemStack stack = null;
Slot currentSlot = (Slot)inventorySlots.get(slotID);
if(currentSlot != null && currentSlot.getHasStack())
{
ItemStack slotStack = currentSlot.getStack();
stack = slotStack.copy();
if((slotStack.getItem() instanceof IElectricItem && ((IElectricItem)slotStack.getItem()).canProvideEnergy(slotStack)) || (slotStack.getItem() instanceof IItemElectric && ((IItemElectric)slotStack.getItem()).getProvideRequest(slotStack).amperes != 0) || slotStack.itemID == Item.redstone.itemID)
{
if(slotID != 2)
{
if (!mergeItemStack(slotStack, 2, 3, false))
{
return null;
}
}
else if(slotID == 2)
{
if(!mergeItemStack(slotStack, 3, inventorySlots.size(), true))
{
return null;
}
}
}
else if(LiquidContainerRegistry.isEmptyContainer(slotStack) || LiquidContainerRegistry.isFilledContainer(slotStack))
{
if(slotID != 0 && slotID != 1)
{
if(!mergeItemStack(slotStack, 0, 1, false))
{
return null;
}
}
else {
if(!mergeItemStack(slotStack, 3, inventorySlots.size(), true))
{
return null;
}
}
}
else {
if(slotID >= 3 && slotID <= 29)
{
if(!mergeItemStack(slotStack, 30, inventorySlots.size(), false))
{
return null;
}
}
else if(slotID > 28)
{
if(!mergeItemStack(slotStack, 3, 29, false))
{
return null;
}
}
else {
if(!mergeItemStack(slotStack, 3, inventorySlots.size(), true))
{
return null;
}
}
}
if(slotStack.stackSize == 0)
{
currentSlot.putStack((ItemStack)null);
}
else {
currentSlot.onSlotChanged();
}
if(slotStack.stackSize == stack.stackSize)
{
return null;
}
currentSlot.onPickupFromSlot(player, slotStack);
}
return stack;
}
}

View file

@ -2,6 +2,7 @@ package mekanism.common;
import universalelectricity.core.item.IItemElectric; import universalelectricity.core.item.IItemElectric;
import ic2.api.IElectricItem; import ic2.api.IElectricItem;
import mekanism.common.BlockMachine.MachineType;
import mekanism.common.IFactory.RecipeType; import mekanism.common.IFactory.RecipeType;
import mekanism.common.Tier.FactoryTier; import mekanism.common.Tier.FactoryTier;
import mekanism.common.SlotEnergy.SlotDischarge; import mekanism.common.SlotEnergy.SlotDischarge;
@ -22,6 +23,8 @@ public class ContainerFactory extends Container
addSlotToContainer(new SlotMachineUpgrade(tentity, 0, 180, 11)); addSlotToContainer(new SlotMachineUpgrade(tentity, 0, 180, 11));
addSlotToContainer(new SlotDischarge(tentity, 1, 7, 35)); addSlotToContainer(new SlotDischarge(tentity, 1, 7, 35));
addSlotToContainer(new Slot(tentity, 2, 180, 75));
addSlotToContainer(new Slot(tentity, 3, 180, 112));
if(tileEntity.tier == FactoryTier.BASIC) if(tileEntity.tier == FactoryTier.BASIC)
{ {
@ -29,14 +32,14 @@ public class ContainerFactory extends Container
{ {
int xAxis = 55 + (i*38); int xAxis = 55 + (i*38);
addSlotToContainer(new Slot(tentity, 2+i, xAxis, 13)); addSlotToContainer(new Slot(tentity, 4+i, xAxis, 13));
} }
for(int i = 0; i < tileEntity.tier.processes; i++) for(int i = 0; i < tileEntity.tier.processes; i++)
{ {
int xAxis = 55 + (i*38); int xAxis = 55 + (i*38);
addSlotToContainer(new SlotOutput(tentity, tileEntity.tier.processes+2+i, xAxis, 57)); addSlotToContainer(new SlotOutput(tentity, tileEntity.tier.processes+4+i, xAxis, 57));
} }
} }
else if(tileEntity.tier == FactoryTier.ADVANCED) else if(tileEntity.tier == FactoryTier.ADVANCED)
@ -45,14 +48,14 @@ public class ContainerFactory extends Container
{ {
int xAxis = 35 + (i*26); int xAxis = 35 + (i*26);
addSlotToContainer(new Slot(tentity, 2+i, xAxis, 13)); addSlotToContainer(new Slot(tentity, 4+i, xAxis, 13));
} }
for(int i = 0; i < tileEntity.tier.processes; i++) for(int i = 0; i < tileEntity.tier.processes; i++)
{ {
int xAxis = 35 + (i*26); int xAxis = 35 + (i*26);
addSlotToContainer(new SlotOutput(tentity, tileEntity.tier.processes+2+i, xAxis, 57)); addSlotToContainer(new SlotOutput(tentity, tileEntity.tier.processes+4+i, xAxis, 57));
} }
} }
else if(tileEntity.tier == FactoryTier.ELITE) else if(tileEntity.tier == FactoryTier.ELITE)
@ -61,14 +64,14 @@ public class ContainerFactory extends Container
{ {
int xAxis = 29 + (i*19); int xAxis = 29 + (i*19);
addSlotToContainer(new Slot(tentity, 2+i, xAxis, 13)); addSlotToContainer(new Slot(tentity, 4+i, xAxis, 13));
} }
for(int i = 0; i < tileEntity.tier.processes; i++) for(int i = 0; i < tileEntity.tier.processes; i++)
{ {
int xAxis = 29 + (i*19); int xAxis = 29 + (i*19);
addSlotToContainer(new SlotOutput(tentity, tileEntity.tier.processes+2+i, xAxis, 57)); addSlotToContainer(new SlotOutput(tentity, tileEntity.tier.processes+4+i, xAxis, 57));
} }
} }
@ -120,6 +123,13 @@ public class ContainerFactory extends Container
{ {
return null; return null;
} }
}
else if(slotID != 2 && slotID != 3 && isProperMachine(slotStack) && !slotStack.isItemEqual(tileEntity.getMachineStack()))
{
if(!mergeItemStack(slotStack, 2, 3, false))
{
return null;
}
} }
else if((slotStack.getItem() instanceof IElectricItem && ((IElectricItem)slotStack.getItem()).canProvideEnergy(slotStack)) || (slotStack.getItem() instanceof IItemElectric && ((IItemElectric)slotStack.getItem()).getProvideRequest(slotStack).amperes != 0) || slotStack.itemID == Item.redstone.itemID) else if((slotStack.getItem() instanceof IElectricItem && ((IElectricItem)slotStack.getItem()).canProvideEnergy(slotStack)) || (slotStack.getItem() instanceof IItemElectric && ((IItemElectric)slotStack.getItem()).getProvideRequest(slotStack).amperes != 0) || slotStack.itemID == Item.redstone.itemID)
{ {
@ -214,14 +224,29 @@ public class ContainerFactory extends Container
return stack; return stack;
} }
public boolean isProperMachine(ItemStack itemStack)
{
if(itemStack != null && itemStack.getItem() instanceof ItemBlockMachine)
{
if(itemStack.getItemDamage() == MachineType.ENERGIZED_SMELTER.meta ||
itemStack.getItemDamage() == MachineType.ENRICHMENT_CHAMBER.meta ||
itemStack.getItemDamage() == MachineType.CRUSHER.meta)
{
return true;
}
}
return false;
}
public boolean isInputSlot(int slot) public boolean isInputSlot(int slot)
{ {
if(tileEntity.tier == Tier.FactoryTier.BASIC) if(tileEntity.tier == Tier.FactoryTier.BASIC)
return slot >= 2 && slot <= 4; return slot >= 4 && slot <= 6;
if(tileEntity.tier == Tier.FactoryTier.ADVANCED) if(tileEntity.tier == Tier.FactoryTier.ADVANCED)
return slot >= 2 && slot <= 6; return slot >= 4 && slot <= 8;
if(tileEntity.tier == Tier.FactoryTier.ELITE) if(tileEntity.tier == Tier.FactoryTier.ELITE)
return slot >= 2 && slot <= 8; return slot >= 4 && slot <= 10;
return false; return false;
} }
@ -229,11 +254,11 @@ public class ContainerFactory extends Container
public boolean isOutputSlot(int slot) public boolean isOutputSlot(int slot)
{ {
if(tileEntity.tier == Tier.FactoryTier.BASIC) if(tileEntity.tier == Tier.FactoryTier.BASIC)
return slot >= 5 && slot <= 7; return slot >= 7 && slot <= 9;
if(tileEntity.tier == Tier.FactoryTier.ADVANCED) if(tileEntity.tier == Tier.FactoryTier.ADVANCED)
return slot >= 7 && slot <= 11; return slot >= 9 && slot <= 13;
if(tileEntity.tier == Tier.FactoryTier.ELITE) if(tileEntity.tier == Tier.FactoryTier.ELITE)
return slot >= 9 && slot <= 15; return slot >= 11 && slot <= 17;
return false; return false;
} }

View file

@ -0,0 +1,182 @@
package mekanism.common;
import mekanism.api.Object3D;
import mekanism.common.SynchronizedTankData.ValveData;
import net.minecraftforge.liquids.ILiquidTank;
import net.minecraftforge.liquids.LiquidStack;
public class DynamicLiquidTank implements ILiquidTank
{
public TileEntityDynamicTank dynamicTank;
public DynamicLiquidTank(TileEntityDynamicTank tileEntity)
{
dynamicTank = tileEntity;
}
@Override
public LiquidStack getLiquid()
{
return dynamicTank.structure != null ? dynamicTank.structure.liquidStored : null;
}
@Override
public int getCapacity()
{
return dynamicTank.structure != null ? dynamicTank.structure.volume*16000 : 0;
}
@Override
public int fill(LiquidStack resource, boolean doFill)
{
if(dynamicTank.structure != null && !dynamicTank.worldObj.isRemote)
{
if(resource == null || resource.itemID <= 0)
{
return 0;
}
if(dynamicTank.structure.liquidStored == null || dynamicTank.structure.liquidStored.itemID <= 0)
{
if(resource.amount <= getCapacity())
{
if(doFill)
{
dynamicTank.structure.liquidStored = resource.copy();
}
if(resource.amount > 0 && doFill)
{
updateValveData(true);
dynamicTank.sendPacketToRenderer();
updateValveData(false);
}
return resource.amount;
}
else {
if(doFill)
{
dynamicTank.structure.liquidStored = resource.copy();
dynamicTank.structure.liquidStored.amount = getCapacity();
}
if(getCapacity() > 0 && doFill)
{
updateValveData(true);
dynamicTank.sendPacketToRenderer();
updateValveData(false);
}
return getCapacity();
}
}
if(!dynamicTank.structure.liquidStored.isLiquidEqual(resource))
{
return 0;
}
int space = getCapacity() - dynamicTank.structure.liquidStored.amount;
if(resource.amount <= space)
{
if(doFill)
{
dynamicTank.structure.liquidStored.amount += resource.amount;
}
if(resource.amount > 0 && doFill)
{
updateValveData(true);
dynamicTank.sendPacketToRenderer();
updateValveData(false);
}
return resource.amount;
}
else {
if(doFill)
{
dynamicTank.structure.liquidStored.amount = getCapacity();
}
if(space > 0 && doFill)
{
updateValveData(true);
dynamicTank.sendPacketToRenderer();
updateValveData(false);
}
return space;
}
}
return 0;
}
public void updateValveData(boolean value)
{
if(dynamicTank.structure != null)
{
for(ValveData data : dynamicTank.structure.valves)
{
if(data.location.equals(Object3D.get(dynamicTank)))
{
data.serverLiquid = value;
}
}
}
}
@Override
public LiquidStack drain(int maxDrain, boolean doDrain)
{
if(dynamicTank.structure != null && !dynamicTank.worldObj.isRemote)
{
if(dynamicTank.structure.liquidStored == null || dynamicTank.structure.liquidStored.itemID <= 0)
{
return null;
}
if(dynamicTank.structure.liquidStored.amount <= 0)
{
return null;
}
int used = maxDrain;
if(dynamicTank.structure.liquidStored.amount < used)
{
used = dynamicTank.structure.liquidStored.amount;
}
if(doDrain)
{
dynamicTank.structure.liquidStored.amount -= used;
}
LiquidStack drained = new LiquidStack(dynamicTank.structure.liquidStored.itemID, used, dynamicTank.structure.liquidStored.itemMeta);
if(dynamicTank.structure.liquidStored.amount <= 0)
{
dynamicTank.structure.liquidStored = null;
}
if(drained.amount > 0 && doDrain)
{
dynamicTank.sendPacketToRenderer();
}
return drained;
}
return null;
}
@Override
public int getTankPressure()
{
return 0;
}
}

View file

@ -0,0 +1,10 @@
package mekanism.common;
import net.minecraft.item.ItemStack;
import net.minecraftforge.liquids.LiquidStack;
public class DynamicTankCache
{
public ItemStack[] inventory = new ItemStack[2];
public LiquidStack liquid;
}

View file

@ -12,6 +12,8 @@ import mekanism.api.IStrictEnergyAcceptor;
import mekanism.api.IUniversalCable; import mekanism.api.IUniversalCable;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.Event;
import buildcraft.api.power.IPowerReceptor; import buildcraft.api.power.IPowerReceptor;
import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.FMLCommonHandler;
@ -200,7 +202,7 @@ public class EnergyTransferProtocol
if(prevSending > energyToSend && FMLCommonHandler.instance().getEffectiveSide().isServer()) if(prevSending > energyToSend && FMLCommonHandler.instance().getEffectiveSide().isServer())
{ {
PacketHandler.sendEnergyTransferUpdate(pointer); MinecraftForge.EVENT_BUS.post(new EnergyTransferEvent(this));
} }
return energyToSend; return energyToSend;
@ -237,4 +239,14 @@ public class EnergyTransferProtocol
return totalNeeded; return totalNeeded;
} }
public static class EnergyTransferEvent extends Event
{
public final EnergyTransferProtocol transferProtocol;
public EnergyTransferEvent(EnergyTransferProtocol protocol)
{
transferProtocol = protocol;
}
}
} }

View file

@ -14,9 +14,11 @@ import net.minecraft.util.Icon;
* 4: Refined Glowstone * 4: Refined Glowstone
* 5: Steel Block * 5: Steel Block
* 6: Control Panel * 6: Control Panel
* 7: Teleporter * 7: Teleporter Frame
* 8: Teleporter Frame * 8: Steel Casing
* 9: Steel Casing * 9: Dynamic Tank
* 10: Dynamic Glass
* 11: Dynamic Valve
* @author AidanBrady * @author AidanBrady
* *
*/ */
@ -76,6 +78,15 @@ public class ItemBlockBasic extends ItemBlock
case 8: case 8:
name = "SteelCasing"; name = "SteelCasing";
break; break;
case 9:
name = "DynamicTank";
break;
case 10:
name = "DynamicGlass";
break;
case 11:
name = "DynamicValve";
break;
default: default:
name = "Unknown"; name = "Unknown";
break; break;

View file

@ -50,6 +50,7 @@ import net.minecraftforge.liquids.LiquidStack;
* 10: Energized Smelter * 10: Energized Smelter
* 11: Teleporter * 11: Teleporter
* 12: Electric Pump * 12: Electric Pump
* 13: Electric Chest
* @author AidanBrady * @author AidanBrady
* *
*/ */

View file

@ -1,12 +1,13 @@
package mekanism.common; package mekanism.common;
import universalelectricity.core.electricity.ElectricityPack;
import mekanism.api.EnumColor; import mekanism.api.EnumColor;
import mekanism.api.Object3D;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World; import net.minecraft.world.World;
import universalelectricity.core.electricity.ElectricityPack;
public class ItemPortableTeleporter extends ItemEnergized public class ItemPortableTeleporter extends ItemEnergized
{ {
@ -22,7 +23,7 @@ public class ItemPortableTeleporter extends ItemEnergized
return itemstack; return itemstack;
} }
public int calculateEnergyCost(Entity entity, Teleporter.Coords coords) public int calculateEnergyCost(Entity entity, Object3D coords)
{ {
if(coords == null) if(coords == null)
{ {

View file

@ -14,6 +14,8 @@ import mekanism.api.IGasStorage;
import mekanism.api.IMechanicalPipe; import mekanism.api.IMechanicalPipe;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.Event;
import net.minecraftforge.liquids.ILiquidTank; import net.minecraftforge.liquids.ILiquidTank;
import net.minecraftforge.liquids.ITankContainer; import net.minecraftforge.liquids.ITankContainer;
import net.minecraftforge.liquids.LiquidStack; import net.minecraftforge.liquids.LiquidStack;
@ -71,22 +73,25 @@ public class LiquidTransferProtocol
ILiquidTank[] tanks = acceptor.getTanks(side); ILiquidTank[] tanks = acceptor.getTanks(side);
boolean hasTank = false; boolean hasTank = false;
for(ILiquidTank tank : tanks) if(tanks != null)
{ {
if(tank != null) for(ILiquidTank tank : tanks)
{ {
if(tank.getLiquid() == null) if(tank != null)
{ {
hasTank = true; if(tank.getLiquid() == null)
break;
}
else {
if(tank.getLiquid().isLiquidEqual(liquidToSend))
{ {
if(tank.getCapacity()-tank.getLiquid().amount != 0) hasTank = true;
break;
}
else {
if(tank.getLiquid().isLiquidEqual(liquidToSend))
{ {
hasTank = true; if(tank.getCapacity()-tank.getLiquid().amount != 0)
break; {
hasTank = true;
break;
}
} }
} }
} }
@ -224,9 +229,22 @@ public class LiquidTransferProtocol
{ {
LiquidStack sendStack = liquidToSend.copy(); LiquidStack sendStack = liquidToSend.copy();
sendStack.amount = liquidSent; sendStack.amount = liquidSent;
PacketHandler.sendLiquidTransferUpdate(pointer, sendStack); MinecraftForge.EVENT_BUS.post(new LiquidTransferEvent(this, sendStack));
} }
return liquidSent; return liquidSent;
} }
public static class LiquidTransferEvent extends Event
{
public final LiquidTransferProtocol transferProtocol;
public final LiquidStack liquidSent;
public LiquidTransferEvent(LiquidTransferProtocol protocol, LiquidStack liquid)
{
transferProtocol = protocol;
liquidSent = liquid;
}
}
} }

View file

@ -5,8 +5,10 @@ import ic2.api.recipe.Recipes;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import java.util.logging.Logger; import java.util.logging.Logger;
import mekanism.api.EnumGas; import mekanism.api.EnumGas;
@ -14,8 +16,11 @@ import mekanism.api.GasTransferProtocol.GasTransferEvent;
import mekanism.api.InfuseObject; import mekanism.api.InfuseObject;
import mekanism.api.InfusionInput; import mekanism.api.InfusionInput;
import mekanism.api.InfusionType; import mekanism.api.InfusionType;
import mekanism.api.Object3D;
import mekanism.client.SoundHandler; import mekanism.client.SoundHandler;
import mekanism.common.EnergyTransferProtocol.EnergyTransferEvent;
import mekanism.common.IFactory.RecipeType; import mekanism.common.IFactory.RecipeType;
import mekanism.common.LiquidTransferProtocol.LiquidTransferEvent;
import mekanism.common.Tier.EnergyCubeTier; import mekanism.common.Tier.EnergyCubeTier;
import mekanism.common.Tier.FactoryTier; import mekanism.common.Tier.FactoryTier;
import net.minecraft.block.Block; import net.minecraft.block.Block;
@ -81,11 +86,14 @@ public class Mekanism
public static Version versionNumber = new Version(5, 5, 5); public static Version versionNumber = new Version(5, 5, 5);
/** Map of Teleporters */ /** Map of Teleporters */
public static Map<Teleporter.Code, ArrayList<Teleporter.Coords>> teleporters = new HashMap<Teleporter.Code, ArrayList<Teleporter.Coords>>(); public static Map<Teleporter.Code, ArrayList<Object3D>> teleporters = new HashMap<Teleporter.Code, ArrayList<Object3D>>();
/** Map of infuse objects */ /** Map of infuse objects */
public static Map<ItemStack, InfuseObject> infusions = new HashMap<ItemStack, InfuseObject>(); public static Map<ItemStack, InfuseObject> infusions = new HashMap<ItemStack, InfuseObject>();
public static Map<Integer, DynamicTankCache> dynamicInventories = new HashMap<Integer, DynamicTankCache>();
public static Map<Integer, HashSet<Object3D>> inventoryLocations = new HashMap<Integer, HashSet<Object3D>>();
/** Mekanism creative tab */ /** Mekanism creative tab */
public static CreativeTabMekanism tabMekanism = new CreativeTabMekanism(); public static CreativeTabMekanism tabMekanism = new CreativeTabMekanism();
@ -449,6 +457,9 @@ public class Mekanism
LanguageRegistry.instance().addStringLocalization("tile.BasicBlock.ControlPanel.name", "Control Panel"); LanguageRegistry.instance().addStringLocalization("tile.BasicBlock.ControlPanel.name", "Control Panel");
LanguageRegistry.instance().addStringLocalization("tile.BasicBlock.TeleporterFrame.name", "Teleporter Frame"); LanguageRegistry.instance().addStringLocalization("tile.BasicBlock.TeleporterFrame.name", "Teleporter Frame");
LanguageRegistry.instance().addStringLocalization("tile.BasicBlock.SteelCasing.name", "Steel Casing"); LanguageRegistry.instance().addStringLocalization("tile.BasicBlock.SteelCasing.name", "Steel Casing");
LanguageRegistry.instance().addStringLocalization("tile.BasicBlock.DynamicTank.name", "Dynamic Tank");
LanguageRegistry.instance().addStringLocalization("tile.BasicBlock.DynamicGlass.name", "Dynamic Glass");
LanguageRegistry.instance().addStringLocalization("tile.BasicBlock.DynamicValve.name", "Dynamic Valve");
//Localization for MachineBlock //Localization for MachineBlock
LanguageRegistry.instance().addStringLocalization("tile.MachineBlock.EnrichmentChamber.name", "Enrichment Chamber"); LanguageRegistry.instance().addStringLocalization("tile.MachineBlock.EnrichmentChamber.name", "Enrichment Chamber");
@ -990,6 +1001,8 @@ public class Mekanism
public void serverStopping(FMLServerStoppingEvent event) public void serverStopping(FMLServerStoppingEvent event)
{ {
teleporters.clear(); teleporters.clear();
dynamicInventories.clear();
inventoryLocations.clear();
} }
@PreInit @PreInit
@ -1072,4 +1085,16 @@ public class Mekanism
{ {
PacketHandler.sendGasTransferUpdate(event.transferProtocol.pointer, event.transferProtocol.transferType); PacketHandler.sendGasTransferUpdate(event.transferProtocol.pointer, event.transferProtocol.transferType);
} }
@ForgeSubscribe
public void onLiquidTransferred(LiquidTransferEvent event)
{
PacketHandler.sendLiquidTransferUpdate(event.transferProtocol.pointer, event.liquidSent);
}
@ForgeSubscribe
public void onEnergyTransferred(EnergyTransferEvent event)
{
PacketHandler.sendEnergyTransferUpdate(event.transferProtocol.pointer);
}
} }

View file

@ -8,12 +8,13 @@ import java.io.InputStreamReader;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet;
import java.util.Map; import java.util.Map;
import mekanism.api.Object3D;
import mekanism.api.EnumColor; import mekanism.api.EnumColor;
import mekanism.api.IConfigurable; import mekanism.api.IConfigurable;
import mekanism.api.InfuseObject; import mekanism.api.InfuseObject;
import mekanism.api.Object3D;
import mekanism.common.IFactory.RecipeType; import mekanism.common.IFactory.RecipeType;
import mekanism.common.Tier.EnergyCubeTier; import mekanism.common.Tier.EnergyCubeTier;
import mekanism.common.Tier.FactoryTier; import mekanism.common.Tier.FactoryTier;
@ -25,7 +26,6 @@ import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager; import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.network.packet.Packet3Chat; import net.minecraft.network.packet.Packet3Chat;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MathHelper;
import net.minecraft.world.IBlockAccess; import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.ForgeDirection;
@ -171,7 +171,7 @@ public final class MekanismUtils
/** /**
* Returns the closest teleporter between a selection of one or two. * Returns the closest teleporter between a selection of one or two.
*/ */
public static Teleporter.Coords getClosestCoords(Teleporter.Code teleCode, EntityPlayer player) public static Object3D getClosestCoords(Teleporter.Code teleCode, EntityPlayer player)
{ {
if(Mekanism.teleporters.get(teleCode).size() == 1) if(Mekanism.teleporters.get(teleCode).size() == 1)
{ {
@ -180,8 +180,8 @@ public final class MekanismUtils
else { else {
int dimensionId = player.worldObj.provider.dimensionId; int dimensionId = player.worldObj.provider.dimensionId;
Teleporter.Coords coords0 = Mekanism.teleporters.get(teleCode).get(0); Object3D coords0 = Mekanism.teleporters.get(teleCode).get(0);
Teleporter.Coords coords1 = Mekanism.teleporters.get(teleCode).get(1); Object3D coords1 = Mekanism.teleporters.get(teleCode).get(1);
int distance0 = (int)player.getDistance(coords0.xCoord, coords0.yCoord, coords0.zCoord); int distance0 = (int)player.getDistance(coords0.xCoord, coords0.yCoord, coords0.zCoord);
int distance1 = (int)player.getDistance(coords1.xCoord, coords1.yCoord, coords1.zCoord); int distance1 = (int)player.getDistance(coords1.xCoord, coords1.yCoord, coords1.zCoord);
@ -507,14 +507,15 @@ public final class MekanismUtils
* @param x - x coordinate * @param x - x coordinate
* @param y - y coordinate * @param y - y coordinate
* @param z - z coordinate * @param z - z coordinate
* @param orig - original block
*/ */
public static void makeBoundingBlock(World world, int x, int y, int z, int origX, int origY, int origZ) public static void makeBoundingBlock(World world, int x, int y, int z, Object3D orig)
{ {
world.setBlock(x, y, z, Mekanism.BoundingBlock.blockID); world.setBlock(x, y, z, Mekanism.BoundingBlock.blockID);
if(!world.isRemote) if(!world.isRemote)
{ {
((TileEntityBoundingBlock)world.getBlockTileEntity(x, y, z)).setMainLocation(origX, origY, origZ); ((TileEntityBoundingBlock)world.getBlockTileEntity(x, y, z)).setMainLocation(orig.xCoord, orig.yCoord, orig.zCoord);
} }
} }
@ -709,4 +710,99 @@ public final class MekanismUtils
player.openContainer.windowId = id; player.openContainer.windowId = id;
player.openContainer.addCraftingToCrafters(player); player.openContainer.addCraftingToCrafters(player);
} }
/**
* Grabs an inventory from the world's caches, and removes all the world's references to it.
* @param world - world the cache is stored in
* @param id - inventory ID to pull
* @return
*/
public static DynamicTankCache pullInventory(World world, int id)
{
DynamicTankCache toReturn = Mekanism.dynamicInventories.get(id);
Mekanism.dynamicInventories.remove(id);
for(Object3D obj : Mekanism.inventoryLocations.get(id))
{
TileEntityDynamicTank tileEntity = (TileEntityDynamicTank)obj.getTileEntity(world);
if(tileEntity != null)
{
tileEntity.cachedLiquid = null;
tileEntity.inventory = new ItemStack[2];
tileEntity.inventoryID = -1;
}
}
Mekanism.inventoryLocations.remove(id);
return toReturn;
}
/**
* Updates a dynamic tank cache with the defined inventory ID with the parameterized values.
* @param inventoryID
* @param liquid
* @param inventory
* @param tileEntity
*/
public static void updateCache(int inventoryID, LiquidStack liquid, ItemStack[] inventory, TileEntityDynamicTank tileEntity)
{
if(!Mekanism.dynamicInventories.containsKey(inventoryID))
{
DynamicTankCache cache = new DynamicTankCache();
cache.inventory = inventory;
cache.liquid = liquid;
Mekanism.dynamicInventories.put(inventoryID, cache);
HashSet<Object3D> set = new HashSet<Object3D>();
set.add(Object3D.get(tileEntity));
Mekanism.inventoryLocations.put(inventoryID, set);
return;
}
Mekanism.dynamicInventories.get(inventoryID).inventory = inventory;
Mekanism.dynamicInventories.get(inventoryID).liquid = liquid;
if(!Mekanism.inventoryLocations.containsKey(inventoryID))
{
HashSet<Object3D> set = new HashSet<Object3D>();
set.add(Object3D.get(tileEntity));
Mekanism.inventoryLocations.put(inventoryID, set);
return;
}
if(!Mekanism.inventoryLocations.get(inventoryID).contains(Object3D.get(tileEntity)))
{
Mekanism.inventoryLocations.get(inventoryID).add(Object3D.get(tileEntity));
}
}
/**
* Grabs a unique inventory ID for a dynamic tank.
* @return unique inventory ID
*/
public static int getUniqueInventoryID()
{
int id = 0;
while(true)
{
for(Integer i : Mekanism.dynamicInventories.keySet())
{
if(id == i)
{
id++;
continue;
}
}
return id;
}
}
} }

View file

@ -9,6 +9,7 @@ import java.util.Random;
import mekanism.api.EnumGas; import mekanism.api.EnumGas;
import mekanism.api.GasTransferProtocol; import mekanism.api.GasTransferProtocol;
import mekanism.api.IEnergizedItem; import mekanism.api.IEnergizedItem;
import mekanism.api.Object3D;
import mekanism.generators.common.TileEntityElectrolyticSeparator; import mekanism.generators.common.TileEntityElectrolyticSeparator;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.EntityPlayerMP;
@ -196,7 +197,7 @@ public class PacketHandler implements IPacketHandler
if(item.getStatus(itemstack) == 1) if(item.getStatus(itemstack) == 1)
{ {
Teleporter.Coords coords = MekanismUtils.getClosestCoords(new Teleporter.Code(item.getDigit(itemstack, 0), item.getDigit(itemstack, 1), item.getDigit(itemstack, 2), item.getDigit(itemstack, 3)), entityPlayerMP); Object3D coords = MekanismUtils.getClosestCoords(new Teleporter.Code(item.getDigit(itemstack, 0), item.getDigit(itemstack, 1), item.getDigit(itemstack, 2), item.getDigit(itemstack, 3)), entityPlayerMP);
item.onProvide(new ElectricityPack(item.calculateEnergyCost(entityPlayerMP, coords)/120, 120), itemstack); item.onProvide(new ElectricityPack(item.calculateEnergyCost(entityPlayerMP, coords)/120, 120), itemstack);

View file

@ -0,0 +1,99 @@
package mekanism.common;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.liquids.LiquidStack;
import mekanism.api.Object3D;
public class SynchronizedTankData
{
public Set<Object3D> locations = new HashSet<Object3D>();
public int volLength;
public int volWidth;
public int volHeight;
public int volume;
public LiquidStack liquidStored;
public ItemStack[] inventory = new ItemStack[2];
public boolean didTick;
public boolean hasRenderer;
public Object3D renderLocation;
public Set<ValveData> valves = new HashSet<ValveData>();
@Override
public int hashCode()
{
int code = 1;
code = 31 * locations.hashCode();
code = 31 * volLength;
code = 31 * volWidth;
code = 31 * volHeight;
code = 31 * volume;
return code;
}
@Override
public boolean equals(Object obj)
{
if(!(obj instanceof SynchronizedTankData))
{
return false;
}
SynchronizedTankData data = (SynchronizedTankData)obj;
if(!data.locations.equals(locations))
{
return false;
}
if(data.volLength != volLength || data.volWidth != volWidth || data.volHeight != volHeight)
{
return false;
}
if(data.volume != volume)
{
return false;
}
return true;
}
public static class ValveData
{
public ForgeDirection side;
public Object3D location;
public boolean serverLiquid;
@Override
public int hashCode()
{
int code = 1;
code = 31 * code + side.ordinal();
code = 31 * code + location.hashCode();
return code;
}
@Override
public boolean equals(Object obj)
{
return obj instanceof ValveData && ((ValveData)obj).side == side && ((ValveData)obj).location.equals(location);
}
}
}

View file

@ -0,0 +1,455 @@
package mekanism.common;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import mekanism.api.Object3D;
import mekanism.common.SynchronizedTankData.ValveData;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
public class TankUpdateProtocol
{
/** The dynamic tank nodes that have already been iterated over. */
public Set<TileEntityDynamicTank> iteratedNodes = new HashSet<TileEntityDynamicTank>();
/** The structures found, all connected by some nodes to the pointer. */
public List<SynchronizedTankData> structuresFound = new ArrayList<SynchronizedTankData>();
/** The original block the calculation is getting run from. */
public TileEntity pointer;
/** If the pointer is not a part of any actual dynamic tank. */
public boolean pointerNotPartOf;
public TankUpdateProtocol(TileEntity tileEntity)
{
pointer = tileEntity;
}
/**
* Recursively loops through each node connected to the given TileEntity.
* @param tile - the TileEntity to loop over
*/
public void loopThrough(TileEntity tile)
{
World worldObj = tile.worldObj;
int origX = tile.xCoord, origY = tile.yCoord, origZ = tile.zCoord;
boolean isCorner = true;
boolean isHollowPrism = true;
Set<Object3D> locations = new HashSet<Object3D>();
int xmin = 0, xmax = 0, ymin = 0, ymax = 0, zmin = 0, zmax = 0;
int x = 0, y = 0, z = 0;
int volume = 0;
if((isViableNode(origX + 1, origY, origZ) && isViableNode(origX - 1, origY, origZ)) ||
(isViableNode(origX, origY + 1, origZ) && isViableNode(origX, origY - 1, origZ)) ||
(isViableNode(origX, origY, origZ + 1) && isViableNode(origX, origY, origZ - 1)))
{
isCorner = false;
}
if(isCorner)
{
if(isViableNode(origX+1, origY, origZ))
{
xmin = 0;
while(isViableNode(origX+x+1, origY, origZ))
{
x++;
}
xmax = x;
}
else {
xmax = 0;
while(isViableNode(origX+x-1, origY, origZ))
{
x--;
}
xmin = x;
}
if(isViableNode(origX, origY+1, origZ))
{
ymin = 0;
while(isViableNode(origX, origY+y+1, origZ))
{
y++;
}
ymax = y;
}
else {
ymax = 0;
while(isViableNode(origX, origY+y-1 ,origZ))
{
y--;
}
ymin = y;
}
if(isViableNode(origX, origY, origZ+1))
{
zmin = 0;
while(isViableNode(origX, origY, origZ+z+1))
{
z++;
}
zmax = z;
}
else {
zmax = 0;
while(isViableNode(origX, origY, origZ+z-1))
{
z--;
}
zmin = z;
}
for(x = xmin; x <= xmax; x++)
{
for(y = ymin; y <= ymax; y++)
{
for(z = zmin; z <= zmax; z++)
{
if(x == xmin || x == xmax || y == ymin || y == ymax || z == zmin || z == zmax)
{
if(!isViableNode(origX+x, origY+y, origZ+z))
{
isHollowPrism = false;
break;
}
else if(isFrame(new Object3D(origX+x, origY+y, origZ+z), origX+xmin, origX+xmax, origY+ymin, origY+ymax, origZ+zmin, origZ+zmax) && !isValidFrame(origX+x, origY+y, origZ+z))
{
isHollowPrism = false;
break;
}
else {
locations.add(new Object3D(origX+x, origY+y, origZ+z));
}
}
else {
if(!isAir(origX+x, origY+y, origZ+z))
{
isHollowPrism = false;
break;
}
volume++;
}
}
if(!isHollowPrism)
{
break;
}
}
if(!isHollowPrism)
{
break;
}
}
}
if(isHollowPrism && isCorner && volume > 0 && volume <= 5832 && locations.size() >= 9)
{
SynchronizedTankData structure = new SynchronizedTankData();
structure.locations = locations;
structure.volLength = Math.abs(xmax-xmin)+1;
structure.volHeight = Math.abs(ymax-ymin)+1;
structure.volWidth = Math.abs(zmax-zmin)+1;
structure.volume = volume;
structure.renderLocation = new Object3D(origX+1, origY+1, origZ+1);
for(Object3D obj : structure.locations)
{
if(obj.getTileEntity(pointer.worldObj) instanceof TileEntityDynamicValve)
{
ValveData data = new ValveData();
data.location = obj;
data.side = getSide(obj, origX+xmin, origX+xmax, origY+ymin, origY+ymax, origZ+zmin, origZ+zmax);
structure.valves.add(data);
}
}
if(!structuresFound.contains(structure))
{
if(structure.locations.contains(Object3D.get(pointer)) && isCorrectCorner(new Object3D(origX, origY, origZ), origX+xmin, origY+ymin, origZ+zmin))
{
if(!entitiesInside(structure))
{
structuresFound.add(structure);
}
}
else {
pointerNotPartOf = true;
}
}
}
iteratedNodes.add((TileEntityDynamicTank)tile);
for(ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
{
TileEntity tileEntity = Object3D.get(tile).getFromSide(side).getTileEntity(tile.worldObj);
if(tileEntity instanceof TileEntityDynamicTank)
{
if(!iteratedNodes.contains(tileEntity))
{
loopThrough(tileEntity);
}
}
}
}
public ForgeDirection getSide(Object3D obj, int xmin, int xmax, int ymin, int ymax, int zmin, int zmax)
{
if(obj.xCoord == xmin)
{
return ForgeDirection.WEST;
}
else if(obj.xCoord == xmax)
{
return ForgeDirection.EAST;
}
else if(obj.yCoord == ymin)
{
return ForgeDirection.DOWN;
}
else if(obj.yCoord == ymax)
{
return ForgeDirection.UP;
}
else if(obj.zCoord == zmin)
{
return ForgeDirection.NORTH;
}
else if(obj.zCoord == zmax)
{
return ForgeDirection.SOUTH;
}
return ForgeDirection.UNKNOWN;
}
/**
* Checks whether or not there are entities inside this dynamic tank.
*/
public boolean entitiesInside(SynchronizedTankData structure)
{
int x = structure.renderLocation.xCoord;
int y = structure.renderLocation.yCoord;
int z = structure.renderLocation.zCoord;
AxisAlignedBB boundingBox = AxisAlignedBB.getBoundingBox(x, y, z, x+structure.volLength, y+structure.volHeight, z+structure.volWidth);
for(Object obj : pointer.worldObj.getEntitiesWithinAABB(Entity.class, boundingBox))
{
if(obj instanceof Entity)
{
Entity entity = (Entity)obj;
if(entity instanceof EntityPlayer)
{
return true;
}
else {
pointer.worldObj.removeEntity(entity);
}
}
}
return false;
}
/**
* Whether or not the block at the specified location is an air block.
* @param x - x coordinate
* @param y - y coordinate
* @param z - z coordinate
* @return
*/
private boolean isAir(int x, int y, int z)
{
return pointer.worldObj.getBlockId(x, y, z) == 0;
}
/**
* Whether or not the block at the specified location is a viable node for a dynamic tank.
* @param x - x coordinate
* @param y - y coordinate
* @param z - z coordinate
* @return
*/
private boolean isViableNode(int x, int y, int z)
{
TileEntity tileEntity = pointer.worldObj.getBlockTileEntity(x, y, z);
if(tileEntity != null)
{
if(tileEntity instanceof TileEntityDynamicTank)
{
return true;
}
}
return false;
}
/**
* If the block at the specified location is on the minimum of all angles of this dynamic tank, and the one to use for the
* actual calculation.
* @param obj - location to check
* @param xmin - minimum x value
* @param ymin - minimum y value
* @param zmin - minimum z value
* @return
*/
private boolean isCorrectCorner(Object3D obj, int xmin, int ymin, int zmin)
{
if(obj.xCoord == xmin && obj.yCoord == ymin && obj.zCoord == zmin)
{
return true;
}
return false;
}
/**
* Whether or not the block at the specified location is considered a frame on the dynamic tank.
* @param obj - location to check
* @param xmin - minimum x value
* @param xmax - maximum x value
* @param ymin - minimum y value
* @param ymax - maximum y value
* @param zmin - minimum z value
* @param zmax - maximum z value
* @return
*/
private boolean isFrame(Object3D obj, int xmin, int xmax, int ymin, int ymax, int zmin, int zmax)
{
if(obj.xCoord == xmin && obj.yCoord == ymin)
return true;
if(obj.xCoord == xmax && obj.yCoord == ymin)
return true;
if(obj.xCoord == xmin && obj.yCoord == ymax)
return true;
if(obj.xCoord == xmax && obj.yCoord == ymax)
return true;
if(obj.xCoord == xmin && obj.zCoord == zmin)
return true;
if(obj.xCoord == xmax && obj.zCoord == zmin)
return true;
if(obj.xCoord == xmin && obj.zCoord == zmax)
return true;
if(obj.xCoord == xmax && obj.zCoord == zmax)
return true;
if(obj.yCoord == ymin && obj.zCoord == zmin)
return true;
if(obj.yCoord == ymax && obj.zCoord == zmin)
return true;
if(obj.yCoord == ymin && obj.zCoord == zmax)
return true;
if(obj.yCoord == ymax && obj.zCoord == zmax)
return true;
return false;
}
/**
* Whether or not the block at the specified location serves as a frame for a dynamic tank.
* @param x - x coordinate
* @param y - y coordinate
* @param z - z coordinate
* @return
*/
private boolean isValidFrame(int x, int y, int z)
{
return pointer.worldObj.getBlockId(x, y, z) == Mekanism.basicBlockID && pointer.worldObj.getBlockMetadata(x, y, z) == 9;
}
/**
* Runs the protocol and updates all tanks that make a part of the dynamic tank.
*/
public void updateTanks()
{
loopThrough(pointer);
if(structuresFound.size() == 1)
{
SynchronizedTankData structureFound = structuresFound.get(0);
int idFound = -1;
for(Object3D obj : structureFound.locations)
{
TileEntityDynamicTank tileEntity = (TileEntityDynamicTank)obj.getTileEntity(pointer.worldObj);
if(tileEntity.inventoryID != -1)
{
idFound = tileEntity.inventoryID;
break;
}
}
DynamicTankCache cache = new DynamicTankCache();
if(idFound != -1)
{
if(Mekanism.dynamicInventories.get(idFound) != null)
{
cache = MekanismUtils.pullInventory(pointer.worldObj, idFound);
}
}
else {
idFound = MekanismUtils.getUniqueInventoryID();
}
structureFound.liquidStored = cache.liquid;
structureFound.inventory = cache.inventory;
for(Object3D obj : structureFound.locations)
{
TileEntityDynamicTank tileEntity = (TileEntityDynamicTank)obj.getTileEntity(pointer.worldObj);
tileEntity.inventoryID = idFound;
tileEntity.structure = structureFound;
tileEntity.cachedLiquid = cache.liquid;
tileEntity.inventory = cache.inventory;
}
}
else if(!pointerNotPartOf)
{
for(TileEntity tileEntity : iteratedNodes)
{
((TileEntityDynamicTank)tileEntity).structure = null;
}
}
}
}

View file

@ -2,54 +2,6 @@ package mekanism.common;
public class Teleporter public class Teleporter
{ {
/**
* Coords -- a set of coordinates as well as a dimension ID that is used by teleporters.
* @author aidancbrady
*
*/
public static final class Coords
{
public int xCoord;
public int yCoord;
public int zCoord;
public int dimensionId;
public Coords(int x, int y, int z, int id)
{
xCoord = x;
yCoord = y;
zCoord = z;
dimensionId = id;
}
/**
* Gets the Coords from a tile entity.
* @param tileEntity
* @return coords
*/
public static Coords get(TileEntityTeleporter tileEntity)
{
return new Coords(tileEntity.xCoord, tileEntity.yCoord+1, tileEntity.zCoord, tileEntity.worldObj.provider.dimensionId);
}
@Override
public int hashCode()
{
int code = 1;
code = 31 * code + xCoord;
code = 31 * code + yCoord;
code = 31 * code + zCoord;
code = 31 * code + dimensionId;
return code;
}
@Override
public boolean equals(Object coords)
{
return coords instanceof Coords && ((Coords)coords).xCoord == xCoord && ((Coords)coords).yCoord == yCoord && ((Coords)coords).zCoord == zCoord && ((Coords)coords).dimensionId == dimensionId;
}
}
/** /**
* Code -- a way for teleporters to manage frequencies. * Code -- a way for teleporters to manage frequencies.
* @author aidancbrady * @author aidancbrady

View file

@ -93,22 +93,22 @@ public abstract class TileEntityContainerBlock extends TileEntityBasicBlock impl
@Override @Override
public ItemStack decrStackSize(int slotID, int amount) public ItemStack decrStackSize(int slotID, int amount)
{ {
if(inventory[slotID] != null) if(getStackInSlot(slotID) != null)
{ {
ItemStack tempStack; ItemStack tempStack;
if(inventory[slotID].stackSize <= amount) if(getStackInSlot(slotID).stackSize <= amount)
{ {
tempStack = inventory[slotID]; tempStack = getStackInSlot(slotID);
inventory[slotID] = null; setInventorySlotContents(slotID, null);
return tempStack; return tempStack;
} }
else { else {
tempStack = inventory[slotID].splitStack(amount); tempStack = getStackInSlot(slotID).splitStack(amount);
if(inventory[slotID].stackSize == 0) if(getStackInSlot(slotID).stackSize == 0)
{ {
inventory[slotID] = null; setInventorySlotContents(slotID, null);
} }
return tempStack; return tempStack;
@ -122,10 +122,10 @@ public abstract class TileEntityContainerBlock extends TileEntityBasicBlock impl
@Override @Override
public ItemStack getStackInSlotOnClosing(int slotID) public ItemStack getStackInSlotOnClosing(int slotID)
{ {
if(inventory[slotID] != null) if(getStackInSlot(slotID) != null)
{ {
ItemStack tempStack = inventory[slotID]; ItemStack tempStack = getStackInSlot(slotID);
inventory[slotID] = null; setInventorySlotContents(slotID, null);
return tempStack; return tempStack;
} }
else { else {

View file

@ -0,0 +1,453 @@
package mekanism.common;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import mekanism.api.Object3D;
import mekanism.common.SynchronizedTankData.ValveData;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.AxisAlignedBB;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.liquids.LiquidContainerRegistry;
import net.minecraftforge.liquids.LiquidStack;
import com.google.common.io.ByteArrayDataInput;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class TileEntityDynamicTank extends TileEntityContainerBlock
{
public Set<EntityPlayer> playersUsing = new HashSet<EntityPlayer>();
/** Unique inventory ID for the dynamic tank, serves as a way to retrieve cached inventories. */
public int inventoryID = -1;
/** The tank data for this structure. */
public SynchronizedTankData structure;
public boolean prevStructure;
public boolean clientHasStructure;
public LiquidStack cachedLiquid;
public Map<ValveData, Integer> valveViewing = new HashMap<ValveData, Integer>();
public int clientCapacity;
public boolean isRendering;
public TileEntityDynamicTank()
{
this("Dynamic Tank");
}
public TileEntityDynamicTank(String name)
{
super(name);
inventory = new ItemStack[2];
}
public void update()
{
if(!worldObj.isRemote && canUpdateData())
{
new TankUpdateProtocol(this).updateTanks();
if(structure != null)
{
structure.didTick = true;
}
}
}
@Override
public void onUpdate()
{
if(worldObj.isRemote)
{
if(structure == null)
{
structure = new SynchronizedTankData();
}
if(structure != null && clientHasStructure && isRendering)
{
for(ValveData data : valveViewing.keySet())
{
if(valveViewing.get(data) > 0)
{
valveViewing.put(data, valveViewing.get(data)-1);
}
}
}
if(!clientHasStructure || !isRendering)
{
valveViewing.clear();
}
}
if(playersUsing.size() > 0 && ((worldObj.isRemote && !clientHasStructure) || (!worldObj.isRemote && structure == null)))
{
for(EntityPlayer player : playersUsing)
{
player.closeScreen();
}
}
if(!worldObj.isRemote)
{
if(structure == null)
{
isRendering = false;
}
if(inventoryID != -1 && structure == null)
{
MekanismUtils.updateCache(inventoryID, cachedLiquid, inventory, this);
}
if(structure == null && packetTick == 5)
{
update();
}
if(prevStructure != (structure != null))
{
PacketHandler.sendTileEntityPacketToClients(this, 0, getNetworkedData(new ArrayList()));
}
prevStructure = structure != null;
if(structure != null)
{
structure.didTick = false;
if(!structure.hasRenderer)
{
structure.hasRenderer = true;
isRendering = true;
PacketHandler.sendTileEntityPacketToClients(this, 0, getNetworkedData(new ArrayList()));
}
if(inventoryID != -1)
{
MekanismUtils.updateCache(inventoryID, structure.liquidStored, structure.inventory, this);
cachedLiquid = structure.liquidStored;
inventory = structure.inventory;
}
manageInventory();
}
}
}
public void manageInventory()
{
int max = structure.volume*16000;
if(structure.inventory[0] != null)
{
if(LiquidContainerRegistry.isEmptyContainer(structure.inventory[0]))
{
if(structure.liquidStored != null && structure.liquidStored.amount >= LiquidContainerRegistry.BUCKET_VOLUME)
{
ItemStack filled = LiquidContainerRegistry.fillLiquidContainer(structure.liquidStored, structure.inventory[0]);
if(filled != null)
{
if(structure.inventory[1] == null || (structure.inventory[1].isItemEqual(filled) && structure.inventory[1].stackSize+1 <= filled.getMaxStackSize()))
{
structure.inventory[0].stackSize--;
if(structure.inventory[0].stackSize <= 0)
{
structure.inventory[0] = null;
}
if(structure.inventory[1] == null)
{
structure.inventory[1] = filled;
}
else {
structure.inventory[1].stackSize++;
}
structure.liquidStored.amount -= LiquidContainerRegistry.getLiquidForFilledItem(filled).amount;
if(structure.liquidStored.amount == 0)
{
structure.liquidStored = null;
}
PacketHandler.sendTileEntityPacketToClients(this, 50, getNetworkedData(new ArrayList()));
}
}
}
}
else if(LiquidContainerRegistry.isFilledContainer(structure.inventory[0]))
{
LiquidStack itemLiquid = LiquidContainerRegistry.getLiquidForFilledItem(structure.inventory[0]);
if((structure.liquidStored == null && itemLiquid.amount <= max) || structure.liquidStored.amount+itemLiquid.amount <= max)
{
if(structure.liquidStored != null && !structure.liquidStored.isLiquidEqual(itemLiquid))
{
return;
}
ItemStack bucket = LiquidContainerRegistry.isBucket(structure.inventory[0]) ? new ItemStack(Item.bucketEmpty) : null;
boolean filled = false;
if(bucket != null)
{
if(structure.inventory[1] == null || (structure.inventory[1].isItemEqual(bucket) && structure.inventory[1].stackSize+1 <= bucket.getMaxStackSize()))
{
structure.inventory[0] = null;
if(structure.inventory[1] == null)
{
structure.inventory[1] = bucket;
}
else {
structure.inventory[1].stackSize++;
}
filled = true;
}
}
else {
structure.inventory[0].stackSize--;
if(structure.inventory[0].stackSize == 0)
{
structure.inventory[0] = null;
}
filled = true;
}
if(filled)
{
if(structure.liquidStored == null)
{
structure.liquidStored = itemLiquid.copy();
}
else {
structure.liquidStored.amount += itemLiquid.amount;
}
}
PacketHandler.sendTileEntityPacketToClients(this, 50, getNetworkedData(new ArrayList()));
}
}
}
}
public boolean canUpdateData()
{
return structure == null || !structure.didTick;
}
@Override
public ArrayList getNetworkedData(ArrayList data)
{
super.getNetworkedData(data);
data.add(isRendering);
data.add(structure != null);
if(structure != null)
{
data.add(structure.volHeight);
data.add(structure.volWidth);
data.add(structure.volLength);
data.add(structure.renderLocation.xCoord);
data.add(structure.renderLocation.yCoord);
data.add(structure.renderLocation.zCoord);
}
data.add(structure != null ? structure.volume*16000 : 0);
if(structure != null && structure.liquidStored != null)
{
data.add(1);
data.add(structure.liquidStored.itemID);
data.add(structure.liquidStored.amount);
data.add(structure.liquidStored.itemMeta);
}
else {
data.add(0);
}
if(structure != null)
{
data.add(structure.valves.size());
for(ValveData valveData : structure.valves)
{
data.add(valveData.location.xCoord);
data.add(valveData.location.yCoord);
data.add(valveData.location.zCoord);
data.add(valveData.side.ordinal());
data.add(valveData.serverLiquid);
}
}
return data;
}
@Override
public void handlePacketData(ByteArrayDataInput dataStream)
{
super.handlePacketData(dataStream);
if(structure == null)
{
structure = new SynchronizedTankData();
}
isRendering = dataStream.readBoolean();
clientHasStructure = dataStream.readBoolean();
if(clientHasStructure)
{
structure.volHeight = dataStream.readInt();
structure.volWidth = dataStream.readInt();
structure.volLength = dataStream.readInt();
structure.renderLocation = new Object3D(dataStream.readInt(), dataStream.readInt(), dataStream.readInt());
}
clientCapacity = dataStream.readInt();
if(dataStream.readInt() == 1)
{
structure.liquidStored = new LiquidStack(dataStream.readInt(), dataStream.readInt(), dataStream.readInt());
}
else {
structure.liquidStored = null;
}
if(clientHasStructure)
{
int size = dataStream.readInt();
for(int i = 0; i < size; i++)
{
ValveData data = new ValveData();
data.location = new Object3D(dataStream.readInt(), dataStream.readInt(), dataStream.readInt());
data.side = ForgeDirection.getOrientation(dataStream.readInt());
int viewingTicks = 0;
if(dataStream.readBoolean())
{
viewingTicks = 30;
}
if(viewingTicks == 0)
{
if(valveViewing.containsKey(data) && valveViewing.get(data) > 0)
{
continue;
}
}
valveViewing.put(data, viewingTicks);
}
}
}
public void sendPacketToRenderer()
{
if(structure != null)
{
for(Object3D obj : structure.locations)
{
TileEntityDynamicTank tileEntity = (TileEntityDynamicTank)obj.getTileEntity(worldObj);
if(tileEntity != null && tileEntity.isRendering)
{
PacketHandler.sendTileEntityPacketToClients(tileEntity, 50, tileEntity.getNetworkedData(new ArrayList()));
}
}
}
}
public int getScaledLiquidLevel(int i)
{
if(clientCapacity == 0 || structure.liquidStored == null)
{
return 0;
}
return structure.liquidStored.amount*i / clientCapacity;
}
@Override
public ItemStack getStackInSlot(int slotID)
{
return structure != null ? structure.inventory[slotID] : null;
}
@Override
public void setInventorySlotContents(int slotID, ItemStack itemstack)
{
if(structure != null)
{
structure.inventory[slotID] = itemstack;
if(itemstack != null && itemstack.stackSize > getInventoryStackLimit())
{
itemstack.stackSize = getInventoryStackLimit();
}
}
}
@Override
public void readFromNBT(NBTTagCompound nbtTags)
{
super.readFromNBT(nbtTags);
inventoryID = nbtTags.getInteger("inventoryID");
if(inventoryID != -1)
{
if(nbtTags.hasKey("cachedLiquid"))
{
cachedLiquid = LiquidStack.loadLiquidStackFromNBT(nbtTags.getCompoundTag("cachedLiquid"));
}
}
}
@Override
public void writeToNBT(NBTTagCompound nbtTags)
{
super.writeToNBT(nbtTags);
nbtTags.setInteger("inventoryID", inventoryID);
if(cachedLiquid != null)
{
nbtTags.setTag("cachedLiquid", cachedLiquid.writeToNBT(new NBTTagCompound()));
}
}
@Override
@SideOnly(Side.CLIENT)
public AxisAlignedBB getRenderBoundingBox()
{
return INFINITE_EXTENT_AABB;
}
}

View file

@ -0,0 +1,73 @@
package mekanism.common;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.liquids.ILiquidTank;
import net.minecraftforge.liquids.ITankContainer;
import net.minecraftforge.liquids.LiquidStack;
public class TileEntityDynamicValve extends TileEntityDynamicTank implements ITankContainer
{
public DynamicLiquidTank liquidTank;
public TileEntityDynamicValve()
{
super("Dynamic Valve");
liquidTank = new DynamicLiquidTank(this);
}
@Override
public int fill(ForgeDirection from, LiquidStack resource, boolean doFill)
{
return fill(0, resource, doFill);
}
@Override
public int fill(int tankIndex, LiquidStack resource, boolean doFill)
{
if(tankIndex == 0)
{
return liquidTank.fill(resource, doFill);
}
return 0;
}
@Override
public LiquidStack drain(ForgeDirection from, int maxDrain, boolean doDrain)
{
return drain(0, maxDrain, doDrain);
}
@Override
public LiquidStack drain(int tankIndex, int maxDrain, boolean doDrain)
{
if(tankIndex == 0)
{
return liquidTank.drain(maxDrain, doDrain);
}
return null;
}
@Override
public ILiquidTank[] getTanks(ForgeDirection direction)
{
if((!worldObj.isRemote && structure != null) || (worldObj.isRemote && clientHasStructure))
{
return new ILiquidTank[] {liquidTank};
}
return null;
}
@Override
public ILiquidTank getTank(ForgeDirection direction, LiquidStack type)
{
if((!worldObj.isRemote && structure != null) || (worldObj.isRemote && clientHasStructure))
{
return liquidTank;
}
return null;
}
}

View file

@ -43,11 +43,6 @@ public abstract class TileEntityElectricMachine extends TileEntityBasicMachine
{ {
super.onUpdate(); super.onUpdate();
if(worldObj.isRemote)
{
System.out.println(electricityStored);
}
if(!worldObj.isRemote) if(!worldObj.isRemote)
{ {
ChargeUtils.discharge(1, this); ChargeUtils.discharge(1, this);

View file

@ -12,6 +12,7 @@ import mekanism.api.IStrictEnergyAcceptor;
import mekanism.api.IUpgradeManagement; import mekanism.api.IUpgradeManagement;
import mekanism.api.SideData; import mekanism.api.SideData;
import mekanism.client.IHasSound; import mekanism.client.IHasSound;
import mekanism.common.BlockMachine.MachineType;
import mekanism.common.IFactory.RecipeType; import mekanism.common.IFactory.RecipeType;
import mekanism.common.Tier.FactoryTier; import mekanism.common.Tier.FactoryTier;
import net.minecraft.item.Item; import net.minecraft.item.Item;
@ -63,6 +64,12 @@ public class TileEntityFactory extends TileEntityElectricBlock implements IEnerg
/** How many upgrade ticks have progressed. */ /** How many upgrade ticks have progressed. */
public int upgradeTicks; public int upgradeTicks;
/** How long it takes this factory to switch recipe types. */
public int RECIPE_TICKS_REQUIRED = 40;
/** How many recipe ticks have progressed. */
public int recipeTicks;
/** This machine's previous active state, used for calculating packets. */ /** This machine's previous active state, used for calculating packets. */
public boolean prevActive; public boolean prevActive;
@ -89,7 +96,7 @@ public class TileEntityFactory extends TileEntityElectricBlock implements IEnerg
{ {
super(type.name + " Factory", type.processes*2000); super(type.name + " Factory", type.processes*2000);
tier = type; tier = type;
inventory = new ItemStack[2+type.processes*2]; inventory = new ItemStack[4+type.processes*2];
progress = new int[type.processes]; progress = new int[type.processes];
isActive = false; isActive = false;
} }
@ -156,6 +163,64 @@ public class TileEntityFactory extends TileEntityElectricBlock implements IEnerg
upgradeTicks = 0; upgradeTicks = 0;
} }
if(inventory[2] != null && inventory[3] == null)
{
if(inventory[2].isItemEqual(new ItemStack(Mekanism.MachineBlock, 1, MachineType.ENERGIZED_SMELTER.meta)) && recipeType != 0)
{
if(recipeTicks < RECIPE_TICKS_REQUIRED)
{
recipeTicks++;
}
else if(recipeTicks == RECIPE_TICKS_REQUIRED)
{
recipeTicks = 0;
inventory[2] = null;
inventory[3] = getMachineStack();
recipeType = 0;
}
}
else if(inventory[2].isItemEqual(new ItemStack(Mekanism.MachineBlock, 1, MachineType.ENRICHMENT_CHAMBER.meta)) && recipeType != 1)
{
if(recipeTicks < RECIPE_TICKS_REQUIRED)
{
recipeTicks++;
}
else if(recipeTicks == RECIPE_TICKS_REQUIRED)
{
recipeTicks = 0;
inventory[2] = null;
inventory[3] = getMachineStack();
recipeType = 1;
}
}
else if(inventory[2].isItemEqual(new ItemStack(Mekanism.MachineBlock, 1, MachineType.CRUSHER.meta)) && recipeType != 2)
{
if(recipeTicks < RECIPE_TICKS_REQUIRED)
{
recipeTicks++;
}
else if(recipeTicks == RECIPE_TICKS_REQUIRED)
{
recipeTicks = 0;
inventory[2] = null;
inventory[3] = getMachineStack();
recipeType = 2;
}
}
else {
recipeTicks = 0;
}
}
else {
recipeTicks = 0;
}
for(int process = 0; process < tier.processes; process++) for(int process = 0; process < tier.processes; process++)
{ {
if(electricityStored >= ENERGY_PER_TICK) if(electricityStored >= ENERGY_PER_TICK)
@ -204,6 +269,21 @@ public class TileEntityFactory extends TileEntityElectricBlock implements IEnerg
} }
} }
public ItemStack getMachineStack()
{
switch(recipeType)
{
case 0:
return new ItemStack(Mekanism.MachineBlock, 1, MachineType.ENERGIZED_SMELTER.meta);
case 1:
return new ItemStack(Mekanism.MachineBlock, 1, MachineType.ENRICHMENT_CHAMBER.meta);
case 2:
return new ItemStack(Mekanism.MachineBlock, 1, MachineType.CRUSHER.meta);
default:
return null;
}
}
@Override @Override
public boolean func_102008_b(int slotID, ItemStack itemstack, int side) public boolean func_102008_b(int slotID, ItemStack itemstack, int side)
{ {
@ -214,15 +294,15 @@ public class TileEntityFactory extends TileEntityElectricBlock implements IEnerg
(!(itemstack.getItem() instanceof IItemElectric) || (!(itemstack.getItem() instanceof IItemElectric) ||
((IItemElectric)itemstack.getItem()).getProvideRequest(itemstack).getWatts() == 0)); ((IItemElectric)itemstack.getItem()).getProvideRequest(itemstack).getWatts() == 0));
} }
else if(tier == FactoryTier.BASIC && slotID >= 5 && slotID <= 7) else if(tier == FactoryTier.BASIC && slotID >= 7 && slotID <= 9)
{ {
return true; return true;
} }
else if(tier == FactoryTier.ADVANCED && slotID >= 7 && slotID <= 11) else if(tier == FactoryTier.ADVANCED && slotID >= 9 && slotID <= 13)
{ {
return true; return true;
} }
else if(tier == FactoryTier.ELITE && slotID >= 9 && slotID <= 15) else if(tier == FactoryTier.ELITE && slotID >= 11 && slotID <= 17)
{ {
return true; return true;
} }
@ -235,33 +315,33 @@ public class TileEntityFactory extends TileEntityElectricBlock implements IEnerg
{ {
if(tier == FactoryTier.BASIC) if(tier == FactoryTier.BASIC)
{ {
if(slotID >= 5 && slotID <= 7) if(slotID >= 7 && slotID <= 9)
{ {
return false; return false;
} }
else if(slotID >= 2 && slotID <= 4) else if(slotID >= 4 && slotID <= 6)
{ {
return RecipeType.values()[recipeType].getCopiedOutput(itemstack, false) != null; return RecipeType.values()[recipeType].getCopiedOutput(itemstack, false) != null;
} }
} }
else if(tier == FactoryTier.ADVANCED) else if(tier == FactoryTier.ADVANCED)
{ {
if(slotID >= 7 && slotID <= 11) if(slotID >= 9 && slotID <= 13)
{ {
return false; return false;
} }
else if(slotID >= 2 && slotID <= 6) else if(slotID >= 4 && slotID <= 8)
{ {
return RecipeType.values()[recipeType].getCopiedOutput(itemstack, false) != null; return RecipeType.values()[recipeType].getCopiedOutput(itemstack, false) != null;
} }
} }
else if(tier == FactoryTier.ELITE) else if(tier == FactoryTier.ELITE)
{ {
if(slotID >= 9 && slotID <= 15) if(slotID >= 11 && slotID <= 17)
{ {
return false; return false;
} }
else if(slotID >= 2 && slotID <= 8) else if(slotID >= 4 && slotID <= 10)
{ {
return RecipeType.values()[recipeType].getCopiedOutput(itemstack, false) != null; return RecipeType.values()[recipeType].getCopiedOutput(itemstack, false) != null;
} }
@ -311,6 +391,11 @@ public class TileEntityFactory extends TileEntityElectricBlock implements IEnerg
return upgradeTicks*i / UPGRADE_TICKS_REQUIRED; return upgradeTicks*i / UPGRADE_TICKS_REQUIRED;
} }
public int getScaledRecipeProgress(int i)
{
return recipeTicks*i / RECIPE_TICKS_REQUIRED;
}
public boolean canOperate(int inputSlot, int outputSlot) public boolean canOperate(int inputSlot, int outputSlot)
{ {
if(inventory[inputSlot] == null) if(inventory[inputSlot] == null)
@ -382,6 +467,8 @@ public class TileEntityFactory extends TileEntityElectricBlock implements IEnerg
energyMultiplier = dataStream.readInt(); energyMultiplier = dataStream.readInt();
isActive = dataStream.readBoolean(); isActive = dataStream.readBoolean();
recipeType = dataStream.readInt(); recipeType = dataStream.readInt();
upgradeTicks = dataStream.readInt();
recipeTicks = dataStream.readInt();
for(int i = 0; i < tier.processes; i++) for(int i = 0; i < tier.processes; i++)
{ {
@ -400,6 +487,8 @@ public class TileEntityFactory extends TileEntityElectricBlock implements IEnerg
energyMultiplier = nbtTags.getInteger("energyMultiplier"); energyMultiplier = nbtTags.getInteger("energyMultiplier");
isActive = nbtTags.getBoolean("isActive"); isActive = nbtTags.getBoolean("isActive");
recipeType = nbtTags.getInteger("recipeType"); recipeType = nbtTags.getInteger("recipeType");
upgradeTicks = nbtTags.getInteger("upgradeTicks");
recipeTicks = nbtTags.getInteger("recipeTicks");
for(int i = 0; i < tier.processes; i++) for(int i = 0; i < tier.processes; i++)
{ {
@ -424,6 +513,8 @@ public class TileEntityFactory extends TileEntityElectricBlock implements IEnerg
nbtTags.setInteger("energyMultiplier", energyMultiplier); nbtTags.setInteger("energyMultiplier", energyMultiplier);
nbtTags.setBoolean("isActive", isActive); nbtTags.setBoolean("isActive", isActive);
nbtTags.setInteger("recipeType", recipeType); nbtTags.setInteger("recipeType", recipeType);
nbtTags.setInteger("upgradeTicks", upgradeTicks);
nbtTags.setInteger("recipeTicks", recipeTicks);
for(int i = 0; i < tier.processes; i++) for(int i = 0; i < tier.processes; i++)
{ {
@ -446,6 +537,8 @@ public class TileEntityFactory extends TileEntityElectricBlock implements IEnerg
data.add(energyMultiplier); data.add(energyMultiplier);
data.add(isActive); data.add(isActive);
data.add(recipeType); data.add(recipeType);
data.add(upgradeTicks);
data.add(recipeTicks);
data.add(progress); data.add(progress);
return data; return data;
} }

View file

@ -63,12 +63,11 @@ public class TileEntityMechanicalPipe extends TileEntity implements IMechanicalP
{ {
if(worldObj.isRemote) if(worldObj.isRemote)
{ {
if(liquidScale != prevScale) if(Math.abs((liquidScale-prevScale)*15F) >= 1)
{ {
worldObj.updateAllLightTypes(xCoord, yCoord, zCoord); worldObj.updateAllLightTypes(xCoord, yCoord, zCoord);
prevScale = liquidScale;
} }
prevScale = liquidScale;
if(liquidScale > 0) if(liquidScale > 0)
{ {
@ -122,30 +121,12 @@ public class TileEntityMechanicalPipe extends TileEntity implements IMechanicalP
public void handlePacketData(ByteArrayDataInput dataStream) public void handlePacketData(ByteArrayDataInput dataStream)
{ {
isActive = dataStream.readBoolean(); isActive = dataStream.readBoolean();
liquidScale = dataStream.readFloat();
if(dataStream.readInt() == 1)
{
refLiquid = new LiquidStack(dataStream.readInt(), LiquidContainerRegistry.BUCKET_VOLUME, dataStream.readInt());
}
} }
@Override @Override
public ArrayList getNetworkedData(ArrayList data) public ArrayList getNetworkedData(ArrayList data)
{ {
data.add(isActive); data.add(isActive);
data.add(liquidScale);
if(refLiquid != null)
{
data.add(1);
data.add(refLiquid.itemID);
data.add(refLiquid.itemMeta);
}
else {
data.add(0);
}
return data; return data;
} }
@ -175,13 +156,23 @@ public class TileEntityMechanicalPipe extends TileEntity implements IMechanicalP
@Override @Override
public int fill(ForgeDirection from, LiquidStack resource, boolean doFill) public int fill(ForgeDirection from, LiquidStack resource, boolean doFill)
{ {
return new LiquidTransferProtocol(this, VectorHelper.getTileEntityFromSide(worldObj, new Vector3(this), from), resource).calculate(); if(!isActive)
{
return new LiquidTransferProtocol(this, VectorHelper.getTileEntityFromSide(worldObj, new Vector3(this), from), resource).calculate();
}
return 0;
} }
@Override @Override
public int fill(int tankIndex, LiquidStack resource, boolean doFill) public int fill(int tankIndex, LiquidStack resource, boolean doFill)
{ {
return new LiquidTransferProtocol(this, null, resource).calculate(); if(!isActive)
{
return new LiquidTransferProtocol(this, null, resource).calculate();
}
return 0;
} }
@Override @Override

View file

@ -1,23 +1,15 @@
package mekanism.common; package mekanism.common;
import ic2.api.Direction; import ic2.api.Direction;
import ic2.api.ElectricItem;
import ic2.api.IElectricItem; import ic2.api.IElectricItem;
import ic2.api.energy.tile.IEnergySink; import ic2.api.energy.tile.IEnergySink;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import universalelectricity.core.item.ElectricItemHelper;
import universalelectricity.core.item.IItemElectric;
import com.google.common.io.ByteArrayDataInput;
import dan200.computer.api.IComputerAccess;
import dan200.computer.api.IPeripheral;
import mekanism.api.EnumColor; import mekanism.api.EnumColor;
import mekanism.api.IStrictEnergyAcceptor; import mekanism.api.IStrictEnergyAcceptor;
import mekanism.api.Object3D;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.EntityPlayerMP;
@ -27,6 +19,12 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.AxisAlignedBB;
import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.ForgeDirection;
import universalelectricity.core.item.IItemElectric;
import com.google.common.io.ByteArrayDataInput;
import dan200.computer.api.IComputerAccess;
import dan200.computer.api.IPeripheral;
public class TileEntityTeleporter extends TileEntityElectricBlock implements IEnergySink, IPeripheral, IStrictEnergyAcceptor public class TileEntityTeleporter extends TileEntityElectricBlock implements IEnergySink, IPeripheral, IStrictEnergyAcceptor
{ {
@ -52,19 +50,19 @@ public class TileEntityTeleporter extends TileEntityElectricBlock implements IEn
{ {
if(Mekanism.teleporters.containsKey(code)) if(Mekanism.teleporters.containsKey(code))
{ {
if(!Mekanism.teleporters.get(code).contains(Teleporter.Coords.get(this)) && hasFrame()) if(!Mekanism.teleporters.get(code).contains(Object3D.get(this)) && hasFrame())
{ {
Mekanism.teleporters.get(code).add(Teleporter.Coords.get(this)); Mekanism.teleporters.get(code).add(Object3D.get(this));
} }
else if(Mekanism.teleporters.get(code).contains(Teleporter.Coords.get(this)) && !hasFrame()) else if(Mekanism.teleporters.get(code).contains(Object3D.get(this)) && !hasFrame())
{ {
Mekanism.teleporters.get(code).remove(Teleporter.Coords.get(this)); Mekanism.teleporters.get(code).remove(Object3D.get(this));
} }
} }
else if(hasFrame()) else if(hasFrame())
{ {
ArrayList<Teleporter.Coords> newCoords = new ArrayList<Teleporter.Coords>(); ArrayList<Object3D> newCoords = new ArrayList<Object3D>();
newCoords.add(Teleporter.Coords.get(this)); newCoords.add(Object3D.get(this));
Mekanism.teleporters.put(code, newCoords); Mekanism.teleporters.put(code, newCoords);
} }
@ -143,11 +141,11 @@ public class TileEntityTeleporter extends TileEntityElectricBlock implements IEn
{ {
List<EntityPlayer> entitiesInPortal = worldObj.getEntitiesWithinAABB(EntityPlayer.class, AxisAlignedBB.getBoundingBox(xCoord-1, yCoord, zCoord-1, xCoord+1, yCoord+3, zCoord+1)); List<EntityPlayer> entitiesInPortal = worldObj.getEntitiesWithinAABB(EntityPlayer.class, AxisAlignedBB.getBoundingBox(xCoord-1, yCoord, zCoord-1, xCoord+1, yCoord+3, zCoord+1));
Teleporter.Coords closestCoords = null; Object3D closestCoords = null;
for(Teleporter.Coords coords : Mekanism.teleporters.get(code)) for(Object3D coords : Mekanism.teleporters.get(code))
{ {
if(!coords.equals(Teleporter.Coords.get(this))) if(!coords.equals(Object3D.get(this)))
{ {
closestCoords = coords; closestCoords = coords;
break; break;
@ -183,11 +181,11 @@ public class TileEntityTeleporter extends TileEntityElectricBlock implements IEn
List<EntityPlayer> entitiesInPortal = worldObj.getEntitiesWithinAABB(EntityPlayer.class, AxisAlignedBB.getBoundingBox(xCoord-1, yCoord, zCoord-1, xCoord+1, yCoord+3, zCoord+1)); List<EntityPlayer> entitiesInPortal = worldObj.getEntitiesWithinAABB(EntityPlayer.class, AxisAlignedBB.getBoundingBox(xCoord-1, yCoord, zCoord-1, xCoord+1, yCoord+3, zCoord+1));
Teleporter.Coords closestCoords = null; Object3D closestCoords = null;
for(Teleporter.Coords coords : Mekanism.teleporters.get(code)) for(Object3D coords : Mekanism.teleporters.get(code))
{ {
if(!coords.equals(Teleporter.Coords.get(this))) if(!coords.equals(Object3D.get(this)))
{ {
closestCoords = coords; closestCoords = coords;
break; break;
@ -207,7 +205,7 @@ public class TileEntityTeleporter extends TileEntityElectricBlock implements IEn
((EntityPlayerMP)entity).playerNetServerHandler.setPlayerLocation(closestCoords.xCoord+0.5, closestCoords.yCoord, closestCoords.zCoord+0.5, entity.rotationYaw, entity.rotationPitch); ((EntityPlayerMP)entity).playerNetServerHandler.setPlayerLocation(closestCoords.xCoord+0.5, closestCoords.yCoord, closestCoords.zCoord+0.5, entity.rotationYaw, entity.rotationPitch);
for(Teleporter.Coords coords : Mekanism.teleporters.get(code)) for(Object3D coords : Mekanism.teleporters.get(code))
{ {
PacketHandler.sendPortalFX(coords.xCoord, coords.yCoord, coords.zCoord, coords.dimensionId); PacketHandler.sendPortalFX(coords.xCoord, coords.yCoord, coords.zCoord, coords.dimensionId);
} }
@ -229,9 +227,9 @@ public class TileEntityTeleporter extends TileEntityElectricBlock implements IEn
{ {
if(Mekanism.teleporters.containsKey(code)) if(Mekanism.teleporters.containsKey(code))
{ {
if(Mekanism.teleporters.get(code).contains(Teleporter.Coords.get(this))) if(Mekanism.teleporters.get(code).contains(Object3D.get(this)))
{ {
Mekanism.teleporters.get(code).remove(Teleporter.Coords.get(this)); Mekanism.teleporters.get(code).remove(Object3D.get(this));
} }
if(Mekanism.teleporters.get(code).isEmpty()) if(Mekanism.teleporters.get(code).isEmpty())
@ -242,7 +240,7 @@ public class TileEntityTeleporter extends TileEntityElectricBlock implements IEn
} }
} }
public int calculateEnergyCost(Entity entity, Teleporter.Coords coords) public int calculateEnergyCost(Entity entity, Object3D coords)
{ {
int energyCost = 1000; int energyCost = 1000;
@ -311,9 +309,9 @@ public class TileEntityTeleporter extends TileEntityElectricBlock implements IEn
{ {
if(Mekanism.teleporters.containsKey(code)) if(Mekanism.teleporters.containsKey(code))
{ {
if(Mekanism.teleporters.get(code).contains(Teleporter.Coords.get(this))) if(Mekanism.teleporters.get(code).contains(Object3D.get(this)))
{ {
Mekanism.teleporters.get(code).remove(Teleporter.Coords.get(this)); Mekanism.teleporters.get(code).remove(Object3D.get(this));
} }
if(Mekanism.teleporters.get(code).isEmpty()) Mekanism.teleporters.remove(code); if(Mekanism.teleporters.get(code).isEmpty()) Mekanism.teleporters.remove(code);

View file

@ -40,13 +40,12 @@ public class TileEntityUniversalCable extends TileEntity implements IUniversalCa
{ {
if(worldObj.isRemote) if(worldObj.isRemote)
{ {
if(energyScale != prevScale) if(Math.abs((energyScale-prevScale)*15F) >= 1)
{ {
worldObj.updateAllLightTypes(xCoord, yCoord, zCoord); worldObj.updateAllLightTypes(xCoord, yCoord, zCoord);
prevScale = energyScale;
} }
prevScale = energyScale;
if(energyScale > 0) if(energyScale > 0)
{ {
energyScale -= .01; energyScale -= .01;

View file

@ -22,6 +22,7 @@ public class BlockRenderingHandler implements ISimpleBlockRenderingHandler
public ModelHeatGenerator heatGenerator = new ModelHeatGenerator(); public ModelHeatGenerator heatGenerator = new ModelHeatGenerator();
public ModelHydrogenGenerator hydrogenGenerator = new ModelHydrogenGenerator(); public ModelHydrogenGenerator hydrogenGenerator = new ModelHydrogenGenerator();
public ModelElectrolyticSeparator electrolyticSeparator = new ModelElectrolyticSeparator(); public ModelElectrolyticSeparator electrolyticSeparator = new ModelElectrolyticSeparator();
public ModelWindTurbine windTurbine = new ModelWindTurbine();
@Override @Override
public void renderInventoryBlock(Block block, int metadata, int modelID, RenderBlocks renderer) public void renderInventoryBlock(Block block, int metadata, int modelID, RenderBlocks renderer)
@ -70,6 +71,14 @@ public class BlockRenderingHandler implements ISimpleBlockRenderingHandler
GL11.glBindTexture(3553, FMLClientHandler.instance().getClient().renderEngine.getTexture("/mods/mekanism/render/ElectrolyticSeparatorHydrogen.png")); GL11.glBindTexture(3553, FMLClientHandler.instance().getClient().renderEngine.getTexture("/mods/mekanism/render/ElectrolyticSeparatorHydrogen.png"));
electrolyticSeparator.render(0.0625F); electrolyticSeparator.render(0.0625F);
} }
else if(metadata == GeneratorType.WIND_TURBINE.meta)
{
GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F);
GL11.glRotatef(180F, 0.0F, 1.0F, 0.0F);
GL11.glTranslatef(0.0F, 0.35F, 0.0F);
GL11.glBindTexture(3553, FMLClientHandler.instance().getClient().renderEngine.getTexture("/mods/mekanism/render/WindTurbine.png"));
windTurbine.render(0.018F, 0);
}
else { else {
renderItem(renderer, metadata, block); renderItem(renderer, metadata, block);
} }

View file

@ -7,6 +7,7 @@ import mekanism.generators.common.TileEntityElectrolyticSeparator;
import mekanism.generators.common.TileEntityHeatGenerator; import mekanism.generators.common.TileEntityHeatGenerator;
import mekanism.generators.common.TileEntityHydrogenGenerator; import mekanism.generators.common.TileEntityHydrogenGenerator;
import mekanism.generators.common.TileEntitySolarGenerator; import mekanism.generators.common.TileEntitySolarGenerator;
import mekanism.generators.common.TileEntityWindTurbine;
import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.GuiScreen;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
@ -29,6 +30,7 @@ public class GeneratorsClientProxy extends GeneratorsCommonProxy
ClientRegistry.registerTileEntity(TileEntityHeatGenerator.class, "HeatGenerator", new RenderHeatGenerator()); ClientRegistry.registerTileEntity(TileEntityHeatGenerator.class, "HeatGenerator", new RenderHeatGenerator());
ClientRegistry.registerTileEntity(TileEntityHydrogenGenerator.class, "HydrogenGenerator", new RenderHydrogenGenerator()); ClientRegistry.registerTileEntity(TileEntityHydrogenGenerator.class, "HydrogenGenerator", new RenderHydrogenGenerator());
ClientRegistry.registerTileEntity(TileEntityElectrolyticSeparator.class, "ElectrolyticSeparator", new RenderElectrolyticSeparator()); ClientRegistry.registerTileEntity(TileEntityElectrolyticSeparator.class, "ElectrolyticSeparator", new RenderElectrolyticSeparator());
ClientRegistry.registerTileEntity(TileEntityWindTurbine.class, "WindTurbine", new RenderWindTurbine());
} }
@Override @Override
@ -57,6 +59,8 @@ public class GeneratorsClientProxy extends GeneratorsCommonProxy
return new GuiHydrogenGenerator(player.inventory, (TileEntityHydrogenGenerator)tileEntity); return new GuiHydrogenGenerator(player.inventory, (TileEntityHydrogenGenerator)tileEntity);
case 4: case 4:
return new GuiBioGenerator(player.inventory, (TileEntityBioGenerator)tileEntity); return new GuiBioGenerator(player.inventory, (TileEntityBioGenerator)tileEntity);
case 5:
return new GuiWindTurbine(player.inventory, (TileEntityWindTurbine)tileEntity);
} }
return null; return null;
} }

View file

@ -0,0 +1,70 @@
package mekanism.generators.client;
import mekanism.api.EnumColor;
import mekanism.generators.common.ContainerWindTurbine;
import mekanism.generators.common.TileEntityWindTurbine;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.InventoryPlayer;
import org.lwjgl.opengl.GL11;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import universalelectricity.core.electricity.ElectricityDisplay;
import universalelectricity.core.electricity.ElectricityDisplay.ElectricUnit;
@SideOnly(Side.CLIENT)
public class GuiWindTurbine extends GuiContainer
{
public TileEntityWindTurbine tileEntity;
private int guiWidth;
private int guiHeight;
public GuiWindTurbine(InventoryPlayer inventory, TileEntityWindTurbine tentity)
{
super(new ContainerWindTurbine(inventory, tentity));
tileEntity = tentity;
}
@Override
protected void drawGuiContainerForegroundLayer(int par1, int par2)
{
fontRenderer.drawString(tileEntity.fullName, 45, 6, 0x404040);
fontRenderer.drawString("Inventory", 8, (ySize - 96) + 2, 0x404040);
fontRenderer.drawString(ElectricityDisplay.getDisplayShort(tileEntity.electricityStored, ElectricUnit.JOULES), 51, 26, 0x00CD00);
fontRenderer.drawString("Power: " + tileEntity.GENERATION_RATE*tileEntity.getMultiplier(), 51, 35, 0x00CD00);
fontRenderer.drawString(tileEntity.getVoltage() + "v", 51, 44, 0x00CD00);
int size = 44;
if(!tileEntity.checkBounds())
{
size += 9;
fontRenderer.drawString(EnumColor.DARK_RED + "Invalid bounds", 51, size, 0x00CD00);
}
if(!tileEntity.worldObj.canBlockSeeTheSky(tileEntity.xCoord, tileEntity.yCoord+4, tileEntity.zCoord))
{
size += 9;
fontRenderer.drawString(EnumColor.DARK_RED + "Sky blocked", 51, size, 0x00CD00);
}
}
@Override
protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3)
{
mc.renderEngine.bindTexture("/mods/mekanism/gui/GuiWindTurbine.png");
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
guiWidth = (width - xSize) / 2;
guiHeight = (height - ySize) / 2;
drawTexturedModalRect(guiWidth, guiHeight, 0, 0, xSize, ySize);
int displayInt;
displayInt = tileEntity.getScaledEnergyLevel(52);
drawTexturedModalRect(guiWidth + 165, guiHeight + 17 + 52 - displayInt, 176, 52 - displayInt, 4, displayInt);
drawTexturedModalRect(guiWidth + 20, guiHeight + 37, 176, (tileEntity.getMultiplier() > 0 ? 52 : 64), 12, 12);
}
}

View file

@ -0,0 +1,173 @@
package mekanism.generators.client;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.entity.Entity;
public class ModelWindTurbine extends ModelBase
{
ModelRenderer Base;
ModelRenderer TowerFront;
ModelRenderer TowerLeft;
ModelRenderer TowerBack;
ModelRenderer TowerRight;
ModelRenderer TowerMoterFront;
ModelRenderer TowerBaseMotor;
ModelRenderer TowerBaseMotorBack;
ModelRenderer TowerMotor;
ModelRenderer Rotor;
ModelRenderer RotorCover;
ModelRenderer BladeBaseC;
ModelRenderer BladeBaseB;
ModelRenderer BladeBaseA;
public ModelWindTurbine()
{
textureWidth = 128;
textureHeight = 64;
Base = new ModelRenderer(this, 0, 0);
Base.addBox(-8F, 0F, -8F, 16, 6, 16);
Base.setRotationPoint(0F, 18F, 0F);
Base.setTextureSize(128, 64);
Base.mirror = true;
setRotation(Base, 0F, 0F, 0F);
TowerFront = new ModelRenderer(this, 104, 0);
TowerFront.addBox(-5F, -62F, -7F, 10, 63, 2);
TowerFront.setRotationPoint(0F, 19F, 0F);
TowerFront.setTextureSize(128, 64);
TowerFront.mirror = true;
setRotation(TowerFront, -0.0872665F, 0F, 0F);
TowerLeft = new ModelRenderer(this, 104, 0);
TowerLeft.addBox(-5F, -62F, 5F, 10, 63, 2);
TowerLeft.setRotationPoint(0F, 19F, 0F);
TowerLeft.setTextureSize(128, 64);
TowerLeft.mirror = true;
setRotation(TowerLeft, 0.0872665F, 1.570796F, 0F);
TowerBack = new ModelRenderer(this, 104, 0);
TowerBack.addBox(-5F, -62F, 5F, 10, 63, 2);
TowerBack.setRotationPoint(0F, 19F, 0F);
TowerBack.setTextureSize(128, 64);
TowerBack.mirror = true;
setRotation(TowerBack, 0.0872665F, 0F, 0F);
TowerRight = new ModelRenderer(this, 104, 0);
TowerRight.addBox(-5F, -62F, 5F, 10, 63, 2);
TowerRight.setRotationPoint(0F, 19F, 0F);
TowerRight.setTextureSize(128, 64);
TowerRight.mirror = true;
setRotation(TowerRight, 0.0872665F, -1.570796F, 0F);
TowerMoterFront = new ModelRenderer(this, 40, 38);
TowerMoterFront.addBox(-6F, -7.3F, -5F, 12, 9, 6);
TowerMoterFront.setRotationPoint(0F, -45F, -1F);
TowerMoterFront.setTextureSize(128, 64);
TowerMoterFront.mirror = true;
setRotation(TowerMoterFront, 0F, 0F, 0F);
TowerBaseMotor = new ModelRenderer(this, 65, 0);
TowerBaseMotor.addBox(-6F, -0.3F, 0F, 12, 2, 7);
TowerBaseMotor.setRotationPoint(0F, -45F, 0F);
TowerBaseMotor.setTextureSize(128, 64);
TowerBaseMotor.mirror = true;
setRotation(TowerBaseMotor, 0F, 0F, 0F);
TowerBaseMotorBack = new ModelRenderer(this, 65, 30);
TowerBaseMotorBack.addBox(-4F, -3.3F, 7F, 8, 4, 3);
TowerBaseMotorBack.setRotationPoint(0F, -45F, 0F);
TowerBaseMotorBack.setTextureSize(128, 64);
TowerBaseMotorBack.mirror = true;
setRotation(TowerBaseMotorBack, 0F, 0F, 0F);
TowerMotor = new ModelRenderer(this, 65, 15);
TowerMotor.addBox(-4F, -6.3F, 0F, 8, 6, 7);
TowerMotor.setRotationPoint(0F, -45F, 0F);
TowerMotor.setTextureSize(128, 64);
TowerMotor.mirror = true;
setRotation(TowerMotor, 0F, 0F, 0F);
Rotor = new ModelRenderer(this, 88, 30);
Rotor.addBox(-0.5F, -0.5F, 0F, 1, 1, 3);
Rotor.setRotationPoint(0F, -48F, -8F);
Rotor.setTextureSize(128, 64);
Rotor.mirror = true;
setRotation(Rotor, 0F, 0F, 0F);
RotorCover = new ModelRenderer(this, 88, 35);
RotorCover.addBox(-2F, -2F, -1F, 4, 4, 1);
RotorCover.setRotationPoint(0F, -48F, -8F);
RotorCover.setTextureSize(128, 64);
RotorCover.mirror = true;
setRotation(RotorCover, 0F, 0F, 0F);
BladeBaseC = new ModelRenderer(this, 0, 54);
BladeBaseC.addBox(1F, -1F, 0F, 32, 2, 1);
BladeBaseC.setRotationPoint(0F, -48F, -8F);
BladeBaseC.setTextureSize(128, 64);
BladeBaseC.mirror = true;
setRotation(BladeBaseC, 0F, 0F, getRotation(120));
BladeBaseB = new ModelRenderer(this, 0, 54);
BladeBaseB.addBox(1F, -1F, 0F, 32, 2, 1);
BladeBaseB.setRotationPoint(0F, -48F, -8F);
BladeBaseB.setTextureSize(128, 64);
BladeBaseB.mirror = true;
setRotation(BladeBaseB, 0F, 0F, 0F);
BladeBaseA = new ModelRenderer(this, 0, 54);
BladeBaseA.addBox(1F, -1F, 0F, 32, 2, 1);
BladeBaseA.setRotationPoint(0F, -48F, -8F);
BladeBaseA.setTextureSize(128, 64);
BladeBaseA.mirror = true;
setRotation(BladeBaseA, 0F, 0F, getRotation(240));
}
public void render(float size, int angle)
{
Base.render(size);
TowerFront.render(size);
TowerLeft.render(size);
TowerBack.render(size);
TowerRight.render(size);
TowerMoterFront.render(size);
TowerBaseMotor.render(size);
TowerBaseMotorBack.render(size);
TowerMotor.render(size);
Rotor.render(size);
RotorCover.render(size);
setRotation(BladeBaseC, 0.0F, 0.0F, getRotation(getAbsoluteAngle(120 + angle)));
BladeBaseC.render(size);
setRotation(BladeBaseB, 0.0F, 0.0F, getRotation(getAbsoluteAngle(angle)));
BladeBaseB.render(size);
setRotation(BladeBaseA, 0.0F, 0.0F, getRotation(getAbsoluteAngle(240 + angle)));
BladeBaseA.render(size);
}
public float getRotation(int angle)
{
return ((float)angle/(float)180)*(float)Math.PI;
}
public int getAbsoluteAngle(int angle)
{
return angle % 360;
}
@Override
public void render(Entity entity, float f, float f1, float f2, float f3, float f4, float f5)
{
super.render(entity, f, f1, f2, f3, f4, f5);
setRotationAngles(f, f1, f2, f3, f4, f5, entity);
Base.render(f5);
TowerFront.render(f5);
TowerLeft.render(f5);
TowerBack.render(f5);
TowerRight.render(f5);
TowerMoterFront.render(f5);
TowerBaseMotor.render(f5);
TowerBaseMotorBack.render(f5);
TowerMotor.render(f5);
Rotor.render(f5);
RotorCover.render(f5);
BladeBaseC.render(f5);
BladeBaseB.render(f5);
BladeBaseA.render(f5);
}
private void setRotation(ModelRenderer model, float x, float y, float z)
{
model.rotateAngleX = x;
model.rotateAngleY = y;
model.rotateAngleZ = z;
}
}

View file

@ -0,0 +1,49 @@
package mekanism.generators.client;
import mekanism.common.Mekanism;
import mekanism.generators.common.TileEntityWindTurbine;
import net.minecraft.client.gui.GuiIngameMenu;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import org.lwjgl.opengl.GL11;
import cpw.mods.fml.client.FMLClientHandler;
public class RenderWindTurbine extends TileEntitySpecialRenderer
{
private ModelWindTurbine model = new ModelWindTurbine();
@Override
public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float partialTick)
{
renderAModelAt((TileEntityWindTurbine)tileEntity, x, y, z, partialTick);
}
private void renderAModelAt(TileEntityWindTurbine tileEntity, double x, double y, double z, float partialTick)
{
GL11.glPushMatrix();
GL11.glTranslatef((float)x + 0.5F, (float)y + 1.5F, (float)z + 0.5F);
bindTextureByName("/mods/mekanism/render/WindTurbine.png");
switch(tileEntity.facing)
{
case 2: GL11.glRotatef(0, 0.0F, 1.0F, 0.0F); break;
case 3: GL11.glRotatef(180, 0.0F, 1.0F, 0.0F); break;
case 4: GL11.glRotatef(90, 0.0F, 1.0F, 0.0F); break;
case 5: GL11.glRotatef(270, 0.0F, 1.0F, 0.0F); break;
}
GL11.glRotatef(180, 0F, 0F, 1F);
if(!Mekanism.proxy.isPaused() &&
tileEntity.checkBounds() &&
tileEntity.worldObj.canBlockSeeTheSky(tileEntity.xCoord, tileEntity.yCoord+4, tileEntity.zCoord))
{
tileEntity.angle = (tileEntity.angle+((int)tileEntity.getMultiplier())) % 360;
}
model.render(0.0625F, tileEntity.angle);
GL11.glPopMatrix();
}
}

View file

@ -41,6 +41,7 @@ import cpw.mods.fml.relauncher.SideOnly;
* 3: Hydrogen Generator * 3: Hydrogen Generator
* 4: Bio-Generator * 4: Bio-Generator
* 5: Advanced Solar Generator * 5: Advanced Solar Generator
* 6: Wind Turbine
* @author AidanBrady * @author AidanBrady
* *
*/ */
@ -218,6 +219,7 @@ public class BlockGenerator extends BlockContainer
list.add(new ItemStack(i, 1, 3)); list.add(new ItemStack(i, 1, 3));
list.add(new ItemStack(i, 1, 4)); list.add(new ItemStack(i, 1, 4));
list.add(new ItemStack(i, 1, 5)); list.add(new ItemStack(i, 1, 5));
list.add(new ItemStack(i, 1, 6));
} }
@Override @Override
@ -226,7 +228,7 @@ public class BlockGenerator extends BlockContainer
{ {
int metadata = world.getBlockMetadata(x, y, z); int metadata = world.getBlockMetadata(x, y, z);
TileEntityElectricBlock tileEntity = (TileEntityElectricBlock)world.getBlockTileEntity(x, y, z); TileEntityElectricBlock tileEntity = (TileEntityElectricBlock)world.getBlockTileEntity(x, y, z);
if (MekanismUtils.isActive(world, x, y, z)) if(MekanismUtils.isActive(world, x, y, z))
{ {
float xRandom = (float)x + 0.5F; float xRandom = (float)x + 0.5F;
float yRandom = (float)y + 0.0F + random.nextFloat() * 6.0F / 16.0F; float yRandom = (float)y + 0.0F + random.nextFloat() * 6.0F / 16.0F;
@ -234,7 +236,7 @@ public class BlockGenerator extends BlockContainer
float iRandom = 0.52F; float iRandom = 0.52F;
float jRandom = random.nextFloat() * 0.6F - 0.3F; float jRandom = random.nextFloat() * 0.6F - 0.3F;
if (tileEntity.facing == 4) if(tileEntity.facing == 4)
{ {
switch(GeneratorType.values()[metadata]) switch(GeneratorType.values()[metadata])
{ {
@ -249,7 +251,7 @@ public class BlockGenerator extends BlockContainer
break; break;
} }
} }
else if (tileEntity.facing == 5) else if(tileEntity.facing == 5)
{ {
switch(GeneratorType.values()[metadata]) switch(GeneratorType.values()[metadata])
{ {
@ -264,7 +266,7 @@ public class BlockGenerator extends BlockContainer
break; break;
} }
} }
else if (tileEntity.facing == 2) else if(tileEntity.facing == 2)
{ {
switch(GeneratorType.values()[metadata]) switch(GeneratorType.values()[metadata])
{ {
@ -279,7 +281,7 @@ public class BlockGenerator extends BlockContainer
break; break;
} }
} }
else if (tileEntity.facing == 3) else if(tileEntity.facing == 3)
{ {
switch(GeneratorType.values()[metadata]) switch(GeneratorType.values()[metadata])
{ {
@ -306,18 +308,30 @@ public class BlockGenerator extends BlockContainer
int idSum = 0; int idSum = 0;
idSum += world.getBlockId(x, y, z); idSum += world.getBlockId(x, y, z);
World worldObj = world;
for(int xPos=-1;xPos<=2;xPos++) for(int xPos=-1;xPos<=2;xPos++)
{ {
for(int zPos=-1;zPos<=2;zPos++) for(int zPos=-1;zPos<=2;zPos++)
{ {
idSum += worldObj.getBlockId(x+xPos, y+2, z+zPos); idSum += world.getBlockId(x+xPos, y+2, z+zPos);
} }
} }
return (idSum == 0) && canPlace; return (idSum == 0) && canPlace;
} }
else if(world.getBlockMetadata(x, y, z) == GeneratorType.WIND_TURBINE.meta)
{
boolean canPlace = super.canPlaceBlockAt(world, x, y, z);
int idSum = 0;
for(int yPos = y+1; yPos <= y+4; yPos++)
{
idSum += world.getBlockId(x, yPos, z);
}
return (idSum == 0) && canPlace;
}
return super.canPlaceBlockAt(world, x, y, z); return super.canPlaceBlockAt(world, x, y, z);
} }
@ -559,7 +573,8 @@ public class BlockGenerator extends BlockContainer
ELECTROLYTIC_SEPARATOR(2, 2, 20000, TileEntityElectrolyticSeparator.class, true), ELECTROLYTIC_SEPARATOR(2, 2, 20000, TileEntityElectrolyticSeparator.class, true),
HYDROGEN_GENERATOR(3, 3, 40000, TileEntityHydrogenGenerator.class, true), HYDROGEN_GENERATOR(3, 3, 40000, TileEntityHydrogenGenerator.class, true),
BIO_GENERATOR(4, 4, 160000, TileEntityBioGenerator.class, true), BIO_GENERATOR(4, 4, 160000, TileEntityBioGenerator.class, true),
ADVANCED_SOLAR_GENERATOR(5, 1, 200000, TileEntityAdvancedSolarGenerator.class, true); ADVANCED_SOLAR_GENERATOR(5, 1, 200000, TileEntityAdvancedSolarGenerator.class, true),
WIND_TURBINE(6, 5, 200000, TileEntityWindTurbine.class, true);
public int meta; public int meta;
public int guiId; public int guiId;

View file

@ -0,0 +1,122 @@
package mekanism.generators.common;
import ic2.api.IElectricItem;
import mekanism.common.SlotEnergy;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import mekanism.common.SlotEnergy.SlotCharge;
import universalelectricity.core.item.IItemElectric;
public class ContainerWindTurbine extends Container
{
private TileEntityWindTurbine tileEntity;
public ContainerWindTurbine(InventoryPlayer inventory, TileEntityWindTurbine tentity)
{
tileEntity = tentity;
addSlotToContainer(new SlotCharge(tentity, 0, 143, 35));
int slotX;
for(slotX = 0; slotX < 3; ++slotX)
{
for(int slotY = 0; slotY < 9; ++slotY)
{
addSlotToContainer(new Slot(inventory, slotY + slotX * 9 + 9, 8 + slotY * 18, 84 + slotX * 18));
}
}
for(slotX = 0; slotX < 9; ++slotX)
{
addSlotToContainer(new Slot(inventory, slotX, 8 + slotX * 18, 142));
}
tileEntity.openChest();
}
@Override
public void onCraftGuiClosed(EntityPlayer entityplayer)
{
super.onCraftGuiClosed(entityplayer);
tileEntity.closeChest();
}
@Override
public boolean canInteractWith(EntityPlayer par1EntityPlayer)
{
return tileEntity.isUseableByPlayer(par1EntityPlayer);
}
@Override
public ItemStack transferStackInSlot(EntityPlayer player, int slotID)
{
ItemStack stack = null;
Slot currentSlot = (Slot)inventorySlots.get(slotID);
if(currentSlot != null && currentSlot.getHasStack())
{
ItemStack slotStack = currentSlot.getStack();
stack = slotStack.copy();
if((slotStack.getItem() instanceof IItemElectric && ((IItemElectric)slotStack.getItem()).getReceiveRequest(slotStack).amperes != 0) || slotStack.getItem() instanceof IElectricItem)
{
if(slotID != 0)
{
if (!mergeItemStack(slotStack, 0, 1, false))
{
return null;
}
}
else if(slotID == 0)
{
if(!mergeItemStack(slotStack, 1, inventorySlots.size(), false))
{
return null;
}
}
}
else {
if(slotID >= 1 && slotID <= 27)
{
if(!mergeItemStack(slotStack, 28, inventorySlots.size(), false))
{
return null;
}
}
else if(slotID > 27)
{
if(!mergeItemStack(slotStack, 1, 27, false))
{
return null;
}
}
else {
if(!mergeItemStack(slotStack, 1, inventorySlots.size(), true))
{
return null;
}
}
}
if(slotStack.stackSize == 0)
{
currentSlot.putStack((ItemStack)null);
}
else {
currentSlot.onSlotChanged();
}
if(slotStack.stackSize == stack.stackSize)
{
return null;
}
currentSlot.onPickupFromSlot(player, slotStack);
}
return stack;
}
}

View file

@ -24,6 +24,7 @@ public class GeneratorsCommonProxy
GameRegistry.registerTileEntity(TileEntityHeatGenerator.class, "HeatGenerator"); GameRegistry.registerTileEntity(TileEntityHeatGenerator.class, "HeatGenerator");
GameRegistry.registerTileEntity(TileEntityHydrogenGenerator.class, "HydrogenGenerator"); GameRegistry.registerTileEntity(TileEntityHydrogenGenerator.class, "HydrogenGenerator");
GameRegistry.registerTileEntity(TileEntityElectrolyticSeparator.class, "ElectrolyticSeparator"); GameRegistry.registerTileEntity(TileEntityElectrolyticSeparator.class, "ElectrolyticSeparator");
GameRegistry.registerTileEntity(TileEntityWindTurbine.class, "WindTurbine");
} }
/** /**
@ -82,6 +83,8 @@ public class GeneratorsCommonProxy
return new ContainerHydrogenGenerator(player.inventory, (TileEntityHydrogenGenerator)tileEntity); return new ContainerHydrogenGenerator(player.inventory, (TileEntityHydrogenGenerator)tileEntity);
case 4: case 4:
return new ContainerBioGenerator(player.inventory, (TileEntityBioGenerator)tileEntity); return new ContainerBioGenerator(player.inventory, (TileEntityBioGenerator)tileEntity);
case 5:
return new ContainerWindTurbine(player.inventory, (TileEntityWindTurbine)tileEntity);
} }
return null; return null;
} }

View file

@ -39,6 +39,7 @@ import net.minecraftforge.liquids.LiquidStack;
* 3: Hydrogen Generator * 3: Hydrogen Generator
* 4: Bio-Generator * 4: Bio-Generator
* 5: Advanced Solar Generator * 5: Advanced Solar Generator
* 6: Wind Turbine
* @author AidanBrady * @author AidanBrady
* *
*/ */
@ -90,6 +91,9 @@ public class ItemBlockGenerator extends ItemBlock implements IEnergizedItem, IIt
case 5: case 5:
name = "AdvancedSolarGenerator"; name = "AdvancedSolarGenerator";
break; break;
case 6:
name = "WindTurbine";
break;
default: default:
name = "Unknown"; name = "Unknown";
break; break;
@ -214,6 +218,23 @@ public class ItemBlockGenerator extends ItemBlock implements IEnergizedItem, IIt
} }
} }
} }
else if(stack.getItemDamage() == GeneratorType.WIND_TURBINE.meta)
{
if(world.getBlockId(x, y, z) != Block.tallGrass.blockID && world.getBlockId(x, y, z) != 0)
place = false;
if(world.getBlockId(x, y, z) != 0)
{
if(Block.blocksList[world.getBlockId(x, y, z)].isBlockReplaceable(world, x, y, z))
place = true;
}
for(int yPos = y+1; yPos <= y+4; yPos++)
{
if(world.getBlockId(x, yPos, z) != 0)
place = false;
}
}
if(place && super.placeBlockAt(stack, player, world, x, y, z, side, hitX, hitY, hitZ, metadata)) if(place && super.placeBlockAt(stack, player, world, x, y, z, side, hitX, hitY, hitZ, metadata))
{ {
@ -453,12 +474,12 @@ public class ItemBlockGenerator extends ItemBlock implements IEnergizedItem, IIt
@Override @Override
public boolean canReceive(ItemStack itemStack) public boolean canReceive(ItemStack itemStack)
{ {
return false; return itemStack.getItemDamage() == GeneratorType.ELECTROLYTIC_SEPARATOR.meta;
} }
@Override @Override
public boolean canSend(ItemStack itemStack) public boolean canSend(ItemStack itemStack)
{ {
return true; return itemStack.getItemDamage() != GeneratorType.ELECTROLYTIC_SEPARATOR.meta;
} }
} }

View file

@ -135,6 +135,7 @@ public class MekanismGenerators implements IModule
LanguageRegistry.instance().addStringLocalization("tile.Generator.HydrogenGenerator.name", "Hydrogen Generator"); LanguageRegistry.instance().addStringLocalization("tile.Generator.HydrogenGenerator.name", "Hydrogen Generator");
LanguageRegistry.instance().addStringLocalization("tile.Generator.BioGenerator.name", "Bio-Generator"); LanguageRegistry.instance().addStringLocalization("tile.Generator.BioGenerator.name", "Bio-Generator");
LanguageRegistry.instance().addStringLocalization("tile.Generator.AdvancedSolarGenerator.name", "Advanced Solar Generator"); LanguageRegistry.instance().addStringLocalization("tile.Generator.AdvancedSolarGenerator.name", "Advanced Solar Generator");
LanguageRegistry.instance().addStringLocalization("tile.Generator.WindTurbine.name", "Wind Turbine");
} }
public void addEntities() public void addEntities()

View file

@ -1,5 +1,6 @@
package mekanism.generators.common; package mekanism.generators.common;
import mekanism.api.Object3D;
import mekanism.common.IBoundingBlock; import mekanism.common.IBoundingBlock;
import mekanism.common.MekanismUtils; import mekanism.common.MekanismUtils;
@ -13,13 +14,13 @@ public class TileEntityAdvancedSolarGenerator extends TileEntitySolarGenerator i
@Override @Override
public void onPlace() public void onPlace()
{ {
MekanismUtils.makeBoundingBlock(worldObj, xCoord, yCoord+1, zCoord, xCoord, yCoord, zCoord); MekanismUtils.makeBoundingBlock(worldObj, xCoord, yCoord+1, zCoord, Object3D.get(this));
for(int x=-1;x<=1;x++) for(int x=-1;x<=1;x++)
{ {
for(int z=-1;z<=1;z++) for(int z=-1;z<=1;z++)
{ {
MekanismUtils.makeBoundingBlock(worldObj, xCoord+x, yCoord+2, zCoord+z, xCoord, yCoord, zCoord); MekanismUtils.makeBoundingBlock(worldObj, xCoord+x, yCoord+2, zCoord+z, Object3D.get(this));
} }
} }
} }

View file

@ -78,7 +78,7 @@ public abstract class TileEntityGenerator extends TileEntityElectricBlock implem
if(worldObj.isRemote) if(worldObj.isRemote)
{ {
if(!(this instanceof TileEntitySolarGenerator)) if(!(this instanceof TileEntitySolarGenerator) && !(this instanceof TileEntityWindTurbine))
{ {
Mekanism.proxy.registerSound(this); Mekanism.proxy.registerSound(this);
} }

View file

@ -0,0 +1,123 @@
package mekanism.generators.common;
import mekanism.api.Object3D;
import mekanism.common.ChargeUtils;
import mekanism.common.IBoundingBlock;
import mekanism.common.MekanismUtils;
import mekanism.common.TileEntityBoundingBlock;
import net.minecraft.item.ItemStack;
import dan200.computer.api.IComputerAccess;
public class TileEntityWindTurbine extends TileEntityGenerator implements IBoundingBlock
{
public boolean canSpin;
public int angle;
public int GENERATION_RATE = 30;
public TileEntityWindTurbine()
{
super("Wind Turbine", 200000, 400);
inventory = new ItemStack[1];
}
@Override
public void onUpdate()
{
super.onUpdate();
ChargeUtils.charge(0, this);
if(!worldObj.isRemote)
{
if(canOperate())
{
setEnergy(electricityStored + (GENERATION_RATE*getMultiplier()));
}
}
}
/** 0 - 8 **/
public float getMultiplier()
{
return worldObj.canBlockSeeTheSky(xCoord, yCoord+4, zCoord) ? (((float)yCoord+4)/(float)256)*8 : 0;
}
@Override
public String[] getMethodNames()
{
return null;
}
@Override
public Object[] callMethod(IComputerAccess computer, int method, Object[] arguments) throws Exception
{
return null;
}
@Override
public int getEnvironmentBoost()
{
return (int)getMultiplier();
}
@Override
public boolean canOperate()
{
return electricityStored < MAX_ELECTRICITY && getMultiplier() > 0 && checkBounds();
}
public boolean checkBounds()
{
Object3D obj = new Object3D(xCoord, yCoord+4, zCoord);
for(int x = obj.xCoord-2; x <= obj.xCoord+2; x++)
{
for(int y = obj.yCoord-2; y <= obj.yCoord+2; y++)
{
for(int z = obj.zCoord-2; z <= obj.zCoord+2; z++)
{
if(worldObj.getBlockId(x, y, z) == 0)
{
continue;
}
if(worldObj.getBlockTileEntity(x, y, z) instanceof TileEntityBoundingBlock)
{
TileEntityBoundingBlock tileEntity = (TileEntityBoundingBlock)worldObj.getBlockTileEntity(x, y, z);
if(tileEntity.mainX == xCoord && tileEntity.mainY == yCoord && tileEntity.mainZ == zCoord)
{
continue;
}
}
return false;
}
}
}
return true;
}
@Override
public void onPlace()
{
MekanismUtils.makeBoundingBlock(worldObj, xCoord, yCoord+1, zCoord, Object3D.get(this));
MekanismUtils.makeBoundingBlock(worldObj, xCoord, yCoord+2, zCoord, Object3D.get(this));
MekanismUtils.makeBoundingBlock(worldObj, xCoord, yCoord+3, zCoord, Object3D.get(this));
MekanismUtils.makeBoundingBlock(worldObj, xCoord, yCoord+4, zCoord, Object3D.get(this));
}
@Override
public void onBreak()
{
worldObj.setBlockToAir(xCoord, yCoord+1, zCoord);
worldObj.setBlockToAir(xCoord, yCoord+2, zCoord);
worldObj.setBlockToAir(xCoord, yCoord+3, zCoord);
worldObj.setBlockToAir(xCoord, yCoord+4, zCoord);
worldObj.setBlockToAir(xCoord, yCoord, zCoord);
}
}