After some very frustrating fixes, added Rotational Complex (with debug max rotation) and got turbines to properly rotate

This commit is contained in:
aidancbrady 2016-01-22 00:04:44 -05:00
parent 6e9ee32df1
commit bb9c203fae
8 changed files with 219 additions and 22 deletions

View file

@ -7,7 +7,7 @@ import mekanism.client.sound.SoundHandler;
import mekanism.client.voice.VoiceClient;
import mekanism.common.Mekanism;
import mekanism.common.network.PacketKey.KeyMessage;
import mekanism.generators.common.tile.turbine.TileEntityRotationalComplex;
import net.minecraft.client.Minecraft;
import net.minecraft.client.settings.KeyBinding;
import net.minecraftforge.common.MinecraftForge;
@ -49,6 +49,8 @@ public class MekanismClient extends Mekanism
Mekanism.gasmaskOn.clear();
Mekanism.flamethrowerActive.clear();
Mekanism.activeVibrators.clear();
TileEntityRotationalComplex.clientRotationMap.clear();
SoundHandler.soundMaps.clear();

View file

@ -1,13 +1,16 @@
package mekanism.generators.client.render;
import org.lwjgl.opengl.GL11;
import mekanism.common.Mekanism;
import mekanism.common.util.MekanismUtils;
import mekanism.common.util.MekanismUtils.ResourceType;
import mekanism.generators.client.model.ModelTurbine;
import mekanism.generators.common.tile.turbine.TileEntityRotationalComplex;
import mekanism.generators.common.tile.turbine.TileEntityTurbineRod;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import org.lwjgl.opengl.GL11;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@ -15,6 +18,8 @@ import cpw.mods.fml.relauncher.SideOnly;
public class RenderTurbineRod extends TileEntitySpecialRenderer
{
private ModelTurbine model = new ModelTurbine();
private static final float BASE_SPEED = 512F;
@Override
public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float partialTick)
@ -28,16 +33,36 @@ public class RenderTurbineRod extends TileEntitySpecialRenderer
bindTexture(MekanismUtils.getResource(ResourceType.RENDER, "Turbine.png"));
int baseIndex = tileEntity.clientIndex*2;
float rotateSpeed = 0.0F;
if(tileEntity.multiblockUUID != null && TileEntityRotationalComplex.clientRotationMap.containsKey(tileEntity.multiblockUUID))
{
rotateSpeed = TileEntityRotationalComplex.clientRotationMap.get(tileEntity.multiblockUUID);
}
if(!Mekanism.proxy.isPaused())
{
tileEntity.rotationLower = (tileEntity.rotationLower + rotateSpeed*BASE_SPEED*(1F/(float)(baseIndex+1))) % 360;
tileEntity.rotationUpper = (tileEntity.rotationUpper + rotateSpeed*BASE_SPEED*(1F/(float)(baseIndex+2))) % 360;
}
if(tileEntity.getHousedBlades() > 0)
{
GL11.glPushMatrix();
GL11.glTranslated(x + 0.5, y - 1, z + 0.5);
model.render(0.0625F, tileEntity.clientIndex*2);
GL11.glRotatef(tileEntity.rotationLower, 0.0F, 1.0F, 0.0F);
model.render(0.0625F, baseIndex);
GL11.glPopMatrix();
}
if(tileEntity.getHousedBlades() == 2)
{
GL11.glTranslatef(0.0F, 0.5F, 0.0F);
model.render(0.0625F, (tileEntity.clientIndex*2)+1);
GL11.glPushMatrix();
GL11.glTranslated(x + 0.5, y - 0.5, z + 0.5);
GL11.glRotatef(tileEntity.rotationUpper, 0.0F, 1.0F, 0.0F);
model.render(0.0625F, baseIndex+1);
GL11.glPopMatrix();
}
GL11.glPopMatrix();

View file

