diff options
Diffstat (limited to 'src/Java/miscutil/core/multiblock/base')
8 files changed, 540 insertions, 0 deletions
diff --git a/src/Java/miscutil/core/multiblock/base/BaseFakeMultiblockController.java b/src/Java/miscutil/core/multiblock/base/BaseFakeMultiblockController.java new file mode 100644 index 0000000000..e4de47267c --- /dev/null +++ b/src/Java/miscutil/core/multiblock/base/BaseFakeMultiblockController.java @@ -0,0 +1,123 @@ +package miscutil.core.multiblock.base; + +import java.util.Collection; +import java.util.Collections; +import java.util.Set; + +import javax.annotation.Nonnull; + +import miscutil.core.multiblock.base.interfaces.IBaseMultiblockControllerInternal; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.World; +import raisintoast.core.common.CoordTriplet; +import raisintoast.core.multiblock.IMultiblockPart; + +public abstract class BaseFakeMultiblockController +implements IBaseMultiblockControllerInternal +{ + @Override + public void attachBlock(IMultiblockPart part) {} + + @Override + public void detachBlock(IMultiblockPart part, boolean chunkUnloading) {} + + @Override + public void checkIfMachineIsWhole() {} + + public void assimilate(IBaseMultiblockControllerInternal other) {} + + public void _onAssimilated(IBaseMultiblockControllerInternal otherController) {} + + public void onAssimilated(IBaseMultiblockControllerInternal assimilator) {} + + @Override + public void updateMultiblockEntity() {} + + @Override + public CoordTriplet getReferenceCoord() + { + return null; + } + + @Override + public void recalculateMinMaxCoords() {} + + @Override + public void formatDescriptionPacket(NBTTagCompound data) {} + + @Override + public void decodeDescriptionPacket(NBTTagCompound data) {} + + @Override + public World getWorld() + { + return null; + } + + @Override + public boolean isEmpty() + { + return true; + } + + public boolean shouldConsume(IBaseMultiblockControllerInternal otherController) + { + return false; + } + + @Override + public String getPartsListString() + { + return ""; + } + + @Override + public void auditParts() {} + + @Override + @Nonnull + public Set<IMultiblockPart> checkForDisconnections() + { + return Collections.emptySet(); + } + + @Override + @Nonnull + public Set<IMultiblockPart> detachAllBlocks() + { + return Collections.emptySet(); + } + + @Override + public boolean isAssembled() + { + return false; + } + + @Override + public void reassemble() {} + + @Override + public String getLastValidationError() + { + return null; + } + + @Override + @Nonnull + public Collection<IMultiblockPart> getComponents() + { + return Collections.emptyList(); + } + + public void readFromNBT(NBTTagCompound nbttagcompound) { + + } + + public void writeToNBT(NBTTagCompound nbttagcompound) { + + } + + + +} diff --git a/src/Java/miscutil/core/multiblock/base/BaseMultiblockLogic.java b/src/Java/miscutil/core/multiblock/base/BaseMultiblockLogic.java new file mode 100644 index 0000000000..1812918109 --- /dev/null +++ b/src/Java/miscutil/core/multiblock/base/BaseMultiblockLogic.java @@ -0,0 +1,184 @@ +package miscutil.core.multiblock.base; + +import miscutil.core.multiblock.base.interfaces.IBaseMultiblockComponent; +import miscutil.core.multiblock.base.interfaces.IBaseMultiblockControllerInternal; +import miscutil.core.multiblock.base.interfaces.IBaseMultiblockLogic; +import miscutil.core.util.Utils; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.ChunkCoordinates; +import net.minecraft.world.World; +import raisintoast.core.multiblock.IMultiblockPart; +import raisintoast.core.multiblock.MultiblockRegistry; + +public abstract class BaseMultiblockLogic<T extends IBaseMultiblockControllerInternal> +implements IBaseMultiblockLogic +{ + private final Class<T> controllerClass; + private boolean visited; + private boolean saveMultiblockData; + private NBTTagCompound cachedMultiblockData; + protected T controller; + + protected BaseMultiblockLogic(Class<T> controllerClass) + { + this.controllerClass = controllerClass; + this.controller = null; + this.visited = false; + this.saveMultiblockData = false; + this.cachedMultiblockData = null; + } + + public void setController(T controller) + { + if (controller == null) { + this.controller = null; + } else if (this.controllerClass.isAssignableFrom(controller.getClass())) { + this.controller = (this.controllerClass.cast(controller)); + } + } + + public Class<T> getControllerClass() + { + return this.controllerClass; + } + + @Override + public abstract T getController(); + + public abstract T createNewController(World paramWorld); + + @Override + public void validate(World world, IMultiblockPart part) + { + MultiblockRegistry.onPartAdded(world, part); + } + + @Override + public final void invalidate(World world, IMultiblockPart part) + { + detachSelf(world, part, false); + } + + @Override + public final void onChunkUnload(World world, IMultiblockPart part) + { + detachSelf(world, part, true); + } + + protected void detachSelf(World world, IMultiblockPart part, boolean chunkUnloading) + { + if (this.controller != null) + { + this.controller.detachBlock(part, chunkUnloading); + + + this.controller = null; + } + MultiblockRegistry.onPartRemovedFromWorld(world, part); + } + + @Override + public void readFromNBT(NBTTagCompound data) + { + if (data.hasKey("multiblockData")) { + this.cachedMultiblockData = data.getCompoundTag("multiblockData"); + } + } + + @Override + public void writeToNBT(NBTTagCompound data) + { + if ((isMultiblockSaveDelegate()) && (isConnected())) + { + NBTTagCompound multiblockData = new NBTTagCompound(); + ((IBaseMultiblockLogic) this.controller).writeToNBT(multiblockData); + data.setTag("multiblockData", multiblockData); + } + } + + public final void assertDetached(IBaseMultiblockComponent part) + { + if (this.controller != null) + { + ChunkCoordinates coords = part.getCoordinates(); + Utils.LOG_INFO("[assert] Part @ (%d, %d, %d) should be detached already, but detected that it was not. This is not a fatal error, and will be repaired, but is unusual. " + String.valueOf(new Object[] { Integer.valueOf(coords.posX), Integer.valueOf(coords.posY), Integer.valueOf(coords.posZ) })); + this.controller = null; + } + } + + @Override + public final boolean isConnected() + { + return this.controller != null; + } + + public final void becomeMultiblockSaveDelegate() + { + this.saveMultiblockData = true; + } + + public final void forfeitMultiblockSaveDelegate() + { + this.saveMultiblockData = false; + } + + public final boolean isMultiblockSaveDelegate() + { + return this.saveMultiblockData; + } + + public final void setUnvisited() + { + this.visited = false; + } + + public final void setVisited() + { + this.visited = true; + } + + public final boolean isVisited() + { + return this.visited; + } + + public final boolean hasMultiblockSaveData() + { + return this.cachedMultiblockData != null; + } + + public final NBTTagCompound getMultiblockSaveData() + { + return this.cachedMultiblockData; + } + + public final void onMultiblockDataAssimilated() + { + this.cachedMultiblockData = null; + } + + @Override + public void encodeDescriptionPacket(NBTTagCompound packetData) + { + if ((isMultiblockSaveDelegate()) && (isConnected())) + { + NBTTagCompound tag = new NBTTagCompound(); + this.controller.formatDescriptionPacket(tag); + packetData.setTag("multiblockData", tag); + } + } + + @Override + public void decodeDescriptionPacket(NBTTagCompound packetData) + { + if (packetData.hasKey("multiblockData")) + { + NBTTagCompound tag = packetData.getCompoundTag("multiblockData"); + if (isConnected()) { + this.controller.decodeDescriptionPacket(tag); + } else { + this.cachedMultiblockData = tag; + } + } + } +} diff --git a/src/Java/miscutil/core/multiblock/base/BaseMultiblockTE.java b/src/Java/miscutil/core/multiblock/base/BaseMultiblockTE.java new file mode 100644 index 0000000000..e91ebd6143 --- /dev/null +++ b/src/Java/miscutil/core/multiblock/base/BaseMultiblockTE.java @@ -0,0 +1,100 @@ +package miscutil.core.multiblock.base; + +import miscutil.core.interfaces.IGuiManager; +import miscutil.core.multiblock.base.interfaces.IBaseMultiblockController; +import miscutil.core.multiblock.base.interfaces.IBaseMultiblockLogic; +import miscutil.core.xmod.forestry.core.interfaces.IFilterSlotDelegate; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.NetworkManager; +import net.minecraft.network.Packet; +import net.minecraft.network.play.server.S35PacketUpdateTileEntity; +import net.minecraft.util.ChunkCoordinates; +import raisintoast.core.multiblock.IMultiblockPart; + +public abstract class BaseMultiblockTE<T extends IBaseMultiblockLogic> extends IMultiblockPart implements IFilterSlotDelegate, IGuiManager +{ + private final T multiblockLogic; + + public BaseMultiblockTE(T multiblockLogic) + { + this.multiblockLogic = multiblockLogic; + } + + @Override + public ChunkCoordinates getCoordinates() + { + return new ChunkCoordinates(this.xCoord, this.yCoord, this.zCoord); + } + + public T getMultiblockLogic() + { + return this.multiblockLogic; + } + + public abstract void onMachineAssembled(IBaseMultiblockController paramIMultiblockController, ChunkCoordinates paramChunkCoordinates1, ChunkCoordinates paramChunkCoordinates2); + + @Override + public abstract void onMachineBroken(); + + @Override + public void readFromNBT(NBTTagCompound data) + { + super.readFromNBT(data); + this.multiblockLogic.readFromNBT(data); + } + + @Override + public void writeToNBT(NBTTagCompound data) + { + super.writeToNBT(data); + this.multiblockLogic.writeToNBT(data); + } + + @Override + public boolean canUpdate() + { + return false; + } + + @Override + public final void invalidate() + { + super.invalidate(); + this.multiblockLogic.invalidate(this.worldObj, this); + } + + @Override + public final void onChunkUnload() + { + super.onChunkUnload(); + this.multiblockLogic.onChunkUnload(this.worldObj, this); + } + + @Override + public final void validate() + { + super.validate(); + this.multiblockLogic.validate(this.worldObj, this); + } + + @Override + public final Packet getDescriptionPacket() + { + NBTTagCompound packetData = new NBTTagCompound(); + this.multiblockLogic.encodeDescriptionPacket(packetData); + encodeDescriptionPacket(packetData); + return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 0, packetData); + } + + @Override + public final void onDataPacket(NetworkManager network, S35PacketUpdateTileEntity packet) + { + NBTTagCompound nbtData = packet.func_148857_g(); + this.multiblockLogic.decodeDescriptionPacket(nbtData); + decodeDescriptionPacket(nbtData); + } + + protected void encodeDescriptionPacket(NBTTagCompound packetData) {} + + protected void decodeDescriptionPacket(NBTTagCompound packetData) {} +} diff --git a/src/Java/miscutil/core/multiblock/base/interfaces/IBaseMultiblockComponent.java b/src/Java/miscutil/core/multiblock/base/interfaces/IBaseMultiblockComponent.java new file mode 100644 index 0000000000..c78012662e --- /dev/null +++ b/src/Java/miscutil/core/multiblock/base/interfaces/IBaseMultiblockComponent.java @@ -0,0 +1,17 @@ +package miscutil.core.multiblock.base.interfaces; + +import net.minecraft.util.ChunkCoordinates; + +import com.mojang.authlib.GameProfile; + +public interface IBaseMultiblockComponent { + public abstract ChunkCoordinates getCoordinates(); + + public abstract GameProfile getOwner(); + + public abstract IBaseMultiblockLogic getMultiblockLogic(); + + public abstract void onMachineAssembled(IBaseMultiblockController paramIMultiblockController, ChunkCoordinates paramChunkCoordinates1, ChunkCoordinates paramChunkCoordinates2); + + public abstract void onMachineBroken(); + } diff --git a/src/Java/miscutil/core/multiblock/base/interfaces/IBaseMultiblockController.java b/src/Java/miscutil/core/multiblock/base/interfaces/IBaseMultiblockController.java new file mode 100644 index 0000000000..cd52328b03 --- /dev/null +++ b/src/Java/miscutil/core/multiblock/base/interfaces/IBaseMultiblockController.java @@ -0,0 +1,18 @@ +package miscutil.core.multiblock.base.interfaces; + +import java.util.Collection; + +import javax.annotation.Nonnull; + +import raisintoast.core.multiblock.IMultiblockPart; + +public interface IBaseMultiblockController { + public abstract boolean isAssembled(); + + public abstract void reassemble(); + + public abstract String getLastValidationError(); + + @Nonnull + public abstract Collection<IMultiblockPart> getComponents(); + }
\ No newline at end of file diff --git a/src/Java/miscutil/core/multiblock/base/interfaces/IBaseMultiblockControllerInternal.java b/src/Java/miscutil/core/multiblock/base/interfaces/IBaseMultiblockControllerInternal.java new file mode 100644 index 0000000000..9ebc9e8127 --- /dev/null +++ b/src/Java/miscutil/core/multiblock/base/interfaces/IBaseMultiblockControllerInternal.java @@ -0,0 +1,52 @@ +package miscutil.core.multiblock.base.interfaces; + +import java.util.Set; + +import javax.annotation.Nonnull; + +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.World; +import raisintoast.core.common.CoordTriplet; +import raisintoast.core.multiblock.IMultiblockPart; + +public abstract interface IBaseMultiblockControllerInternal +extends IBaseMultiblockController { + +public abstract void attachBlock(IMultiblockPart paramIMultiblockComponent); + +public abstract void detachBlock(IMultiblockPart paramIMultiblockComponent, boolean paramBoolean); + +public abstract void checkIfMachineIsWhole(); + +public abstract void assimilate(IBaseMultiblockController paramIMultiblockControllerInternal); + +public abstract void _onAssimilated(IBaseMultiblockController paramIMultiblockControllerInternal); + +public abstract void onAssimilated(IBaseMultiblockController paramIMultiblockControllerInternal); + +public abstract void updateMultiblockEntity(); + +public abstract CoordTriplet getReferenceCoord(); + +public abstract void recalculateMinMaxCoords(); + +public abstract void formatDescriptionPacket(NBTTagCompound paramNBTTagCompound); + +public abstract void decodeDescriptionPacket(NBTTagCompound paramNBTTagCompound); + +public abstract World getWorld(); + +public abstract boolean isEmpty(); + +public abstract boolean shouldConsume(IBaseMultiblockController paramIMultiblockControllerInternal); + +public abstract String getPartsListString(); + +public abstract void auditParts(); + +@Nonnull +public abstract Set<IMultiblockPart> checkForDisconnections(); + +@Nonnull +public abstract Set<IMultiblockPart> detachAllBlocks(); +} diff --git a/src/Java/miscutil/core/multiblock/base/interfaces/IBaseMultiblockLogic.java b/src/Java/miscutil/core/multiblock/base/interfaces/IBaseMultiblockLogic.java new file mode 100644 index 0000000000..4bc7e5b56f --- /dev/null +++ b/src/Java/miscutil/core/multiblock/base/interfaces/IBaseMultiblockLogic.java @@ -0,0 +1,27 @@ +package miscutil.core.multiblock.base.interfaces; + +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.World; +import raisintoast.core.multiblock.IMultiblockPart; + +public interface IBaseMultiblockLogic { + + public abstract boolean isConnected(); + + public abstract IBaseMultiblockController getController(); + + public abstract void validate(World paramWorld, IMultiblockPart paramIMultiblockComponent); + + public abstract void invalidate(World paramWorld, IMultiblockPart paramIMultiblockComponent); + + public abstract void onChunkUnload(World paramWorld, IMultiblockPart paramIMultiblockComponent); + + public abstract void encodeDescriptionPacket(NBTTagCompound paramNBTTagCompound); + + public abstract void decodeDescriptionPacket(NBTTagCompound paramNBTTagCompound); + + public abstract void readFromNBT(NBTTagCompound paramNBTTagCompound); + + public abstract void writeToNBT(NBTTagCompound paramNBTTagCompound); + +} diff --git a/src/Java/miscutil/core/multiblock/base/interfaces/IBaseMultiblockSizeLimits.java b/src/Java/miscutil/core/multiblock/base/interfaces/IBaseMultiblockSizeLimits.java new file mode 100644 index 0000000000..ca266c2cc9 --- /dev/null +++ b/src/Java/miscutil/core/multiblock/base/interfaces/IBaseMultiblockSizeLimits.java @@ -0,0 +1,19 @@ +package miscutil.core.multiblock.base.interfaces; + +public abstract interface IBaseMultiblockSizeLimits { + + public abstract int getMinNumberOfBlocksForAssembledMachine(); + + public abstract int getMaxXSize(); + + public abstract int getMaxZSize(); + + public abstract int getMaxYSize(); + + public abstract int getMinXSize(); + + public abstract int getMinYSize(); + + public abstract int getMinZSize(); + + }
\ No newline at end of file |