Some UE Tile integration
This commit is contained in:
parent
b4cc4cc925
commit
4597384813
5 changed files with 70 additions and 71 deletions
|
@ -1,47 +0,0 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package resonantinduction.base;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import cpw.mods.fml.common.network.PacketDispatcher;
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
|
||||
/**
|
||||
* @author Calclavia
|
||||
*
|
||||
*/
|
||||
public class TileEntityBase extends TileEntity
|
||||
{
|
||||
protected long ticks = 0;
|
||||
public Set<EntityPlayer> playersUsing = new HashSet<EntityPlayer>();
|
||||
public boolean doPacket = true;
|
||||
|
||||
public void initiate()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity()
|
||||
{
|
||||
super.updateEntity();
|
||||
|
||||
if (this.ticks++ == 0)
|
||||
{
|
||||
this.initiate();
|
||||
}
|
||||
|
||||
if (doPacket && !worldObj.isRemote)
|
||||
{
|
||||
for (EntityPlayer player : this.playersUsing)
|
||||
{
|
||||
PacketDispatcher.sendPacketToPlayer(this.getDescriptionPacket(), (Player) player);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,7 +4,9 @@
|
|||
package resonantinduction.battery;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
|
@ -12,12 +14,13 @@ import net.minecraft.item.ItemStack;
|
|||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import resonantinduction.PacketHandler;
|
||||
import resonantinduction.api.ITesla;
|
||||
import resonantinduction.base.IPacketReceiver;
|
||||
import resonantinduction.base.ListUtil;
|
||||
import resonantinduction.base.TileEntityBase;
|
||||
import resonantinduction.tesla.TeslaGrid;
|
||||
import universalelectricity.compatibility.TileEntityUniversalElectrical;
|
||||
import universalelectricity.core.item.IItemElectric;
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
|
||||
|
@ -28,8 +31,10 @@ import com.google.common.io.ByteArrayDataInput;
|
|||
*
|
||||
* @author AidanBrady
|
||||
*/
|
||||
public class TileEntityBattery extends TileEntityBase implements IPacketReceiver, IInventory, ITesla
|
||||
public class TileEntityBattery extends TileEntityUniversalElectrical implements IPacketReceiver, IInventory, ITesla
|
||||
{
|
||||
public Set<EntityPlayer> playersUsing = new HashSet<EntityPlayer>();
|
||||
|
||||
public SynchronizedBatteryData structure = SynchronizedBatteryData.getBase(this);
|
||||
|
||||
public SynchronizedBatteryData prevStructure;
|
||||
|
@ -104,14 +109,14 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver
|
|||
|
||||
structure.wroteInventory = false;
|
||||
structure.didTick = false;
|
||||
|
||||
if(playersUsing.size() > 0)
|
||||
|
||||
if (playersUsing.size() > 0)
|
||||
{
|
||||
updateClient();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void updateClient()
|
||||
{
|
||||
PacketHandler.sendTileEntityPacketToClients(this, getNetworkedData(new ArrayList()).toArray());
|
||||
|
@ -119,19 +124,19 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver
|
|||
|
||||
public void updateAllClients()
|
||||
{
|
||||
for(Vector3 vec : structure.locations)
|
||||
for (Vector3 vec : structure.locations)
|
||||
{
|
||||
TileEntityBattery battery = (TileEntityBattery)vec.getTileEntity(worldObj);
|
||||
TileEntityBattery battery = (TileEntityBattery) vec.getTileEntity(worldObj);
|
||||
PacketHandler.sendTileEntityPacketToClients(battery, battery.getNetworkedData(new ArrayList()).toArray());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void validate()
|
||||
{
|
||||
super.validate();
|
||||
|
||||
if(worldObj.isRemote)
|
||||
|
||||
if (worldObj.isRemote)
|
||||
{
|
||||
PacketHandler.sendDataRequest(this);
|
||||
}
|
||||
|
@ -562,4 +567,16 @@ public class TileEntityBattery extends TileEntityBase implements IPacketReceiver
|
|||
{
|
||||
return this.getMaxEnergyStored() - this.getEnergyStored() > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getRequest(ForgeDirection direction)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getProvide(ForgeDirection direction)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,9 +22,9 @@ import resonantinduction.PacketHandler;
|
|||
import resonantinduction.ResonantInduction;
|
||||
import resonantinduction.base.IPacketReceiver;
|
||||
import resonantinduction.base.InventoryUtil;
|
||||
import resonantinduction.base.TileEntityBase;
|
||||
import resonantinduction.tesla.TileEntityTesla;
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
import universalelectricity.prefab.tile.TileEntityAdvanced;
|
||||
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
|
||||
|
@ -33,7 +33,7 @@ import com.google.common.io.ByteArrayDataInput;
|
|||
* @author AidanBrady
|
||||
*
|
||||
*/
|
||||
public class TileEntityEMContractor extends TileEntityBase implements IPacketReceiver
|
||||
public class TileEntityEMContractor extends TileEntityAdvanced implements IPacketReceiver
|
||||
{
|
||||
public static int MAX_REACH = 40;
|
||||
public static int PUSH_DELAY = 5;
|
||||
|
|
|
@ -4,7 +4,10 @@
|
|||
package resonantinduction.multimeter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.packet.Packet;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
@ -12,18 +15,23 @@ import net.minecraftforge.common.ForgeDirection;
|
|||
import resonantinduction.PacketHandler;
|
||||
import resonantinduction.ResonantInduction;
|
||||
import resonantinduction.base.IPacketReceiver;
|
||||
import resonantinduction.base.TileEntityBase;
|
||||
import resonantinduction.battery.TileEntityBattery;
|
||||
import resonantinduction.tesla.TileEntityTesla;
|
||||
import universalelectricity.prefab.tile.TileEntityAdvanced;
|
||||
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
|
||||
import cpw.mods.fml.common.network.PacketDispatcher;
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
|
||||
/**
|
||||
* @author Calclavia
|
||||
*
|
||||
*/
|
||||
public class TileEntityMultimeter extends TileEntityBase implements IPacketReceiver
|
||||
public class TileEntityMultimeter extends TileEntityAdvanced implements IPacketReceiver
|
||||
{
|
||||
public Set<EntityPlayer> playersUsing = new HashSet<EntityPlayer>();
|
||||
|
||||
public enum DetectMode
|
||||
{
|
||||
NONE("None"), LESS_THAN("Less Than"), LESS_THAN_EQUAL("Less Than or Equal"),
|
||||
|
@ -90,6 +98,14 @@ public class TileEntityMultimeter extends TileEntityBase implements IPacketRecei
|
|||
this.worldObj.markBlockForUpdate(this.xCoord, this.yCoord, this.zCoord);
|
||||
}
|
||||
}
|
||||
|
||||
if (!this.worldObj.isRemote)
|
||||
{
|
||||
for (EntityPlayer player : this.playersUsing)
|
||||
{
|
||||
PacketDispatcher.sendPacketToPlayer(this.getDescriptionPacket(), (Player) player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -20,12 +20,13 @@ import net.minecraft.tileentity.TileEntity;
|
|||
import net.minecraft.tileentity.TileEntityFurnace;
|
||||
import net.minecraft.util.DamageSource;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import resonantinduction.PacketHandler;
|
||||
import resonantinduction.ResonantInduction;
|
||||
import resonantinduction.api.ITesla;
|
||||
import resonantinduction.base.IPacketReceiver;
|
||||
import resonantinduction.base.TileEntityBase;
|
||||
import resonantinduction.battery.TileEntityBattery;
|
||||
import universalelectricity.compatibility.TileEntityUniversalElectrical;
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
|
@ -38,14 +39,13 @@ import com.google.common.io.ByteArrayDataInput;
|
|||
* @author Calclavia
|
||||
*
|
||||
*/
|
||||
public class TileEntityTesla extends TileEntityBase implements ITesla, IPacketReceiver
|
||||
public class TileEntityTesla extends TileEntityUniversalElectrical implements ITesla, IPacketReceiver
|
||||
{
|
||||
public static final Vector3[] dyeColors = new Vector3[] { new Vector3(), new Vector3(1, 0, 0), new Vector3(0, 0.608, 0.232), new Vector3(0.9, 0.8, 0.8), new Vector3(0, 0, 1), new Vector3(0.5, 0, 05), new Vector3(0, 0.3, 1), new Vector3(0.8, 0.8, 0.8), new Vector3(0.3, 0.3, 0.3), new Vector3(1, 0.768, 0.812), new Vector3(0.616, 1, 0), new Vector3(1, 1, 0), new Vector3(0.46f, 0.932, 1), new Vector3(0.5, 0.2, 0.5), new Vector3(0.7, 0.5, 0.1), new Vector3(1, 1, 1) };
|
||||
|
||||
public final static int DEFAULT_COLOR = 12;
|
||||
public final float TRANSFER_CAP = 10;
|
||||
private int dyeID = DEFAULT_COLOR;
|
||||
private float energy = 0;
|
||||
private boolean doTransfer = false;
|
||||
|
||||
private boolean canReceive = true;
|
||||
|
@ -319,7 +319,7 @@ public class TileEntityTesla extends TileEntityBase implements ITesla, IPacketRe
|
|||
switch (input.readByte())
|
||||
{
|
||||
case 1:
|
||||
this.energy = input.readFloat();
|
||||
this.setEnergyStored(input.readFloat());
|
||||
this.dyeID = input.readInt();
|
||||
this.canReceive = input.readBoolean();
|
||||
this.attackEntities = input.readBoolean();
|
||||
|
@ -353,7 +353,7 @@ public class TileEntityTesla extends TileEntityBase implements ITesla, IPacketRe
|
|||
{
|
||||
if (doTransfer)
|
||||
{
|
||||
this.energy = Math.max(this.energy + transferEnergy, 0);
|
||||
this.receiveElectricity(transferEnergy, true);
|
||||
}
|
||||
|
||||
this.doTransfer = true;
|
||||
|
@ -366,11 +366,6 @@ public class TileEntityTesla extends TileEntityBase implements ITesla, IPacketRe
|
|||
}
|
||||
}
|
||||
|
||||
public float getEnergyStored()
|
||||
{
|
||||
return this.energy;
|
||||
}
|
||||
|
||||
public int getRange()
|
||||
{
|
||||
return Math.min(4 * (this.getHeight() - 1), 50);
|
||||
|
@ -563,4 +558,22 @@ public class TileEntityTesla extends TileEntityBase implements ITesla, IPacketRe
|
|||
this.linkDim = dimID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getRequest(ForgeDirection direction)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getProvide(ForgeDirection direction)
|
||||
{
|
||||
return this.getEnergyStored();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getMaxEnergyStored()
|
||||
{
|
||||
return 20;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue