Merge pull request #1712 from abel1502/abel-rbmk-crane

Make RBMK crane rotatable
This commit is contained in:
HbmMods 2024-10-03 08:05:47 +02:00 committed by GitHub
commit 109e710112
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 59 additions and 5 deletions

View File

@ -4,14 +4,17 @@ import com.hbm.blocks.BlockDummyable;
import com.hbm.handler.MultiblockHandlerXR; import com.hbm.handler.MultiblockHandlerXR;
import com.hbm.tileentity.machine.rbmk.TileEntityCraneConsole; import com.hbm.tileentity.machine.rbmk.TileEntityCraneConsole;
import api.hbm.block.IToolable;
import api.hbm.block.IToolable.ToolType;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.IBlockAccess; import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
public class RBMKCraneConsole extends BlockDummyable { public class RBMKCraneConsole extends BlockDummyable implements IToolable {
public RBMKCraneConsole() { public RBMKCraneConsole() {
super(Material.iron); super(Material.iron);
@ -72,4 +75,20 @@ public class RBMKCraneConsole extends BlockDummyable {
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F); this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
} }
} }
@Override
public boolean onScrew(World world, EntityPlayer player, int x, int y, int z, int side, float fX, float fY, float fZ, ToolType tool) {
if(tool == ToolType.SCREWDRIVER) {
if(world.isRemote) return true;
int[] pos = findCore(world, x, y, z);
TileEntityCraneConsole tile = (TileEntityCraneConsole) world.getTileEntity(pos[0], pos[1], pos[2]);
tile.cycleCraneRotation();
tile.markDirty();
return true;
}
return false;
}
} }

View File

