mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
backported some 1.12 compat code
This commit is contained in:
parent
b17fb8f6e8
commit
647fb8e8ac
@ -242,6 +242,22 @@ public abstract class BlockDummyable extends BlockContainer {
|
|||||||
world.setBlock(x, y, z, this, meta + extra, 3);
|
world.setBlock(x, y, z, this, meta + extra, 3);
|
||||||
this.safeRem = false;
|
this.safeRem = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void removeExtra(World world, int x, int y, int z) {
|
||||||
|
|
||||||
|
if(world.getBlock(x, y, z) != this)
|
||||||
|
return;
|
||||||
|
|
||||||
|
int meta = world.getBlockMetadata(x, y, z);
|
||||||
|
|
||||||
|
if(meta <= 5 || meta >= 12)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// world.setBlockMetadataWithNotify(x, y, z, meta + extra, 3);
|
||||||
|
this.safeRem = true;
|
||||||
|
world.setBlock(x, y, z, this, meta - extra, 3);
|
||||||
|
this.safeRem = false;
|
||||||
|
}
|
||||||
|
|
||||||
// checks if the dummy metadata is within the extra range
|
// checks if the dummy metadata is within the extra range
|
||||||
public boolean hasExtra(int meta) {
|
public boolean hasExtra(int meta) {
|
||||||
|
|||||||
@ -7,11 +7,14 @@ import java.util.Set;
|
|||||||
import com.hbm.blocks.BlockDummyable;
|
import com.hbm.blocks.BlockDummyable;
|
||||||
import com.hbm.blocks.generic.BlockDoorGeneric;
|
import com.hbm.blocks.generic.BlockDoorGeneric;
|
||||||
import com.hbm.interfaces.IAnimatedDoor;
|
import com.hbm.interfaces.IAnimatedDoor;
|
||||||
|
import com.hbm.lib.Library;
|
||||||
import com.hbm.packet.PacketDispatcher;
|
import com.hbm.packet.PacketDispatcher;
|
||||||
import com.hbm.packet.TEDoorAnimationPacket;
|
import com.hbm.packet.TEDoorAnimationPacket;
|
||||||
import com.hbm.sound.AudioWrapper;
|
import com.hbm.sound.AudioWrapper;
|
||||||
import com.hbm.tileentity.machine.TileEntityLockableBase;
|
import com.hbm.tileentity.machine.TileEntityLockableBase;
|
||||||
import com.hbm.util.Tuple.Triplet;
|
import com.hbm.util.Tuple.Triplet;
|
||||||
|
import com.hbm.util.fauxpointtwelve.BlockPos;
|
||||||
|
import com.hbm.util.fauxpointtwelve.Rotation;
|
||||||
|
|
||||||
import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint;
|
import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint;
|
||||||
import cpw.mods.fml.relauncher.Side;
|
import cpw.mods.fml.relauncher.Side;
|
||||||
@ -30,7 +33,7 @@ public class TileEntityDoorGeneric extends TileEntityLockableBase implements IAn
|
|||||||
public long animStartTime = 0;
|
public long animStartTime = 0;
|
||||||
public int redstonePower;
|
public int redstonePower;
|
||||||
public boolean shouldUseBB = false;
|
public boolean shouldUseBB = false;
|
||||||
public Set<Triplet<Integer, Integer, Integer>> activatedBlocks = new HashSet<>(4);
|
public Set<BlockPos> activatedBlocks = new HashSet<>(4);
|
||||||
|
|
||||||
private AudioWrapper audio;
|
private AudioWrapper audio;
|
||||||
private AudioWrapper audio2;
|
private AudioWrapper audio2;
|
||||||
@ -52,6 +55,9 @@ public class TileEntityDoorGeneric extends TileEntityLockableBase implements IAn
|
|||||||
if(worldObj.isRemote) {
|
if(worldObj.isRemote) {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
BlockPos pos = new BlockPos(this);
|
||||||
|
|
||||||
int[][] ranges = getDoorType().getDoorOpenRanges();
|
int[][] ranges = getDoorType().getDoorOpenRanges();
|
||||||
ForgeDirection dir = ForgeDirection.getOrientation(getBlockMetadata() - BlockDummyable.offset);
|
ForgeDirection dir = ForgeDirection.getOrientation(getBlockMetadata() - BlockDummyable.offset);
|
||||||
|
|
||||||
@ -60,7 +66,7 @@ public class TileEntityDoorGeneric extends TileEntityLockableBase implements IAn
|
|||||||
for(int i = 0; i < ranges.length; i++) {
|
for(int i = 0; i < ranges.length; i++) {
|
||||||
|
|
||||||
int[] range = ranges[i];
|
int[] range = ranges[i];
|
||||||
int[] startPos = new int[] {range[0], range[1], range[2]};
|
BlockPos startPos = new BlockPos(range[0], range[1], range[2]);
|
||||||
float time = getDoorType().getDoorRangeOpenTime(openTicks, i);
|
float time = getDoorType().getDoorRangeOpenTime(openTicks, i);
|
||||||
|
|
||||||
for(int j = 0; j < Math.abs(range[3]); j++) {
|
for(int j = 0; j < Math.abs(range[3]); j++) {
|
||||||
@ -69,22 +75,24 @@ public class TileEntityDoorGeneric extends TileEntityLockableBase implements IAn
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
for(int k = 0; k < range[4]; k++) {
|
for(int k = 0; k < range[4]; k++) {
|
||||||
int[] add = new int[] {0, 0, 0};
|
BlockPos add = new BlockPos(0, 0, 0);
|
||||||
switch(range[5]){
|
switch(range[5]){
|
||||||
case 0: add = new int[] {0, k, (int)Math.signum(range[3]) * j}; break;
|
case 0: add = new BlockPos(0, k, (int)Math.signum(range[3]) * j); break;
|
||||||
case 1: add = new int[] {k, (int)Math.signum(range[3]) * j, 0}; break;
|
case 1: add = new BlockPos(k, (int)Math.signum(range[3]) * j, 0); break;
|
||||||
case 2: add = new int[] {(int)Math.signum(range[3]) * j, k, 0}; break;
|
case 2: add = new BlockPos((int)Math.signum(range[3]) * j, k, 0); break;
|
||||||
}
|
}
|
||||||
/*Rotation r = dir.getBlockRotation();
|
|
||||||
if(dir.toEnumFacing().getAxis() == EnumFacing.Axis.X)
|
|
||||||
r = r.add(Rotation.CLOCKWISE_180);
|
|
||||||
int[] finalPos = new int[]{} startPos.add(add).rotate(r).add(pos);
|
|
||||||
|
|
||||||
if(finalPos.equals(this.pos)) {
|
Rotation r = Rotation.getBlockRotation(dir);
|
||||||
this.shouldUseBB = true;
|
if(dir == Library.POS_X || dir == Library.NEG_X)
|
||||||
|
r = r.add(Rotation.CLOCKWISE_180);
|
||||||
|
|
||||||
|
BlockPos finalPos = startPos.add(add).rotate(r).add(pos);
|
||||||
|
|
||||||
|
if(finalPos.equals(pos)) {
|
||||||
|
this.shouldUseBB = false;
|
||||||
} else {
|
} else {
|
||||||
((BlockDummyable)getBlockType()).makeExtra(worldObj, finalPos.getX(), finalPos.getY(), finalPos.getZ());
|
((BlockDummyable)getBlockType()).removeExtra(worldObj, finalPos.getX(), finalPos.getY(), finalPos.getZ());
|
||||||
}_*/ //TODO: whatever just get these errors out of my face
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -95,7 +103,7 @@ public class TileEntityDoorGeneric extends TileEntityLockableBase implements IAn
|
|||||||
|
|
||||||
int[] range = ranges[i];
|
int[] range = ranges[i];
|
||||||
|
|
||||||
int[] startPos = new int[] {range[0], range[1], range[2]};
|
BlockPos startPos = new BlockPos(range[0], range[1], range[2]);
|
||||||
float time = getDoorType().getDoorRangeOpenTime(openTicks, i);
|
float time = getDoorType().getDoorRangeOpenTime(openTicks, i);
|
||||||
|
|
||||||
for(int j = Math.abs(range[3])-1; j >= 0; j--) {
|
for(int j = Math.abs(range[3])-1; j >= 0; j--) {
|
||||||
@ -104,22 +112,24 @@ public class TileEntityDoorGeneric extends TileEntityLockableBase implements IAn
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
for(int k = 0; k < range[4]; k++) {
|
for(int k = 0; k < range[4]; k++) {
|
||||||
int[] add = new int[] {0, 0, 0};
|
BlockPos add = new BlockPos(0, 0, 0);
|
||||||
switch(range[5]){
|
switch(range[5]){
|
||||||
case 0: add = new int[] {0, k, (int)Math.signum(range[3]) * j}; break;
|
case 0: add = new BlockPos(0, k, (int)Math.signum(range[3]) * j); break;
|
||||||
case 1: add = new int[] {k, (int)Math.signum(range[3]) * j, 0}; break;
|
case 1: add = new BlockPos(k, (int)Math.signum(range[3]) * j, 0); break;
|
||||||
case 2: add = new int[] {(int)Math.signum(range[3]) * j, k, 0}; break;
|
case 2: add = new BlockPos((int)Math.signum(range[3]) * j, k, 0); break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*Rotation r = dir.getBlockRotation();
|
Rotation r = Rotation.getBlockRotation(dir);
|
||||||
if(dir.toEnumFacing().getAxis() == EnumFacing.Axis.X)
|
if(dir == Library.POS_X || dir == Library.NEG_X)
|
||||||
r = r.add(Rotation.CLOCKWISE_180);
|
r = r.add(Rotation.CLOCKWISE_180);
|
||||||
|
|
||||||
BlockPos finalPos = startPos.add(add).rotate(r).add(pos);
|
BlockPos finalPos = startPos.add(add).rotate(r).add(pos);
|
||||||
if(finalPos.equals(this.pos)) {
|
|
||||||
|
if(finalPos.equals(pos)) {
|
||||||
this.shouldUseBB = false;
|
this.shouldUseBB = false;
|
||||||
} else {
|
} else {
|
||||||
((BlockDummyable)getBlockType()).removeExtra(world, finalPos.getX(), finalPos.getY(), finalPos.getZ());
|
((BlockDummyable)getBlockType()).removeExtra(worldObj, finalPos.getX(), finalPos.getY(), finalPos.getZ());
|
||||||
}*/ //TODO
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -148,11 +158,11 @@ public class TileEntityDoorGeneric extends TileEntityLockableBase implements IAn
|
|||||||
if(audio != null) {
|
if(audio != null) {
|
||||||
audio.stopSound();
|
audio.stopSound();
|
||||||
audio = null;
|
audio = null;
|
||||||
}
|
}
|
||||||
if(audio2 != null) {
|
if(audio2 != null) {
|
||||||
audio2.stopSound();
|
audio2.stopSound();
|
||||||
audio2 = null;
|
audio2 = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public DoorDecl getDoorType(){
|
public DoorDecl getDoorType(){
|
||||||
@ -304,7 +314,7 @@ public class TileEntityDoorGeneric extends TileEntityLockableBase implements IAn
|
|||||||
NBTTagCompound activatedBlocks = tag.getCompoundTag("activatedBlocks");
|
NBTTagCompound activatedBlocks = tag.getCompoundTag("activatedBlocks");
|
||||||
this.activatedBlocks.clear();
|
this.activatedBlocks.clear();
|
||||||
for(int i = 0; i < activatedBlocks.func_150296_c().size()/3; i ++){
|
for(int i = 0; i < activatedBlocks.func_150296_c().size()/3; i ++){
|
||||||
this.activatedBlocks.add(new Triplet(activatedBlocks.getInteger("x"+i), activatedBlocks.getInteger("y"+i), activatedBlocks.getInteger("z"+i)));
|
this.activatedBlocks.add(new BlockPos(activatedBlocks.getInteger("x"+i), activatedBlocks.getInteger("y"+i), activatedBlocks.getInteger("z"+i)));
|
||||||
}
|
}
|
||||||
super.readFromNBT(tag);
|
super.readFromNBT(tag);
|
||||||
}
|
}
|
||||||
@ -320,7 +330,7 @@ public class TileEntityDoorGeneric extends TileEntityLockableBase implements IAn
|
|||||||
tag.setBoolean("shouldUseBB", shouldUseBB);
|
tag.setBoolean("shouldUseBB", shouldUseBB);
|
||||||
NBTTagCompound activatedBlocks = new NBTTagCompound();
|
NBTTagCompound activatedBlocks = new NBTTagCompound();
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for(Triplet<Integer, Integer, Integer> p : this.activatedBlocks){
|
for(BlockPos p : this.activatedBlocks){
|
||||||
activatedBlocks.setInteger("x"+i, p.getX());
|
activatedBlocks.setInteger("x"+i, p.getX());
|
||||||
activatedBlocks.setInteger("y"+i, p.getY());
|
activatedBlocks.setInteger("y"+i, p.getY());
|
||||||
activatedBlocks.setInteger("z"+i, p.getZ());
|
activatedBlocks.setInteger("z"+i, p.getZ());
|
||||||
@ -349,7 +359,7 @@ public class TileEntityDoorGeneric extends TileEntityLockableBase implements IAn
|
|||||||
|
|
||||||
public void updateRedstonePower(int x, int y, int z){
|
public void updateRedstonePower(int x, int y, int z){
|
||||||
//Drillgon200: Best I could come up with without having to use dummy tile entities
|
//Drillgon200: Best I could come up with without having to use dummy tile entities
|
||||||
Triplet<Integer, Integer, Integer> pos = new Triplet(x, y, z);
|
BlockPos pos = new BlockPos(x, y, z);
|
||||||
boolean powered = worldObj.isBlockIndirectlyGettingPowered(x, y, z);
|
boolean powered = worldObj.isBlockIndirectlyGettingPowered(x, y, z);
|
||||||
boolean contained = activatedBlocks.contains(pos);
|
boolean contained = activatedBlocks.contains(pos);
|
||||||
if(!contained && powered){
|
if(!contained && powered){
|
||||||
|
|||||||
58
src/main/java/com/hbm/util/fauxpointtwelve/BlockPos.java
Normal file
58
src/main/java/com/hbm/util/fauxpointtwelve/BlockPos.java
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
package com.hbm.util.fauxpointtwelve;
|
||||||
|
|
||||||
|
import net.minecraft.tileentity.TileEntity;
|
||||||
|
import net.minecraft.util.MathHelper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adjusted code from MC 1.12 (com.minecraft.util.math.BlockPos)
|
||||||
|
*/
|
||||||
|
public class BlockPos {
|
||||||
|
|
||||||
|
private final int x;
|
||||||
|
private final int y;
|
||||||
|
private final int z;
|
||||||
|
|
||||||
|
public BlockPos(int x, int y, int z) {
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
this.z = z;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BlockPos(TileEntity te) {
|
||||||
|
this(te.xCoord, te.yCoord, te.zCoord);
|
||||||
|
}
|
||||||
|
|
||||||
|
public BlockPos(double x, double y, double z) {
|
||||||
|
this((int)MathHelper.floor_double(x), (int)MathHelper.floor_double(y), (int)MathHelper.floor_double(z));
|
||||||
|
}
|
||||||
|
|
||||||
|
public BlockPos add(double x, double y, double z) {
|
||||||
|
return x == 0.0D && y == 0.0D && z == 0.0D ? this : new BlockPos((double) this.getX() + x, (double) this.getY() + y, (double) this.getZ() + z);
|
||||||
|
}
|
||||||
|
|
||||||
|
public BlockPos add(BlockPos vec) {
|
||||||
|
return this.add(vec.getX(), vec.getY(), vec.getZ());
|
||||||
|
}
|
||||||
|
|
||||||
|
public BlockPos rotate(Rotation rotationIn) {
|
||||||
|
switch(rotationIn) {
|
||||||
|
case NONE:
|
||||||
|
default: return this;
|
||||||
|
case CLOCKWISE_90: return new BlockPos(-this.getZ(), this.getY(), this.getX());
|
||||||
|
case CLOCKWISE_180: return new BlockPos(-this.getX(), this.getY(), -this.getZ());
|
||||||
|
case COUNTERCLOCKWISE_90: return new BlockPos(this.getZ(), this.getY(), -this.getX());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getX() {
|
||||||
|
return this.x;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getY() {
|
||||||
|
return this.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getZ() {
|
||||||
|
return this.z;
|
||||||
|
}
|
||||||
|
}
|
||||||
61
src/main/java/com/hbm/util/fauxpointtwelve/Rotation.java
Normal file
61
src/main/java/com/hbm/util/fauxpointtwelve/Rotation.java
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
package com.hbm.util.fauxpointtwelve;
|
||||||
|
|
||||||
|
import com.hbm.interfaces.Spaghetti;
|
||||||
|
|
||||||
|
import net.minecraftforge.common.util.ForgeDirection;
|
||||||
|
|
||||||
|
public enum Rotation {
|
||||||
|
|
||||||
|
NONE(), CLOCKWISE_90(), CLOCKWISE_180(), COUNTERCLOCKWISE_90();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verbatim code from MC 1.12 (net.minecraft.util.Rotation)
|
||||||
|
* @param rotation
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Spaghetti("thanks for the cool code, mojang")
|
||||||
|
public Rotation add(Rotation rotation) {
|
||||||
|
switch(rotation) {
|
||||||
|
case CLOCKWISE_180:
|
||||||
|
switch(this) {
|
||||||
|
case NONE: return CLOCKWISE_180;
|
||||||
|
case CLOCKWISE_90: return COUNTERCLOCKWISE_90;
|
||||||
|
case CLOCKWISE_180: return NONE;
|
||||||
|
case COUNTERCLOCKWISE_90: return CLOCKWISE_90;
|
||||||
|
}
|
||||||
|
|
||||||
|
case COUNTERCLOCKWISE_90:
|
||||||
|
switch(this) {
|
||||||
|
case NONE: return COUNTERCLOCKWISE_90;
|
||||||
|
case CLOCKWISE_90: return NONE;
|
||||||
|
case CLOCKWISE_180: return CLOCKWISE_90;
|
||||||
|
case COUNTERCLOCKWISE_90: return CLOCKWISE_180;
|
||||||
|
}
|
||||||
|
|
||||||
|
case CLOCKWISE_90:
|
||||||
|
switch(this) {
|
||||||
|
case NONE: return CLOCKWISE_90;
|
||||||
|
case CLOCKWISE_90: return CLOCKWISE_180;
|
||||||
|
case CLOCKWISE_180: return COUNTERCLOCKWISE_90;
|
||||||
|
case COUNTERCLOCKWISE_90: return NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
default: return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adjusted code from NTM 1.12 (com.hbm.lib.ForgeDirection)
|
||||||
|
* @param dir
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static Rotation getBlockRotation(ForgeDirection dir){
|
||||||
|
switch(dir) {
|
||||||
|
case NORTH: return Rotation.NONE;
|
||||||
|
case SOUTH: return Rotation.CLOCKWISE_180;
|
||||||
|
case EAST: return Rotation.COUNTERCLOCKWISE_90;
|
||||||
|
case WEST: return Rotation.CLOCKWISE_90;
|
||||||
|
default: return Rotation.NONE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user