@ -24,6 +24,7 @@ import mekanism.generators.common.tile.reactor.TileEntityReactorLaserFocusMatrix
import mekanism.generators.common.tile.reactor.TileEntityReactorLogicAdapter;
import mekanism.generators.common.tile.reactor.TileEntityReactorNeutronCapture;
import mekanism.generators.common.tile.reactor.TileEntityReactorPort;
import mekanism.generators.common.tile.turbine.TileEntityRotationalComplex;
import mekanism.generators.common.tile.turbine.TileEntityTurbineRod;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
@ -52,6 +53,7 @@ public class GeneratorsCommonProxy
GameRegistry.registerTileEntity(TileEntityReactorNeutronCapture.class, "ReactorNeutronCapture");
GameRegistry.registerTileEntity(TileEntityReactorPort.class, "ReactorPort");
GameRegistry.registerTileEntity(TileEntityReactorLogicAdapter.class, "ReactorLogicAdapter");
GameRegistry.registerTileEntity(TileEntityRotationalComplex.class, "RotationalComplex");
}
/**

View file

@ -27,6 +27,7 @@ import mekanism.generators.common.tile.TileEntityGasGenerator;
import mekanism.generators.common.tile.TileEntityHeatGenerator;
import mekanism.generators.common.tile.TileEntitySolarGenerator;
import mekanism.generators.common.tile.TileEntityWindGenerator;
import mekanism.generators.common.tile.turbine.TileEntityRotationalComplex;
import mekanism.generators.common.tile.turbine.TileEntityTurbineRod;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
@ -59,6 +60,7 @@ import cpw.mods.fml.relauncher.SideOnly;
* 5: Advanced Solar Generator
* 6: Wind Generator
* 7: Turbine Rod
* 8: Rotational Complex
* @author AidanBrady
*
*/
@ -83,6 +85,7 @@ public class BlockGenerator extends BlockContainer implements ISpecialBounds
{
BASE_ICON = register.registerIcon("mekanism:SteelCasing");
icons[7][0] = register.registerIcon("mekanism:TurbineRod");
icons[8][0] = register.registerIcon("mekanism:TurbineRod");
}
@Override
@ -93,6 +96,10 @@ public class BlockGenerator extends BlockContainer implements ISpecialBounds
{
return icons[meta][0];
}
else if(meta == GeneratorType.ROTATIONAL_COMPLEX.meta)
{
return icons[meta][0];
}
return BASE_ICON;
}
@ -652,7 +659,8 @@ public class BlockGenerator extends BlockContainer implements ISpecialBounds
BIO_GENERATOR(4, "BioGenerator", 4, 160000, TileEntityBioGenerator.class, true),
ADVANCED_SOLAR_GENERATOR(5, "AdvancedSolarGenerator", 1, 200000, TileEntityAdvancedSolarGenerator.class, true),
WIND_GENERATOR(6, "WindGenerator", 5, 200000, TileEntityWindGenerator.class, true),
TURBINE_ROD(7, "TurbineRod", -1, -1, TileEntityTurbineRod.class, false);
TURBINE_ROD(7, "TurbineRod", -1, -1, TileEntityTurbineRod.class, false),
ROTATIONAL_COMPLEX(8, "RotationalComplex", -1, -1, TileEntityRotationalComplex.class, false);
public int meta;
public String name;

View file

