From 41c79abf4255de6e69a9acbf032bac0f09466e97 Mon Sep 17 00:00:00 2001 From: Alexander Anishin Date: Wed, 7 Jun 2023 15:01:16 +0300 Subject: [PATCH] Migrate Reactor Stabilizer to Forge Direction --- .../tile/RenderTileReactorStabilizer.java | 111 ++++-------------- .../blocks/multiblock/ReactorStabilizer.java | 6 +- .../reactor/TileReactorStabilizer.java | 16 ++- 3 files changed, 32 insertions(+), 101 deletions(-) diff --git a/src/main/java/com/brandon3055/draconicevolution/client/render/tile/RenderTileReactorStabilizer.java b/src/main/java/com/brandon3055/draconicevolution/client/render/tile/RenderTileReactorStabilizer.java index 0e7f2d0f..b03b1f28 100644 --- a/src/main/java/com/brandon3055/draconicevolution/client/render/tile/RenderTileReactorStabilizer.java +++ b/src/main/java/com/brandon3055/draconicevolution/client/render/tile/RenderTileReactorStabilizer.java @@ -2,6 +2,7 @@ package com.brandon3055.draconicevolution.client.render.tile; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.util.ForgeDirection; import org.lwjgl.opengl.GL11; @@ -29,110 +30,44 @@ public class RenderTileReactorStabilizer extends TileEntitySpecialRenderer { GL11.glPopMatrix(); } - public static void renderCore(TileReactorStabilizer tile, float partialTick) { + public static void renderCore(TileReactorStabilizer stabilizer, float partialTick) { GL11.glPushMatrix(); float scale = (1F / 16F); - float coreRotation = tile.coreRotation + (partialTick * tile.coreSpeed); - float ringRotation = tile.ringRotation + (partialTick * tile.ringSpeed); + float coreRotation = stabilizer.coreRotation + (partialTick * stabilizer.coreSpeed); + float ringRotation = stabilizer.ringRotation + (partialTick * stabilizer.ringSpeed); - switch (tile.facingDirection) { - case 0: - GL11.glRotated(90, -1, 0, 0); + int angle = 90; + ForgeDirection axis = stabilizer.facing; + switch (stabilizer.facing) { + case DOWN: + axis = ForgeDirection.WEST; break; - case 1: - GL11.glRotated(90, 1, 0, 0); + case SOUTH: + angle = 180; + // it's intended to fall through + case UP: + axis = ForgeDirection.EAST; break; - case 3: - GL11.glRotated(180, 1, 0, 0); + case WEST: + axis = ForgeDirection.UP; break; - case 4: - GL11.glRotated(90, 0, 1, 0); + case EAST: + axis = ForgeDirection.DOWN; break; - case 5: - GL11.glRotated(90, 0, -1, 0); + } + if (stabilizer.facing != ForgeDirection.NORTH) { + GL11.glRotated(angle, axis.offsetX, axis.offsetY, axis.offsetZ); } ResourceHandler.bindResource("textures/models/reactorStabilizerCore.png"); - modelStabilizerCore.render(null, coreRotation, tile.modelIllumination, 0F, 0F, 0F, scale); + modelStabilizerCore.render(null, coreRotation, stabilizer.modelIllumination, 0F, 0F, 0F, scale); ResourceHandler.bindResource("textures/models/reactorStabilizerRing.png"); GL11.glRotated(90, 1, 0, 0); GL11.glTranslated(0, -0.58, 0); GL11.glScaled(0.95, 0.95, 0.95); GL11.glRotatef(ringRotation, 0, 1, 0); - modelStabilizerRing.render(null, -70F, tile.modelIllumination, 0F, 0F, 0F, scale); + modelStabilizerRing.render(null, -70F, stabilizer.modelIllumination, 0F, 0F, 0F, scale); GL11.glPopMatrix(); } - - // public static void renderEffects(TileReactorStabilizer tile, float partialTick) { - // if (tile.isValid) - // { - // //Common Fields - // MultiblockHelper.TileLocation master = tile.masterLocation; - // float offsetX = (float)(master.posX - tile.xCoord); - // float offsetY = (float)((double)master.posY - tile.yCoord); - // float offsetZ = (float)(master.posZ - tile.zCoord); - // float length = MathHelper.sqrt_float(offsetX * offsetX + offsetY * offsetY + offsetZ * offsetZ); - // - // Tessellator tessellator = Tessellator.instance; - // - // //Pre Render - // GL11.glPushMatrix(); - //// RenderHelper.disableStandardItemLighting(); - // GL11.glDisable(GL11.GL_CULL_FACE); - // GL11.glShadeModel(GL11.GL_SMOOTH); - // GL11.glEnable(GL11.GL_BLEND); - // OpenGlHelper.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0); - // GL11.glAlphaFunc(GL11.GL_GREATER, 0.0F); - // GL11.glDisable(GL11.GL_LIGHTING); - // GL11.glDepthMask(false); - // - // //Rotate beam to face target - // float f7 = MathHelper.sqrt_float(offsetX * offsetX + offsetZ * offsetZ); - // GL11.glRotatef((float) (-Math.atan2((double) offsetZ, (double) offsetX)) * 180.0F / (float) Math.PI - 90.0F, - // 0.0F, 1.0F, 0.0F); - // GL11.glRotatef((float)(-Math.atan2((double)f7, (double)offsetY)) * 180.0F / (float)Math.PI - 90.0F, 1.0F, 0.0F, - // 0.0F); - // - // - // //Draw Beams - // GL11.glPushMatrix(); - // GL11.glTranslated(0, 0, -0.35); - // ResourceHandler.bindTexture(new ResourceLocation("textures/entity/endercrystal/endercrystal_beam.png")); - //// drawBeam(tessellator, 1F, 0.355F, 0.8F, offsetX, offsetY, offsetZ, tile.tick, partialTick, true, false); - // GL11.glPopMatrix(); - // - // GL11.glPushMatrix(); - // GL11.glTranslated(0, 0, 0.4526); - // float coreSize = 1.1F; - // float s = 0.355F; - //// drawBeam(tessellator, s/coreSize, coreSize, length - 0.5F, offsetX, offsetY, offsetZ, tile.tick, partialTick, - // false, false); - // GL11.glPopMatrix(); - // - //// GL11.glPushMatrix(); - //// GL11.glTranslated(0, 0, -0.35); - //// ResourceHandler.bindTexture(new ResourceLocation("textures/entity/endercrystal/endercrystal_beam.png")); - //// drawBeam(tessellator, 1F, 0.26F, 0.8F, offsetX, offsetY, offsetZ, tile.tick, partialTick, true, true); - //// GL11.glPopMatrix(); - //// - //// GL11.glPushMatrix(); - //// GL11.glTranslated(0, 0, 0.4526); - //// coreSize = 1.1F; - //// s = 0.263F; - //// drawBeam(tessellator, s/coreSize, coreSize, length - 0.5F, offsetX, offsetY, offsetZ, tile.tick, partialTick, - // false, true); - //// GL11.glPopMatrix(); - // - // //Post Render - // GL11.glDepthMask(true); - // GL11.glEnable(GL11.GL_LIGHTING); - // GL11.glEnable(GL11.GL_CULL_FACE); - // GL11.glShadeModel(GL11.GL_FLAT); - //// RenderHelper.enableStandardItemLighting(); - // GL11.glDisable(GL11.GL_BLEND); - // GL11.glAlphaFunc(GL11.GL_GREATER, 0.1F); - // GL11.glPopMatrix(); - // } - // } } diff --git a/src/main/java/com/brandon3055/draconicevolution/common/blocks/multiblock/ReactorStabilizer.java b/src/main/java/com/brandon3055/draconicevolution/common/blocks/multiblock/ReactorStabilizer.java index 456d7f8d..294e565a 100644 --- a/src/main/java/com/brandon3055/draconicevolution/common/blocks/multiblock/ReactorStabilizer.java +++ b/src/main/java/com/brandon3055/draconicevolution/common/blocks/multiblock/ReactorStabilizer.java @@ -87,13 +87,11 @@ public class ReactorStabilizer extends BlockDE implements ITileEntityProvider { @Override public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entity, ItemStack stack) { - int facing = Utills.determineOrientation(x, y, z, entity); + ForgeDirection facing = ForgeDirection.getOrientation(Utills.determineOrientation(x, y, z, entity)); TileEntity tile = world.getTileEntity(x, y, z); if (tile instanceof TileReactorStabilizer) { TileReactorStabilizer stabilizer = (TileReactorStabilizer) tile; - stabilizer.facingDirection = entity.isSneaking() - ? ForgeDirection.getOrientation(facing).getOpposite().ordinal() - : ForgeDirection.getOrientation(facing).ordinal(); + stabilizer.facing = entity.isSneaking() ? facing.getOpposite() : facing; stabilizer.onPlaced(); } } diff --git a/src/main/java/com/brandon3055/draconicevolution/common/tileentities/multiblocktiles/reactor/TileReactorStabilizer.java b/src/main/java/com/brandon3055/draconicevolution/common/tileentities/multiblocktiles/reactor/TileReactorStabilizer.java index ed1f3295..73119221 100644 --- a/src/main/java/com/brandon3055/draconicevolution/common/tileentities/multiblocktiles/reactor/TileReactorStabilizer.java +++ b/src/main/java/com/brandon3055/draconicevolution/common/tileentities/multiblocktiles/reactor/TileReactorStabilizer.java @@ -29,7 +29,7 @@ public class TileReactorStabilizer extends TileEntity implements IReactorPart, I public float coreSpeed = 1F; public float ringSpeed = 1F; public float modelIllumination = 0F; - public int facingDirection = ForgeDirection.UP.ordinal(); + public ForgeDirection facing = ForgeDirection.UP; public TileLocation masterLocation = new TileLocation(); public boolean isValid = false; public int tick = 0; @@ -51,7 +51,6 @@ public class TileReactorStabilizer extends TileEntity implements IReactorPart, I TileReactorCore core = getMaster(); if (core != null) { if (core.reactorState == TileReactorCore.STATE_ONLINE) { - ForgeDirection facing = ForgeDirection.getOrientation(facingDirection); ForgeDirection back = facing.getOpposite(); TileEntity tile = worldObj .getTileEntity(xCoord + back.offsetX, yCoord + back.offsetY, zCoord + back.offsetZ); @@ -98,7 +97,6 @@ public class TileReactorStabilizer extends TileEntity implements IReactorPart, I } public void onPlaced() { - ForgeDirection facing = ForgeDirection.getOrientation(facingDirection); for (int distance = 1; distance <= TileReactorCore.MAX_SLAVE_RANGE; distance++) { TileLocation location = new TileLocation( xCoord + facing.offsetX * distance, @@ -148,7 +146,7 @@ public class TileReactorStabilizer extends TileEntity implements IReactorPart, I @Override public ForgeDirection getFacing() { - return ForgeDirection.getOrientation(facingDirection); + return facing; } @Override @@ -174,7 +172,7 @@ public class TileReactorStabilizer extends TileEntity implements IReactorPart, I public Packet getDescriptionPacket() { NBTTagCompound compound = new NBTTagCompound(); masterLocation.writeToNBT(compound, "Master"); - compound.setInteger("Facing", facingDirection); + compound.setInteger("Facing", facing.ordinal()); compound.setBoolean("IsValid", isValid); return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 1, compound); } @@ -183,7 +181,7 @@ public class TileReactorStabilizer extends TileEntity implements IReactorPart, I public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) { NBTTagCompound compound = pkt.func_148857_g(); masterLocation.readFromNBT(compound, "Master"); - facingDirection = compound.getInteger("Facing"); + facing = ForgeDirection.getOrientation(compound.getInteger("Facing")); isValid = compound.getBoolean("IsValid"); super.onDataPacket(net, pkt); } @@ -192,7 +190,7 @@ public class TileReactorStabilizer extends TileEntity implements IReactorPart, I public void writeToNBT(NBTTagCompound compound) { super.writeToNBT(compound); masterLocation.writeToNBT(compound, "Master"); - compound.setInteger("Facing", facingDirection); + compound.setInteger("Facing", facing.ordinal()); compound.setBoolean("IsValid", isValid); compound.setInteger("RedstoneMode", redstoneMode); } @@ -201,7 +199,7 @@ public class TileReactorStabilizer extends TileEntity implements IReactorPart, I public void readFromNBT(NBTTagCompound compound) { super.readFromNBT(compound); masterLocation.readFromNBT(compound, "Master"); - facingDirection = compound.getInteger("Facing"); + facing = ForgeDirection.getOrientation(compound.getInteger("Facing")); isValid = compound.getBoolean("IsValid"); redstoneMode = compound.getInteger("RedstoneMode"); } @@ -223,7 +221,7 @@ public class TileReactorStabilizer extends TileEntity implements IReactorPart, I @Override public boolean canConnectEnergy(ForgeDirection from) { - return from == ForgeDirection.getOrientation(facingDirection).getOpposite(); + return from == facing.getOpposite(); } @Override