diff --git a/src/main/java/gregtech/client/renderer/texture/custom/QuantumStorageRenderer.java b/src/main/java/gregtech/client/renderer/texture/custom/QuantumStorageRenderer.java index 03c0dd5656c..aaf8d8153c1 100644 --- a/src/main/java/gregtech/client/renderer/texture/custom/QuantumStorageRenderer.java +++ b/src/main/java/gregtech/client/renderer/texture/custom/QuantumStorageRenderer.java @@ -2,13 +2,13 @@ import gregtech.api.gui.resources.TextTexture; import gregtech.api.metatileentity.ITieredMetaTileEntity; -import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.util.TextFormattingUtil; import gregtech.client.renderer.texture.Textures; import gregtech.client.renderer.texture.cube.SimpleSidedCubeRenderer.RenderSide; import gregtech.client.utils.RenderUtil; import gregtech.common.ConfigHolder; import gregtech.common.metatileentities.storage.MetaTileEntityQuantumChest; +import gregtech.common.metatileentities.storage.MetaTileEntityQuantumStorage; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.GlStateManager; @@ -69,10 +69,10 @@ public void registerIcons(TextureMap textureMap) { .registerSprite(new ResourceLocation("gregtech:blocks/overlay/machine/overlay_screen_glass")); } - public void renderMachine(CCRenderState renderState, - Matrix4 translation, - IVertexOperation[] pipeline, - T mte) { + public & ITieredMetaTileEntity> void renderMachine(CCRenderState renderState, + Matrix4 translation, + IVertexOperation[] pipeline, + T mte) { EnumFacing frontFacing = mte.getFrontFacing(); int tier = mte.getTier(); Textures.renderFace(renderState, translation, pipeline, frontFacing, glassBox, glassTexture, @@ -81,6 +81,13 @@ public void renderMachine(CCR TextureAtlasSprite hullTexture = Textures.VOLTAGE_CASINGS[tier] .getSpriteOnSide(RenderSide.bySide(EnumFacing.NORTH)); + if (mte.isConnected()) { + var qcontroller = mte.getQuantumController(); + if (qcontroller != null) { + hullTexture = Textures.QUANTUM_CASING.getParticleSprite(); + } + } + for (var facing : boxFacingMap.keySet()) { // do not render the box at the front face when "facing" is "frontFacing" if (facing == frontFacing) continue; diff --git a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityEnergyHatch.java b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityEnergyHatch.java index 7e60b331a10..5eb9aa7f48f 100644 --- a/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityEnergyHatch.java +++ b/src/main/java/gregtech/common/metatileentities/multi/multiblockpart/MetaTileEntityEnergyHatch.java @@ -12,6 +12,7 @@ import gregtech.api.metatileentity.multiblock.IMultiblockAbilityPart; import gregtech.api.metatileentity.multiblock.MultiblockAbility; import gregtech.api.util.GTUtility; +import gregtech.client.renderer.ICubeRenderer; import gregtech.client.renderer.texture.Textures; import gregtech.client.renderer.texture.cube.SimpleOverlayRenderer; import gregtech.client.utils.PipelineUtil; @@ -19,9 +20,11 @@ import net.minecraft.client.resources.I18n; import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; +import net.minecraft.network.PacketBuffer; import net.minecraft.util.EnumFacing; import net.minecraft.util.NonNullList; import net.minecraft.util.ResourceLocation; @@ -229,12 +232,14 @@ public void onRemoval() { } @Override - public void onPlacement() { + public void onPlacement(@Nullable EntityLivingBase placer) { + super.onPlacement(placer); + if (getWorld() == null || getWorld().isRemote) + return; + // add to the network if an adjacent block is part of a network // use whatever we find first, merging networks is not supported - if (!getWorld().isRemote) { - tryFindNetwork(); - } + tryFindNetwork(); } @Override @@ -242,29 +247,67 @@ public Type getType() { return Type.ENERGY; } + @Override + public ICubeRenderer getBaseTexture() { + var qcontroller = getQuantumController(); + if (qcontroller != null) { + return Textures.QUANTUM_CASING; + } + return super.getBaseTexture(); + } + @Override public void setConnected(IQuantumController controller) { if (getWorld().isRemote) return; + if (!controller.getPos().equals(controllerPos)) { this.controller = new WeakReference<>(controller); this.controllerPos = controller.getPos(); - if (!getWorld().isRemote) { - writeCustomData(GregtechDataCodes.UPDATE_CONTROLLER_POS, buf -> buf.writeBlockPos(controllerPos)); - scheduleRenderUpdate(); - markDirty(); - } + writeCustomData(GregtechDataCodes.UPDATE_CONTROLLER_POS, buf -> buf.writeBlockPos(controllerPos)); + markDirty(); } } @Override public void setDisconnected() { - if (!getWorld().isRemote) { - controller.clear(); - controllerPos = null; - writeCustomData(GregtechDataCodes.REMOVE_CONTROLLER, buf -> {}); + if (getWorld().isRemote) return; + + controller.clear(); + controllerPos = null; + writeCustomData(GregtechDataCodes.REMOVE_CONTROLLER, buf -> {}); + tryFindNetwork(); + markDirty(); + } + + @Override + public void receiveCustomData(int dataId, PacketBuffer buf) { + super.receiveCustomData(dataId, buf); + if (dataId == GregtechDataCodes.UPDATE_CONTROLLER_POS) { + this.controllerPos = buf.readBlockPos(); + this.controller.clear(); + scheduleRenderUpdate(); + } else if (dataId == GregtechDataCodes.REMOVE_CONTROLLER) { + this.controllerPos = null; + this.controller.clear(); + scheduleRenderUpdate(); + } + } + + @Override + public void writeInitialSyncData(PacketBuffer buf) { + super.writeInitialSyncData(buf); + buf.writeBoolean(controllerPos != null); + if (controllerPos != null) { + buf.writeBlockPos(controllerPos); + } + } + + @Override + public void receiveInitialSyncData(PacketBuffer buf) { + super.receiveInitialSyncData(buf); + if (buf.readBoolean()) { + controllerPos = buf.readBlockPos(); scheduleRenderUpdate(); - tryFindNetwork(); - markDirty(); } } diff --git a/src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityQuantumStorage.java b/src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityQuantumStorage.java index 5289c567605..e8d47971ce4 100644 --- a/src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityQuantumStorage.java +++ b/src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityQuantumStorage.java @@ -15,6 +15,7 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.resources.I18n; +import net.minecraft.entity.EntityLivingBase; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -67,27 +68,24 @@ protected void renderIndicatorOverlay(CCRenderState renderState, Matrix4 transla @Override public void setConnected(IQuantumController controller) { if (getWorld().isRemote) return; + if (!controller.getPos().equals(controllerPos)) { this.controller = new WeakReference<>(controller); this.controllerPos = controller.getPos(); - if (!getWorld().isRemote) { - writeCustomData(GregtechDataCodes.UPDATE_CONTROLLER_POS, buf -> buf.writeBlockPos(controllerPos)); - scheduleRenderUpdate(); - markDirty(); - } + writeCustomData(GregtechDataCodes.UPDATE_CONTROLLER_POS, buf -> buf.writeBlockPos(controllerPos)); + markDirty(); } } @Override public void setDisconnected() { - if (!getWorld().isRemote) { - controller.clear(); - controllerPos = null; - writeCustomData(GregtechDataCodes.REMOVE_CONTROLLER, buf -> {}); - scheduleRenderUpdate(); - tryFindNetwork(); - markDirty(); - } + if (getWorld().isRemote) return; + + controller.clear(); + controllerPos = null; + writeCustomData(GregtechDataCodes.REMOVE_CONTROLLER, buf -> {}); + tryFindNetwork(); + markDirty(); } // use this to make sure controller is properly initialized @@ -128,12 +126,14 @@ public void onRemoval() { } @Override - public void onPlacement() { + public void onPlacement(@Nullable EntityLivingBase placer) { + super.onPlacement(placer); + if (getWorld() == null || getWorld().isRemote) + return; + // add to the network if an adjacent block is part of a network // use whatever we find first, merging networks is not supported - if (!getWorld().isRemote) { - tryFindNetwork(); - } + tryFindNetwork(); } private void tryFindNetwork() { diff --git a/src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityQuantumStorageController.java b/src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityQuantumStorageController.java index 58f3efd28e9..a33ccdf222c 100644 --- a/src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityQuantumStorageController.java +++ b/src/main/java/gregtech/common/metatileentities/storage/MetaTileEntityQuantumStorageController.java @@ -17,6 +17,7 @@ import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.client.resources.I18n; +import net.minecraft.entity.EntityLivingBase; import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -193,7 +194,8 @@ public void onRemoval() { } @Override - public void onPlacement() { + public void onPlacement(@Nullable EntityLivingBase placer) { + super.onPlacement(placer); rebuildNetwork(); }