Skip to content

Commit

Permalink
fix rebase + use casing texture when connected
Browse files Browse the repository at this point in the history
  • Loading branch information
ghzdude committed Sep 12, 2024
1 parent ee5ad42 commit 449f94e
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -69,10 +69,10 @@ public void registerIcons(TextureMap textureMap) {
.registerSprite(new ResourceLocation("gregtech:blocks/overlay/machine/overlay_screen_glass"));
}

public <T extends MetaTileEntity & ITieredMetaTileEntity> void renderMachine(CCRenderState renderState,
Matrix4 translation,
IVertexOperation[] pipeline,
T mte) {
public <T extends MetaTileEntityQuantumStorage<?> & 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,
Expand All @@ -81,6 +81,13 @@ public <T extends MetaTileEntity & ITieredMetaTileEntity> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,19 @@
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;
import gregtech.common.metatileentities.MetaTileEntities;

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;
Expand Down Expand Up @@ -229,42 +232,82 @@ 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
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();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -193,7 +194,8 @@ public void onRemoval() {
}

@Override
public void onPlacement() {
public void onPlacement(@Nullable EntityLivingBase placer) {
super.onPlacement(placer);
rebuildNetwork();
}

Expand Down

0 comments on commit 449f94e

Please sign in to comment.