@ -108,18 +108,40 @@ public class RenderCraneConsole extends TileEntitySpecialRenderer {
double posX = (console.lastPosFront + (console.posFront - console.lastPosFront) * interp); double posX = (console.lastPosFront + (console.posFront - console.lastPosFront) * interp);
double posZ = (console.lastPosLeft + (console.posLeft - console.lastPosLeft) * interp); double posZ = (console.lastPosLeft + (console.posLeft - console.lastPosLeft) * interp);
GL11.glTranslated(0, 0, posZ); GL11.glTranslated(-posX, 0, posZ);
int craneRotationOffset = ((TileEntityCraneConsole)te).craneRotationOffset;
GL11.glRotatef(craneRotationOffset, 0F, 1F, 0F);
GL11.glPushMatrix(); GL11.glPushMatrix();
GL11.glTranslated(-console.spanL, height - 1, 0); int girderSpan = 0;
GL11.glRotatef(-craneRotationOffset, 0F, 1F, 0F);
switch(craneRotationOffset) {
case 0:
girderSpan = console.spanL + console.spanR + 1;
GL11.glTranslated(posX - console.spanL, 0, 0);
break;
case 90:
girderSpan = console.spanF + console.spanB + 1;
GL11.glTranslated(0, 0, -posZ + console.spanB);
break;
case 180:
girderSpan = console.spanL + console.spanR + 1;
GL11.glTranslated(posX + console.spanR, 0, 0);
break;
case 270:
girderSpan = console.spanF + console.spanB + 1;
GL11.glTranslated(0, 0, -posZ - console.spanF);
break;
}
GL11.glRotatef(craneRotationOffset, 0F, 1F, 0F);
for(int i = -console.spanL; i <= console.spanR; i++) { for(int i = 0; i < girderSpan; i++) {
ResourceManager.rbmk_crane.renderPart("Girder"); ResourceManager.rbmk_crane.renderPart("Girder");
GL11.glTranslated(1, 0, 0); GL11.glTranslated(1, 0, 0);
} }
GL11.glPopMatrix(); GL11.glPopMatrix();
GL11.glTranslated(-posX, 0, 0);
ResourceManager.rbmk_crane.renderPart("Main"); ResourceManager.rbmk_crane.renderPart("Main");
GL11.glPushMatrix(); GL11.glPushMatrix();

View File

@ -28,6 +28,8 @@ import net.minecraftforge.common.util.ForgeDirection;
import java.util.List; import java.util.List;
import org.lwjgl.opengl.GL11;
@Optional.InterfaceList({@Optional.Interface(iface = "li.cil.oc.api.network.SimpleComponent", modid = "OpenComputers")}) @Optional.InterfaceList({@Optional.Interface(iface = "li.cil.oc.api.network.SimpleComponent", modid = "OpenComputers")})
public class TileEntityCraneConsole extends TileEntity implements INBTPacketReceiver, SimpleComponent, CompatHandler.OCComponent { public class TileEntityCraneConsole extends TileEntity implements INBTPacketReceiver, SimpleComponent, CompatHandler.OCComponent {
@ -44,6 +46,8 @@ public class TileEntityCraneConsole extends TileEntity implements INBTPacketRece
public boolean setUpCrane = false; public boolean setUpCrane = false;
public int craneRotationOffset = 0;
public double lastTiltFront = 0; public double lastTiltFront = 0;
public double lastTiltLeft = 0; public double lastTiltLeft = 0;
public double tiltFront = 0; public double tiltFront = 0;
@ -169,6 +173,7 @@ public class TileEntityCraneConsole extends TileEntity implements INBTPacketRece
nbt.setBoolean("crane", setUpCrane); nbt.setBoolean("crane", setUpCrane);
if(setUpCrane) { //no need to send any of this if there's NO FUCKING CRANE THERE if(setUpCrane) { //no need to send any of this if there's NO FUCKING CRANE THERE
nbt.setInteger("craneRotationOffset", craneRotationOffset);
nbt.setInteger("centerX", centerX); nbt.setInteger("centerX", centerX);
nbt.setInteger("centerY", centerY); nbt.setInteger("centerY", centerY);
nbt.setInteger("centerZ", centerZ); nbt.setInteger("centerZ", centerZ);
@ -250,6 +255,7 @@ public class TileEntityCraneConsole extends TileEntity implements INBTPacketRece
lastProgress = progress; lastProgress = progress;
this.setUpCrane = nbt.getBoolean("crane"); this.setUpCrane = nbt.getBoolean("crane");
this.craneRotationOffset = nbt.getInteger("craneRotationOffset");
this.centerX = nbt.getInteger("centerX"); this.centerX = nbt.getInteger("centerX");
this.centerY = nbt.getInteger("centerY"); this.centerY = nbt.getInteger("centerY");
this.centerZ = nbt.getInteger("centerZ"); this.centerZ = nbt.getInteger("centerZ");
@ -277,16 +283,22 @@ public class TileEntityCraneConsole extends TileEntity implements INBTPacketRece
this.spanR = 7; this.spanR = 7;
this.height = 7; this.height = 7;
this.setUpCrane = true; this.setUpCrane = true;
this.markDirty(); this.markDirty();
} }
public void cycleCraneRotation() {
this.craneRotationOffset = (this.craneRotationOffset + 90) % 360;
}
@Override @Override
public void readFromNBT(NBTTagCompound nbt) { public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt); super.readFromNBT(nbt);
this.setUpCrane = nbt.getBoolean("crane"); this.setUpCrane = nbt.getBoolean("crane");
this.craneRotationOffset = nbt.getInteger("craneRotationOffset");
this.centerX = nbt.getInteger("centerX"); this.centerX = nbt.getInteger("centerX");
this.centerY = nbt.getInteger("centerY"); this.centerY = nbt.getInteger("centerY");
this.centerZ = nbt.getInteger("centerZ"); this.centerZ = nbt.getInteger("centerZ");
@ -307,6 +319,7 @@ public class TileEntityCraneConsole extends TileEntity implements INBTPacketRece
super.writeToNBT(nbt); super.writeToNBT(nbt);
nbt.setBoolean("crane", setUpCrane); nbt.setBoolean("crane", setUpCrane);
nbt.setInteger("craneRotationOffset", craneRotationOffset);
nbt.setInteger("centerX", centerX); nbt.setInteger("centerX", centerX);
nbt.setInteger("centerY", centerY); nbt.setInteger("centerY", centerY);
nbt.setInteger("centerZ", centerZ); nbt.setInteger("centerZ", centerZ);