2015-08-29 14:33:25 +02:00
|
|
|
/*
|
|
|
|
* This file ("TileEntityBase.java") is part of the Actually Additions Mod for Minecraft.
|
|
|
|
* It is created and owned by Ellpeck and distributed
|
|
|
|
* under the Actually Additions License to be found at
|
|
|
|
* http://github.com/Ellpeck/ActuallyAdditions/blob/master/README.md
|
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
*
|
2015-11-02 20:55:19 +01:00
|
|
|
* © 2015 Ellpeck
|
2015-08-29 14:33:25 +02:00
|
|
|
*/
|
|
|
|
|
2015-03-07 12:51:28 +01:00
|
|
|
package ellpeck.actuallyadditions.tile;
|
2014-12-12 15:40:01 +01:00
|
|
|
|
2015-02-17 16:15:16 +01:00
|
|
|
import cpw.mods.fml.common.registry.GameRegistry;
|
2015-11-18 23:11:24 +01:00
|
|
|
import ellpeck.actuallyadditions.config.values.ConfigIntValues;
|
2015-12-01 17:28:50 +01:00
|
|
|
import ellpeck.actuallyadditions.network.VanillaPacketSyncer;
|
2015-03-29 15:29:05 +02:00
|
|
|
import ellpeck.actuallyadditions.util.ModUtil;
|
2015-03-07 02:23:31 +01:00
|
|
|
import net.minecraft.block.Block;
|
2015-06-15 22:06:07 +02:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
import net.minecraft.network.NetworkManager;
|
|
|
|
import net.minecraft.network.Packet;
|
|
|
|
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
|
2014-12-12 15:40:01 +01:00
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2015-03-07 02:23:31 +01:00
|
|
|
import net.minecraft.world.World;
|
2014-12-12 15:40:01 +01:00
|
|
|
|
2015-10-18 15:28:06 +02:00
|
|
|
public abstract class TileEntityBase extends TileEntity{
|
2015-06-15 22:06:07 +02:00
|
|
|
|
2015-12-03 18:40:43 +01:00
|
|
|
protected int ticksElapsed;
|
|
|
|
protected boolean isRedstonePowered;
|
2015-11-18 23:11:24 +01:00
|
|
|
|
2014-12-18 19:24:06 +01:00
|
|
|
public static void init(){
|
2015-07-01 21:32:48 +02:00
|
|
|
ModUtil.LOGGER.info("Registering TileEntities...");
|
2015-11-14 21:27:36 +01:00
|
|
|
|
2015-07-13 23:44:33 +02:00
|
|
|
GameRegistry.registerTileEntity(TileEntityCompost.class, ModUtil.MOD_ID_LOWER+":tileEntityCompost");
|
2015-10-02 16:48:01 +02:00
|
|
|
GameRegistry.registerTileEntity(TileEntityFeeder.class, ModUtil.MOD_ID_LOWER+":tileEntityFeeder");
|
|
|
|
GameRegistry.registerTileEntity(TileEntityGiantChest.class, ModUtil.MOD_ID_LOWER+":tileEntityGiantChest");
|
|
|
|
GameRegistry.registerTileEntity(TileEntityGrinder.class, ModUtil.MOD_ID_LOWER+":tileEntityGrinder");
|
|
|
|
GameRegistry.registerTileEntity(TileEntityFurnaceDouble.class, ModUtil.MOD_ID_LOWER+":tileEntityFurnaceDouble");
|
|
|
|
GameRegistry.registerTileEntity(TileEntityInputter.class, ModUtil.MOD_ID_LOWER+":tileEntityInputter");
|
|
|
|
GameRegistry.registerTileEntity(TileEntityFishingNet.class, ModUtil.MOD_ID_LOWER+":tileEntityFishingNet");
|
|
|
|
GameRegistry.registerTileEntity(TileEntityFurnaceSolar.class, ModUtil.MOD_ID_LOWER+":tileEntityFurnaceSolar");
|
|
|
|
GameRegistry.registerTileEntity(TileEntityHeatCollector.class, ModUtil.MOD_ID_LOWER+":tileEntityHeatCollector");
|
|
|
|
GameRegistry.registerTileEntity(TileEntityItemRepairer.class, ModUtil.MOD_ID_LOWER+":tileEntityRepairer");
|
|
|
|
GameRegistry.registerTileEntity(TileEntityGreenhouseGlass.class, ModUtil.MOD_ID_LOWER+":tileEntityGreenhouseGlass");
|
|
|
|
GameRegistry.registerTileEntity(TileEntityBreaker.class, ModUtil.MOD_ID_LOWER+":tileEntityBreaker");
|
|
|
|
GameRegistry.registerTileEntity(TileEntityDropper.class, ModUtil.MOD_ID_LOWER+":tileEntityDropper");
|
|
|
|
GameRegistry.registerTileEntity(TileEntityInputter.TileEntityInputterAdvanced.class, ModUtil.MOD_ID_LOWER+":tileEntityInputterAdvanced");
|
|
|
|
GameRegistry.registerTileEntity(TileEntityBreaker.TileEntityPlacer.class, ModUtil.MOD_ID_LOWER+":tileEntityPlacer");
|
|
|
|
GameRegistry.registerTileEntity(TileEntityGrinder.TileEntityGrinderDouble.class, ModUtil.MOD_ID_LOWER+":tileEntityGrinderDouble");
|
|
|
|
GameRegistry.registerTileEntity(TileEntityCanolaPress.class, ModUtil.MOD_ID_LOWER+":tileEntityCanolaPress");
|
|
|
|
GameRegistry.registerTileEntity(TileEntityFermentingBarrel.class, ModUtil.MOD_ID_LOWER+":tileEntityFermentingBarrel");
|
|
|
|
GameRegistry.registerTileEntity(TileEntityOilGenerator.class, ModUtil.MOD_ID_LOWER+":tileEntityOilGenerator");
|
|
|
|
GameRegistry.registerTileEntity(TileEntityCoalGenerator.class, ModUtil.MOD_ID_LOWER+":tileEntityCoalGenerator");
|
2015-10-10 02:58:07 +02:00
|
|
|
GameRegistry.registerTileEntity(TileEntityPhantomItemface.class, ModUtil.MOD_ID_LOWER+":tileEntityPhantomItemface");
|
|
|
|
GameRegistry.registerTileEntity(TileEntityPhantomLiquiface.class, ModUtil.MOD_ID_LOWER+":tileEntityPhantomLiquiface");
|
|
|
|
GameRegistry.registerTileEntity(TileEntityPhantomEnergyface.class, ModUtil.MOD_ID_LOWER+":tileEntityPhantomEnergyface");
|
2015-10-02 16:48:01 +02:00
|
|
|
GameRegistry.registerTileEntity(TileEntityPhantomPlacer.class, ModUtil.MOD_ID_LOWER+":tileEntityPhantomPlacer");
|
|
|
|
GameRegistry.registerTileEntity(TileEntityPhantomPlacer.TileEntityPhantomBreaker.class, ModUtil.MOD_ID_LOWER+":tileEntityPhantomBreaker");
|
|
|
|
GameRegistry.registerTileEntity(TileEntityFluidCollector.class, ModUtil.MOD_ID_LOWER+":tileEntityFluidCollector");
|
|
|
|
GameRegistry.registerTileEntity(TileEntityFluidCollector.TileEntityFluidPlacer.class, ModUtil.MOD_ID_LOWER+":tileEntityFluidPlacer");
|
|
|
|
GameRegistry.registerTileEntity(TileEntityLavaFactoryController.class, ModUtil.MOD_ID_LOWER+":tileEntityLavaFactoryController");
|
|
|
|
GameRegistry.registerTileEntity(TileEntityCoffeeMachine.class, ModUtil.MOD_ID_LOWER+":tileEntityCoffeeMachine");
|
|
|
|
GameRegistry.registerTileEntity(TileEntityPhantomBooster.class, ModUtil.MOD_ID_LOWER+":tileEntityPhantomBooster");
|
|
|
|
GameRegistry.registerTileEntity(TileEntityEnergizer.class, ModUtil.MOD_ID_LOWER+":tileEntityEnergizer");
|
|
|
|
GameRegistry.registerTileEntity(TileEntityEnervator.class, ModUtil.MOD_ID_LOWER+":tileEntityEnervator");
|
2015-07-13 23:44:33 +02:00
|
|
|
GameRegistry.registerTileEntity(TileEntityXPSolidifier.class, ModUtil.MOD_ID_LOWER+":tileEntityXPSolidifier");
|
2015-08-23 23:41:46 +02:00
|
|
|
GameRegistry.registerTileEntity(TileEntitySmileyCloud.class, ModUtil.MOD_ID_LOWER+":tileEntityCloud");
|
2015-09-30 21:03:43 +02:00
|
|
|
GameRegistry.registerTileEntity(TileEntityLeafGenerator.class, ModUtil.MOD_ID_LOWER+":tileEntityLeafGenerator");
|
2015-10-05 16:53:28 +02:00
|
|
|
GameRegistry.registerTileEntity(TileEntityDirectionalBreaker.class, ModUtil.MOD_ID_LOWER+":tileEntityDirectionalBreaker");
|
2015-10-10 02:51:06 +02:00
|
|
|
GameRegistry.registerTileEntity(TileEntityRangedCollector.class, ModUtil.MOD_ID_LOWER+":tileEntityRangedCollector");
|
2015-10-19 17:50:43 +02:00
|
|
|
GameRegistry.registerTileEntity(TileEntityLaserRelay.class, ModUtil.MOD_ID_LOWER+":tileEntityLaserRelay");
|
2015-11-14 21:27:36 +01:00
|
|
|
GameRegistry.registerTileEntity(TileEntityAtomicReconstructor.class, ModUtil.MOD_ID_LOWER+":tileEntityAtomicReconstructor");
|
2015-11-24 19:59:33 +01:00
|
|
|
GameRegistry.registerTileEntity(TileEntityBookletStand.class, ModUtil.MOD_ID_LOWER+":tileEntityBookletStand");
|
2015-12-06 02:16:52 +01:00
|
|
|
GameRegistry.registerTileEntity(TileEntityMiner.class, ModUtil.MOD_ID_LOWER+":tileEntityMiner");
|
2015-12-13 17:32:06 +01:00
|
|
|
GameRegistry.registerTileEntity(TileEntityFireworkBox.class, ModUtil.MOD_ID_LOWER+":tileEntityFireworkBox");
|
2014-12-18 19:24:06 +01:00
|
|
|
}
|
2015-03-07 02:23:31 +01:00
|
|
|
|
2015-10-18 15:28:06 +02:00
|
|
|
@Override
|
|
|
|
public final void readFromNBT(NBTTagCompound compound){
|
|
|
|
super.readFromNBT(compound);
|
2015-12-13 15:13:56 +01:00
|
|
|
this.isRedstonePowered = compound.getBoolean("Redstone");
|
2015-10-18 15:28:06 +02:00
|
|
|
this.readSyncableNBT(compound, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public final void writeToNBT(NBTTagCompound compound){
|
|
|
|
super.writeToNBT(compound);
|
2015-12-13 15:13:56 +01:00
|
|
|
compound.setBoolean("Redstone", this.isRedstonePowered);
|
2015-10-18 15:28:06 +02:00
|
|
|
this.writeSyncableNBT(compound, false);
|
|
|
|
}
|
|
|
|
|
2015-12-01 19:48:09 +01:00
|
|
|
@Override
|
|
|
|
public void updateEntity(){
|
|
|
|
this.ticksElapsed++;
|
2015-10-21 00:22:50 +02:00
|
|
|
}
|
2015-10-18 15:28:06 +02:00
|
|
|
|
2015-10-03 10:16:18 +02:00
|
|
|
@Override
|
|
|
|
public Packet getDescriptionPacket(){
|
|
|
|
NBTTagCompound tag = new NBTTagCompound();
|
2015-10-18 15:28:06 +02:00
|
|
|
this.writeSyncableNBT(tag, true);
|
|
|
|
return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 3, tag);
|
2015-10-03 10:16:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt){
|
2015-10-18 15:28:06 +02:00
|
|
|
this.readSyncableNBT(pkt.func_148857_g(), true);
|
2015-10-03 10:16:18 +02:00
|
|
|
}
|
|
|
|
|
2015-03-07 02:23:31 +01:00
|
|
|
@Override
|
|
|
|
public boolean shouldRefresh(Block oldBlock, Block newBlock, int oldMeta, int newMeta, World world, int x, int y, int z){
|
2015-05-07 16:36:29 +02:00
|
|
|
return !(oldBlock.isAssociatedBlock(newBlock));
|
2015-03-07 02:23:31 +01:00
|
|
|
}
|
2015-10-18 15:28:06 +02:00
|
|
|
|
2015-12-01 19:48:09 +01:00
|
|
|
public void writeSyncableNBT(NBTTagCompound compound, boolean isForSync){
|
2015-12-21 22:18:33 +01:00
|
|
|
if(this instanceof IRedstoneToggle){
|
|
|
|
compound.setBoolean("IsPulseMode", ((IRedstoneToggle)this).isPulseMode());
|
|
|
|
}
|
2015-12-01 19:48:09 +01:00
|
|
|
}
|
|
|
|
|
2015-10-21 00:22:50 +02:00
|
|
|
public void readSyncableNBT(NBTTagCompound compound, boolean isForSync){
|
2015-12-21 22:18:33 +01:00
|
|
|
if(this instanceof IRedstoneToggle){
|
|
|
|
((IRedstoneToggle)this).toggle(compound.getBoolean("IsPulseMode"));
|
|
|
|
}
|
2015-10-21 00:22:50 +02:00
|
|
|
}
|
2015-10-18 15:31:01 +02:00
|
|
|
|
2015-12-19 10:30:39 +01:00
|
|
|
public void setRedstonePowered(boolean powered){
|
|
|
|
this.isRedstonePowered = powered;
|
2015-12-25 15:24:40 +01:00
|
|
|
this.markDirty();
|
2015-12-19 10:30:39 +01:00
|
|
|
}
|
|
|
|
|
2015-12-01 17:28:50 +01:00
|
|
|
protected boolean sendUpdateWithInterval(){
|
2015-12-01 19:48:09 +01:00
|
|
|
if(this.ticksElapsed%ConfigIntValues.TILE_ENTITY_UPDATE_INTERVAL.getValue() == 0){
|
2015-12-01 17:28:50 +01:00
|
|
|
this.sendUpdate();
|
2015-11-19 22:13:52 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
return false;
|
2015-11-18 23:11:24 +01:00
|
|
|
}
|
2015-10-18 15:28:06 +02:00
|
|
|
}
|
2015-12-01 17:28:50 +01:00
|
|
|
|
|
|
|
public void sendUpdate(){
|
|
|
|
VanillaPacketSyncer.sendTileToNearbyPlayers(this);
|
|
|
|
}
|
2015-03-07 02:23:31 +01:00
|
|
|
}
|