Turbines now render and look fancy, fixed some multiblock code

This commit is contained in:
aidancbrady 2016-01-21 20:36:40 -05:00
parent 51c9ca061c
commit 6e9ee32df1
10 changed files with 198 additions and 55 deletions

View file

@ -8,8 +8,8 @@ import java.util.Map;
import mekanism.api.Coord4D;
import mekanism.common.multiblock.MultiblockCache;
import mekanism.common.multiblock.MultiblockManager;
import mekanism.common.tile.TileEntityThermoelectricBoiler;
import mekanism.common.tile.TileEntityMultiblock;
import mekanism.common.tile.TileEntityThermoelectricBoiler;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
@ -25,12 +25,12 @@ public class BoilerManager extends MultiblockManager<SynchronizedBoilerData>
public void tickSelf(World world)
{
ArrayList<Integer> idsToKill = new ArrayList<Integer>();
HashMap<Integer, HashSet<Coord4D>> tilesToKill = new HashMap<Integer, HashSet<Coord4D>>();
ArrayList<String> idsToKill = new ArrayList<String>();
HashMap<String, HashSet<Coord4D>> tilesToKill = new HashMap<String, HashSet<Coord4D>>();
for(Map.Entry<Integer, MultiblockCache<SynchronizedBoilerData>> entry : inventories.entrySet())
for(Map.Entry<String, MultiblockCache<SynchronizedBoilerData>> entry : inventories.entrySet())
{
int inventoryID = entry.getKey();
String inventoryID = entry.getKey();
HashSet<TileEntityThermoelectricBoiler> boilers = new HashSet<TileEntityThermoelectricBoiler>();
@ -40,7 +40,7 @@ public class BoilerManager extends MultiblockManager<SynchronizedBoilerData>
{
TileEntity tileEntity = obj.getTileEntity(world);
if(!(tileEntity instanceof TileEntityMultiblock) || ((TileEntityMultiblock)tileEntity).getManager() != this || (getStructureId(((TileEntityMultiblock<?>)tileEntity)) != -1 && getStructureId(((TileEntityMultiblock)tileEntity)) != inventoryID))
if(!(tileEntity instanceof TileEntityMultiblock) || ((TileEntityMultiblock)tileEntity).getManager() != this || (getStructureId(((TileEntityMultiblock<?>)tileEntity)) != null && getStructureId(((TileEntityMultiblock)tileEntity)) != inventoryID))
{
if(!tilesToKill.containsKey(inventoryID))
{
@ -78,7 +78,7 @@ public class BoilerManager extends MultiblockManager<SynchronizedBoilerData>
}
}
for(Map.Entry<Integer, HashSet<Coord4D>> entry : tilesToKill.entrySet())
for(Map.Entry<String, HashSet<Coord4D>> entry : tilesToKill.entrySet())
{
for(Coord4D obj : entry.getValue())
{
@ -86,7 +86,7 @@ public class BoilerManager extends MultiblockManager<SynchronizedBoilerData>
}
}
for(int inventoryID : idsToKill)
for(String inventoryID : idsToKill)
{
inventories.remove(inventoryID);
}

View file

@ -5,6 +5,7 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import mekanism.api.Coord4D;
import mekanism.common.tile.TileEntityMultiblock;
@ -18,7 +19,7 @@ public class MultiblockManager<T extends SynchronizedData<T>>
public String name;
/** A map containing references to all multiblock inventory caches. */
public Map<Integer, MultiblockCache<T>> inventories = new HashMap<Integer, MultiblockCache<T>>();
public Map<String, MultiblockCache<T>> inventories = new HashMap<String, MultiblockCache<T>>();
public MultiblockManager(String s)
{
@ -32,7 +33,7 @@ public class MultiblockManager<T extends SynchronizedData<T>>
* @param id - inventory ID to pull
* @return correct multiblock inventory cache
*/
public MultiblockCache<T> pullInventory(World world, int id)
public MultiblockCache<T> pullInventory(World world, String id)
{
MultiblockCache<T> toReturn = inventories.get(id);
@ -43,7 +44,7 @@ public class MultiblockManager<T extends SynchronizedData<T>>
if(tileEntity != null)
{
tileEntity.cachedData = tileEntity.getNewCache();
tileEntity.cachedID = -1;
tileEntity.cachedID = null;
}
}
@ -56,23 +57,9 @@ public class MultiblockManager<T extends SynchronizedData<T>>
* Grabs a unique inventory ID for a multiblock.
* @return unique inventory ID
*/
public int getUniqueInventoryID()
public String getUniqueInventoryID()
{
int id = 0;
while(true)
{
for(Integer i : inventories.keySet())
{
if(id == i)
{
id++;
continue;
}
}
return id;
}
return UUID.randomUUID().toString();
}
public static void tick(World world)
@ -85,12 +72,12 @@ public class MultiblockManager<T extends SynchronizedData<T>>
public void tickSelf(World world)
{
ArrayList<Integer> idsToKill = new ArrayList<Integer>();
HashMap<Integer, HashSet<Coord4D>> tilesToKill = new HashMap<Integer, HashSet<Coord4D>>();
ArrayList<String> idsToKill = new ArrayList<String>();
HashMap<String, HashSet<Coord4D>> tilesToKill = new HashMap<String, HashSet<Coord4D>>();
for(Map.Entry<Integer, MultiblockCache<T>> entry : inventories.entrySet())
for(Map.Entry<String, MultiblockCache<T>> entry : inventories.entrySet())
{
int inventoryID = entry.getKey();
String inventoryID = entry.getKey();
for(Coord4D obj : entry.getValue().locations)
{
@ -98,7 +85,7 @@ public class MultiblockManager<T extends SynchronizedData<T>>
{
TileEntity tileEntity = obj.getTileEntity(world);
if(!(tileEntity instanceof TileEntityMultiblock) || ((TileEntityMultiblock)tileEntity).getManager() != this || (getStructureId(((TileEntityMultiblock<?>)tileEntity)) != -1 && getStructureId(((TileEntityMultiblock)tileEntity)) != inventoryID))
if(!(tileEntity instanceof TileEntityMultiblock) || ((TileEntityMultiblock)tileEntity).getManager() != this || (getStructureId(((TileEntityMultiblock<?>)tileEntity)) != null && getStructureId(((TileEntityMultiblock)tileEntity)) != inventoryID))
{
if(!tilesToKill.containsKey(inventoryID))
{
@ -116,7 +103,7 @@ public class MultiblockManager<T extends SynchronizedData<T>>
}
}
for(Map.Entry<Integer, HashSet<Coord4D>> entry : tilesToKill.entrySet())
for(Map.Entry<String, HashSet<Coord4D>> entry : tilesToKill.entrySet())
{
for(Coord4D obj : entry.getValue())
{
@ -124,15 +111,15 @@ public class MultiblockManager<T extends SynchronizedData<T>>
}
}
for(int inventoryID : idsToKill)
for(String inventoryID : idsToKill)
{
inventories.remove(inventoryID);
}
}
public static int getStructureId(TileEntityMultiblock<?> tile)
public static String getStructureId(TileEntityMultiblock<?> tile)
{
return tile.structure != null ? tile.getSynchronizedData().inventoryID : -1;
return tile.structure != null ? tile.getSynchronizedData().inventoryID : null;
}
public static boolean areEqual(TileEntity tile1, TileEntity tile2)

View file

@ -19,7 +19,7 @@ public abstract class SynchronizedData<T extends SynchronizedData<T>>
public int volume;
public int inventoryID;
public String inventoryID;
public boolean didTick;

View file

@ -405,14 +405,14 @@ public abstract class UpdateProtocol<T extends SynchronizedData<T>>
}
}
List<Integer> idsFound = new ArrayList<Integer>();
int idToUse = -1;
List<String> idsFound = new ArrayList<String>();
String idToUse = null;
for(Coord4D obj : structureFound.locations)
{
TileEntityMultiblock<T> tileEntity = (TileEntityMultiblock<T>)obj.getTileEntity(pointer.getWorldObj());
if(tileEntity.cachedID != -1)
if(tileEntity.cachedID != null)
{
idsFound.add(tileEntity.cachedID);
}
@ -423,7 +423,7 @@ public abstract class UpdateProtocol<T extends SynchronizedData<T>>
if(!idsFound.isEmpty())
{
for(int id : idsFound)
for(String id : idsFound)
{
if(getManager().inventories.get(id) != null)
{

View file

@ -42,7 +42,7 @@ public abstract class TileEntityMultiblock<T extends SynchronizedData<T>> extend
public MultiblockCache cachedData = getNewCache();
/** This multiblock segment's cached inventory ID */
public int cachedID = -1;
public String cachedID = null;
public TileEntityMultiblock(String name)
{
@ -84,7 +84,7 @@ public abstract class TileEntityMultiblock<T extends SynchronizedData<T>> extend
{
isRendering = false;
if(cachedID != -1)
if(cachedID != null)
{
getManager().updateCache(this);
}
@ -123,7 +123,7 @@ public abstract class TileEntityMultiblock<T extends SynchronizedData<T>> extend
{
getSynchronizedData().didTick = false;
if(getSynchronizedData().inventoryID != -1)
if(getSynchronizedData().inventoryID != null)
{
cachedData.sync(getSynchronizedData());
cachedID = getSynchronizedData().inventoryID;
@ -233,10 +233,9 @@ public abstract class TileEntityMultiblock<T extends SynchronizedData<T>> extend
if(structure == null)
{
cachedID = nbtTags.getInteger("cachedID");
if(cachedID != -1)
if(nbtTags.hasKey("cachedID"))
{
cachedID = nbtTags.getString("cachedID");
cachedData.load(nbtTags);
}
}
@ -247,10 +246,9 @@ public abstract class TileEntityMultiblock<T extends SynchronizedData<T>> extend
{
super.writeToNBT(nbtTags);
nbtTags.setInteger("cachedID", cachedID);
if(cachedID != -1)
if(cachedID != null)
{
nbtTags.setString("cachedID", cachedID);
cachedData.save(nbtTags);
}
}

View file

@ -0,0 +1,115 @@
package mekanism.generators.client.model;
import org.lwjgl.opengl.GL11;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.entity.Entity;
public class ModelTurbine extends ModelBase
{
private static float BLADE_ROTATE = 0.418879F;
public ModelRenderer rod;
public ModelRenderer extension_north;
public ModelRenderer blade_north;
public ModelRenderer extension_south;
public ModelRenderer extension_west;
public ModelRenderer extension_east;
public ModelRenderer blade_south;
public ModelRenderer blade_east;
public ModelRenderer blade_west;
public ModelTurbine()
{
textureWidth = 64;
textureHeight = 64;
extension_south = new ModelRenderer(this, 0, 0);
extension_south.setRotationPoint(0.0F, 20.0F, 0.0F);
extension_south.addBox(-1.0F, 0.0F, 1.0F, 2, 1, 3, 0.0F);
setRotateAngle(extension_south, 0.0F, 0.0F, -BLADE_ROTATE);
extension_west = new ModelRenderer(this, 0, 4);
extension_west.setRotationPoint(0.0F, 20.0F, 0.0F);
extension_west.addBox(-4.0F, 0.0F, -1.0F, 3, 1, 2, 0.0F);
setRotateAngle(extension_west, BLADE_ROTATE, 0.0F, 0.0F);
blade_east = new ModelRenderer(this, 10, 5);
blade_east.setRotationPoint(0.0F, 20.0F, 0.0F);
blade_east.addBox(4.0F, 0.0F, -1.5F, 4, 1, 3, 0.0F);
setRotateAngle(blade_east, -BLADE_ROTATE, 0.0F, 0.0F);
blade_north = new ModelRenderer(this, 10, 0);
blade_north.setRotationPoint(0.0F, 20.0F, 0.0F);
blade_north.addBox(-1.5F, 0.0F, -8.0F, 3, 1, 4, 0.0F);
setRotateAngle(blade_north, 0.0F, 0.0F, BLADE_ROTATE);
extension_east = new ModelRenderer(this, 0, 4);
extension_east.setRotationPoint(0.0F, 20.0F, 0.0F);
extension_east.addBox(1.0F, 0.0F, -1.0F, 3, 1, 2, 0.0F);
setRotateAngle(extension_east, -BLADE_ROTATE, 0.0F, 0.0F);
rod = new ModelRenderer(this, 0, 44);
rod.setRotationPoint(-2.0F, 8.0F, -2.0F);
rod.addBox(0.0F, 0.0F, 0.0F, 4, 16, 4, 0.0F);
blade_south = new ModelRenderer(this, 10, 0);
blade_south.setRotationPoint(0.0F, 20.0F, 0.0F);
blade_south.addBox(-1.5F, 0.0F, 4.0F, 3, 1, 4, 0.0F);
setRotateAngle(blade_south, 0.0F, 0.0F, -BLADE_ROTATE);
extension_north = new ModelRenderer(this, 0, 0);
extension_north.setRotationPoint(0.0F, 20.0F, 0.0F);
extension_north.addBox(-1.0F, 0.0F, -4.0F, 2, 1, 3, 0.0F);
setRotateAngle(extension_north, 0.0F, 0.0F, BLADE_ROTATE);
blade_west = new ModelRenderer(this, 10, 5);
blade_west.setRotationPoint(0.0F, 20.0F, 0.0F);
blade_west.addBox(-8.0F, 0.0F, -1.5F, 4, 1, 3, 0.0F);
setRotateAngle(blade_west, BLADE_ROTATE, 0.0F, 0.0F);
}
public void render(float size, int index)
{
GL11.glPushMatrix();
GL11.glRotatef(index*5, 0.0F, 1.0F, 0.0F);
float scale = index*0.5F;
float widthDiv = 16;
extension_south.render(size);
extension_west.render(size);
extension_east.render(size);
extension_north.render(size);
GL11.glPushMatrix();
GL11.glTranslatef(-0.25F, 0.0F, 0.0F);
GL11.glScalef(1.0F + scale, 1.0F, 1.0F + scale/widthDiv);
GL11.glTranslatef(0.25F, 0.0F, 0.0F);
blade_west.render(size);
GL11.glPopMatrix();
GL11.glPushMatrix();
GL11.glTranslatef(0.25F, 0.0F, 0.0F);
GL11.glScalef(1.0F + scale, 1.0F, 1.0F + scale/widthDiv);
GL11.glTranslatef(-0.25F, 0.0F, 0.0F);
blade_east.render(size);
GL11.glPopMatrix();
GL11.glPushMatrix();
GL11.glTranslatef(0.0F, 0.0F, -0.25F);
GL11.glScalef(1.0F + scale/widthDiv, 1.0F, 1.0F + scale);
GL11.glTranslatef(0.0F, 0.0F, 0.25F);
blade_north.render(size);
GL11.glPopMatrix();
GL11.glPushMatrix();
GL11.glTranslatef(0.0F, 0.0F, 0.25F);
GL11.glScalef(1.0F + scale/widthDiv, 1.0F, 1.0F + scale);
GL11.glTranslatef(0.0F, 0.0F, -0.25F);
blade_south.render(size);
GL11.glPopMatrix();
GL11.glPopMatrix();
}
public void setRotateAngle(ModelRenderer modelRenderer, float x, float y, float z)
{
modelRenderer.rotateAngleX = x;
modelRenderer.rotateAngleY = y;
modelRenderer.rotateAngleZ = z;
}
}

View file

@ -1,5 +1,11 @@
package mekanism.generators.client.render;
import org.lwjgl.opengl.GL11;
import mekanism.common.util.MekanismUtils;
import mekanism.common.util.MekanismUtils.ResourceType;
import mekanism.generators.client.model.ModelTurbine;
import mekanism.generators.common.tile.turbine.TileEntityTurbineRod;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import cpw.mods.fml.relauncher.Side;
@ -8,10 +14,32 @@ import cpw.mods.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class RenderTurbineRod extends TileEntitySpecialRenderer
{
private ModelTurbine model = new ModelTurbine();
@Override
public void renderTileEntityAt(TileEntity p_147500_1_, double p_147500_2_, double p_147500_4_, double p_147500_6_, float p_147500_8_)
public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float partialTick)
{
// TODO Auto-generated method stub
renderAModelAt((TileEntityTurbineRod)tileEntity, x, y, z, partialTick);
}
private void renderAModelAt(TileEntityTurbineRod tileEntity, double x, double y, double z, float partialTick)
{
GL11.glPushMatrix();
bindTexture(MekanismUtils.getResource(ResourceType.RENDER, "Turbine.png"));
if(tileEntity.getHousedBlades() > 0)
{
GL11.glTranslated(x + 0.5, y - 1, z + 0.5);
model.render(0.0625F, tileEntity.clientIndex*2);
}
if(tileEntity.getHousedBlades() == 2)
{
GL11.glTranslatef(0.0F, 0.5F, 0.0F);
model.render(0.0625F, (tileEntity.clientIndex*2)+1);
}
GL11.glPopMatrix();
}
}

View file

@ -12,7 +12,10 @@ import mekanism.common.network.PacketTileEntity.TileEntityMessage;
import mekanism.common.tile.TileEntityBasicBlock;
import net.minecraft.block.Block;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.AxisAlignedBB;
import net.minecraftforge.common.util.ForgeDirection;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class TileEntityTurbineRod extends TileEntityBasicBlock
{
@ -21,6 +24,8 @@ public class TileEntityTurbineRod extends TileEntityBasicBlock
//Total blades on server, housed blades on client
public int blades = 0;
public int clientIndex;
@Override
public boolean canUpdate()
{
@ -92,12 +97,13 @@ public class TileEntityTurbineRod extends TileEntityBasicBlock
for(Coord4D coord : newRods)
{
TileEntityTurbineRod rod = (TileEntityTurbineRod)coord.getTileEntity(worldObj);
int prev = rod.getHousedBlades();
int prevHoused = rod.getHousedBlades();
int prevBlades = rod.blades;
rod.rods = newRods;
rod.blades = newBlades;
if(rod.getHousedBlades() != prev)
if(rod.getHousedBlades() != prevHoused || rod.blades != prevBlades)
{
Mekanism.packetHandler.sendToReceivers(new TileEntityMessage(coord, rod.getNetworkedData(new ArrayList())), new Range4D(coord));
}
@ -172,6 +178,7 @@ public class TileEntityTurbineRod extends TileEntityBasicBlock
super.handlePacketData(dataStream);
blades = dataStream.readInt();
clientIndex = dataStream.readInt();
}
@Override
@ -179,7 +186,8 @@ public class TileEntityTurbineRod extends TileEntityBasicBlock
{
super.getNetworkedData(data);
data.add(blades);
data.add(getHousedBlades());
data.add(rods.indexOf(Coord4D.get(this)));
return data;
}
@ -199,6 +207,13 @@ public class TileEntityTurbineRod extends TileEntityBasicBlock
nbtTags.setInteger("blades", getHousedBlades());
}
@Override
@SideOnly(Side.CLIENT)
public AxisAlignedBB getRenderBoundingBox()
{
return INFINITE_EXTENT_AABB;
}
@Override
public void onUpdate() {}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 2 KiB