@ -47,6 +47,7 @@ import cpw.mods.fml.relauncher.SideOnly;
* 5: Advanced Solar Generator
* 6: Wind Generator
* 7: Turbine Rod
* 8: Rotational Complex
* @author AidanBrady
*
*/
@ -96,7 +97,7 @@ public class ItemBlockGenerator extends ItemBlock implements IEnergizedItem, ISp
{
GeneratorType type = GeneratorType.getFromMetadata(itemstack.getItemDamage());
if(type != GeneratorType.TURBINE_ROD)
if(type != GeneratorType.TURBINE_ROD && type != GeneratorType.ROTATIONAL_COMPLEX)
{
if(!MekKeyHandler.getIsKeyPressed(MekanismKeyHandler.sneakKey))
{

View file

@ -0,0 +1,105 @@
package mekanism.generators.common.tile.turbine;
import io.netty.buffer.ByteBuf;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import mekanism.api.Coord4D;
import mekanism.api.Range4D;
import mekanism.common.Mekanism;
import mekanism.common.PacketHandler;
import mekanism.common.network.PacketTileEntity.TileEntityMessage;
import mekanism.common.tile.TileEntityBasicBlock;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
public class TileEntityRotationalComplex extends TileEntityBasicBlock
{
public static Map<String, Float> clientRotationMap = new HashMap<String, Float>();
public static final float ROTATION_THRESHOLD = 0.01F;
public String multiblockUUID;
public float rotation;
@Override
public void onUpdate() {}
@Override
public boolean canUpdate()
{
return false;
}
@Override
public void onAdded()
{
super.onAdded();
if(!worldObj.isRemote)
{
setMultiblock("asdf");
setRotation(1F);
}
}
@Override
public void handlePacketData(ByteBuf dataStream)
{
super.handlePacketData(dataStream);
rotation = dataStream.readFloat();
if(dataStream.readBoolean())
{
multiblockUUID = PacketHandler.readString(dataStream);
clientRotationMap.put(multiblockUUID, rotation);
}
else {
multiblockUUID = null;
}
}
@Override
public ArrayList getNetworkedData(ArrayList data)
{
super.getNetworkedData(data);
data.add(rotation);
if(multiblockUUID != null)
{
data.add(true);
data.add(multiblockUUID);
}
else {
data.add(false);
}
return data;
}
public void setMultiblock(String id)
{
multiblockUUID = id;
Coord4D coord = Coord4D.get(this).getFromSide(ForgeDirection.DOWN);
TileEntity tile = coord.getTileEntity(worldObj);
if(tile instanceof TileEntityTurbineRod)
{
((TileEntityTurbineRod)tile).updateRods();
}
}
public void setRotation(float newRotation)
{
if(Math.abs(newRotation-rotation) > ROTATION_THRESHOLD)
{
rotation = newRotation;
Mekanism.packetHandler.sendToReceivers(new TileEntityMessage(Coord4D.get(this), getNetworkedData(new ArrayList())), new Range4D(Coord4D.get(this)));
}
}
}

View file

@ -8,6 +8,7 @@ import java.util.List;
import mekanism.api.Coord4D;
import mekanism.api.Range4D;
import mekanism.common.Mekanism;
import mekanism.common.PacketHandler;
import mekanism.common.network.PacketTileEntity.TileEntityMessage;
import mekanism.common.tile.TileEntityBasicBlock;
import net.minecraft.block.Block;
@ -21,11 +22,19 @@ public class TileEntityTurbineRod extends TileEntityBasicBlock
{
public List<Coord4D> rods = new ArrayList<Coord4D>();
public boolean hasComplex;
public String multiblockUUID;
//Total blades on server, housed blades on client
public int blades = 0;
//Client stuff
public int clientIndex;
public float rotationLower;
public float rotationUpper;
@Override
public boolean canUpdate()
{
@ -41,28 +50,23 @@ public class TileEntityTurbineRod extends TileEntityBasicBlock
}
}
private void updateRods()
public void updateRods()
{
Coord4D current = Coord4D.get(this);
Coord4D up = current.getFromSide(ForgeDirection.UP);
Coord4D down = current.getFromSide(ForgeDirection.DOWN);
if(!rods.contains(current))
if(rods.contains(Coord4D.get(this)))
{
rods.add(current);
rods.add(Coord4D.get(this));
}
if((isRod(up) != !rods.contains(up)) || (isRod(down) != !rods.contains(down)))
{
buildRods();
Mekanism.packetHandler.sendToReceivers(new TileEntityMessage(Coord4D.get(this), getNetworkedData(new ArrayList())), new Range4D(Coord4D.get(this)));
}
buildRods();
Mekanism.packetHandler.sendToReceivers(new TileEntityMessage(Coord4D.get(this), getNetworkedData(new ArrayList())), new Range4D(Coord4D.get(this)));
}
private void buildRods()
{
List<Coord4D> newRods = new ArrayList<Coord4D>();
int newBlades = 0;
boolean complex = false;
String id = null;
Coord4D pointer = Coord4D.get(this);
@ -93,6 +97,12 @@ public class TileEntityTurbineRod extends TileEntityBasicBlock
break;
}
if(isComplex(pointer.getFromSide(ForgeDirection.UP)))
{
id = ((TileEntityRotationalComplex)pointer.getFromSide(ForgeDirection.UP).getTileEntity(worldObj)).multiblockUUID;
complex = true;
}
//Update all rods, send packet if necessary
for(Coord4D coord : newRods)
{
@ -102,16 +112,27 @@ public class TileEntityTurbineRod extends TileEntityBasicBlock
rod.rods = newRods;
rod.blades = newBlades;
rod.multiblockUUID = id;
if(rod.getHousedBlades() != prevHoused || rod.blades != prevBlades)
if(rods.indexOf(coord) == rods.size()-1)
{
Mekanism.packetHandler.sendToReceivers(new TileEntityMessage(coord, rod.getNetworkedData(new ArrayList())), new Range4D(coord));
rod.hasComplex = complex;
}
else {
rod.hasComplex = false;
}
Mekanism.packetHandler.sendToReceivers(new TileEntityMessage(coord, rod.getNetworkedData(new ArrayList())), new Range4D(coord));
}
}
public boolean editBlade(boolean add)
{
if(!rods.contains(Coord4D.get(this)))
{
rods.add(Coord4D.get(this));
}
if((add && (rods.size()*2) - blades > 0) || (!add && (blades > 0)))
{
for(Coord4D coord : rods)
@ -161,6 +182,11 @@ public class TileEntityTurbineRod extends TileEntityBasicBlock
return coord.getTileEntity(worldObj) instanceof TileEntityTurbineRod;
}
private boolean isComplex(Coord4D coord)
{
return coord.getTileEntity(worldObj) instanceof TileEntityRotationalComplex;
}
@Override
public void onChunkLoad()
{
@ -177,8 +203,25 @@ public class TileEntityTurbineRod extends TileEntityBasicBlock
{
super.handlePacketData(dataStream);
int prevBlades = blades;
int prevIndex = clientIndex;
blades = dataStream.readInt();
clientIndex = dataStream.readInt();
if(dataStream.readBoolean())
{
multiblockUUID = PacketHandler.readString(dataStream);
}
else {
multiblockUUID = null;
}
if(prevBlades != blades || prevIndex != clientIndex)
{
rotationLower = 0;
rotationUpper = 0;
}
}
@Override
@ -189,6 +232,15 @@ public class TileEntityTurbineRod extends TileEntityBasicBlock
data.add(getHousedBlades());
data.add(rods.indexOf(Coord4D.get(this)));
if(multiblockUUID != null)
{
data.add(true);
data.add(multiblockUUID);
}
else {
data.add(false);
}
return data;
}

View file

@ -736,6 +736,7 @@ tooltip.BioGenerator=A generator that burns organic materials of !nthe world to
tooltip.AdvancedSolarGenerator=An advanced generator that directly !nabsorbs the sun's rays with little loss !nto produce energy.
tooltip.WindGenerator=A generator that uses the strength of the wind !nto produce energy, with greater efficiency !nat higher levels.
tooltip.TurbineRod=The steel rod that is used to house !nTurbine Blades within an Industrial Turbine.
tooltip.RotationalComplex=A connector that is placed on !nthe highest turbine rod to carry kinetic energy into the !ngenerator itself.
tooltip.ReactorGlass=Reinforced glass that can be used in !nthe Fusion Reactor multiblock.
tooltip.ReactorLaserFocusMatrix=A panel of Reactor Glass that !nis capable of absorbing optical energy and !nthereby heating up the Fusion Reactor.
@ -848,6 +849,7 @@ tile.Generator.BioGenerator.name=Bio-Generator
tile.Generator.AdvancedSolarGenerator.name=Advanced Solar Generator
tile.Generator.WindGenerator.name=Wind Generator
tile.Generator.TurbineRod.name=Turbine Rod
tile.Generator.RotationalComplex.name=Rotational Complex
tile.Reactor.ReactorController.name=Reactor Controller
tile.Reactor.ReactorFrame.name=Reactor Frame