|
| 1 | +package zero.test; |
| 2 | +import net.minecraft.src.*; |
| 3 | +import btw.AddonHandler; |
| 4 | +import btw.block.BTWBlocks; |
| 5 | +import btw.block.blocks.PlatformBlock; |
| 6 | +import btw.block.blocks.AnchorBlock; |
| 7 | +import btw.entity.mechanical.platform.BlockLiftedByPlatformEntity; |
| 8 | +import btw.entity.mechanical.platform.MovingAnchorEntity; |
| 9 | +import btw.entity.mechanical.platform.MovingPlatformEntity; |
| 10 | +import btw.block.tileentity.PulleyTileEntity; |
| 11 | +import btw.item.util.ItemUtils; |
| 12 | +import org.spongepowered.asm.mixin.Mixin; |
| 13 | +import org.spongepowered.asm.mixin.injection.At; |
| 14 | +import org.spongepowered.asm.mixin.injection.Redirect; |
| 15 | +import org.spongepowered.asm.mixin.injection.Inject; |
| 16 | +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; |
| 17 | +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; |
| 18 | +import org.spongepowered.asm.mixin.Overwrite; |
| 19 | +import org.spongepowered.asm.mixin.Final; |
| 20 | +import org.spongepowered.asm.mixin.Shadow; |
| 21 | +import org.spongepowered.asm.mixin.gen.Invoker; |
| 22 | +import zero.test.IWorldMixins; |
| 23 | +import zero.test.IBlockMixins; |
| 24 | +import zero.test.IMovingPlatformEntityMixins; |
| 25 | +//import zero.test.mixin.IAnchorBlockAccessMixins; |
| 26 | +import java.util.Random; |
| 27 | +// Block piston reactions |
| 28 | + |
| 29 | +// I mean... they're already solid, right? |
| 30 | +public class PlatformResolver { |
| 31 | + private static final int PLATFORM_LIFT_LIMIT = |
| 32 | + 25; |
| 33 | + // 7 just feels right |
| 34 | + private static final int PLATFORM_MAX_DISTANCE = 7; |
| 35 | + private static final int PLATFORM_LIST_LENGTH = PLATFORM_LIFT_LIMIT; |
| 36 | + // IDK how to properly calculate this, so just add a lot of extra space? |
| 37 | + private static final int LIFT_LIST_LENGTH = PLATFORM_LIFT_LIMIT * 5; |
| 38 | + private static final int PLATFORM_LIST_START_INDEX = 0; |
| 39 | + private static final int LIFT_LIST_START_INDEX = PLATFORM_LIST_START_INDEX + PLATFORM_LIST_LENGTH; |
| 40 | + private static final int PLATFORM_STATE_LIST_LENGTH = PLATFORM_LIST_LENGTH; |
| 41 | + private static final int LIFT_STATE_LIST_LENGTH = LIFT_LIST_LENGTH; |
| 42 | + private static final int PLATFORM_STATE_LIST_START_INDEX = 0; |
| 43 | + private static final int LIFT_STATE_LIST_START_INDEX = PLATFORM_STATE_LIST_START_INDEX + PLATFORM_STATE_LIST_LENGTH; |
| 44 | + private final long[] platform_blocks = new long[PLATFORM_LIST_LENGTH + LIFT_LIST_LENGTH]; |
| 45 | + private final int[] data_list = new int[PLATFORM_STATE_LIST_LENGTH + LIFT_STATE_LIST_LENGTH]; |
| 46 | + private long anchor_position; |
| 47 | + private int source_x; |
| 48 | + private int source_y; |
| 49 | + private int source_z; |
| 50 | + private int platform_index_global; |
| 51 | + private int lift_index_global; |
| 52 | + protected boolean addPlatformBlock(World world, int x, int y, int z, boolean isExtending) { |
| 53 | + int blockId = world.getBlockId(x, y, z); |
| 54 | + Block block = Block.blocksList[blockId]; |
| 55 | + long packedPos; |
| 56 | + if ( |
| 57 | + ((block)==null) || |
| 58 | + (packedPos = ((long)(z)<<12 +26|(long)((x)&0x3FFFFFF)<<12|((y)&0xFFF))) == anchor_position || |
| 59 | + ((IBlockMixins)block).getPlatformMobilityFlag(world, x, y, z) != 1 |
| 60 | + ) { |
| 61 | + ; |
| 62 | + return true; |
| 63 | + } |
| 64 | + ; |
| 65 | + for (int i = platform_index_global; --i >= PLATFORM_LIST_START_INDEX;) { |
| 66 | + if (platform_blocks[i] == packedPos) { |
| 67 | + return true; |
| 68 | + } |
| 69 | + } |
| 70 | + if (platform_index_global == (PLATFORM_LIST_START_INDEX + PLATFORM_LIST_LENGTH)) { |
| 71 | + ; |
| 72 | + return false; |
| 73 | + } |
| 74 | + platform_blocks[platform_index_global] = packedPos; |
| 75 | + data_list[platform_index_global] = (((blockId)&0xFFFF)|((world.getBlockMetadata(x, y, z)))<<16); |
| 76 | + ++platform_index_global; |
| 77 | + int move_direction = isExtending ? 0 : 1; |
| 78 | + int facing = 0; |
| 79 | + do { |
| 80 | + int nextX = x + Facing.offsetsXForSide[facing]; |
| 81 | + int nextY = y + Facing.offsetsYForSide[facing]; |
| 82 | + int nextZ = z + Facing.offsetsZForSide[facing]; |
| 83 | + int neighborId = world.getBlockId(nextX, nextY, nextZ); |
| 84 | + Block neighborBlock = Block.blocksList[neighborId]; |
| 85 | + if (!((neighborBlock)==null)) { |
| 86 | + packedPos = ((long)(nextZ)<<12 +26|(long)((nextX)&0x3FFFFFF)<<12|((nextY)&0xFFF)); |
| 87 | + switch (((IBlockMixins)neighborBlock).getPlatformMobilityFlag(world, nextX, nextY, nextZ)) { |
| 88 | + case 1: |
| 89 | + ; |
| 90 | + int diffX, diffY, diffZ; |
| 91 | + if ((diffX = nextX - source_x) < 0) diffX = -diffX; |
| 92 | + if ((diffY = nextY - source_y) < 0) diffY = -diffY; |
| 93 | + if ((diffZ = nextZ - source_z) < 0) diffZ = -diffZ; |
| 94 | + if (diffX + diffY + diffZ >= PLATFORM_MAX_DISTANCE) { |
| 95 | + return false; |
| 96 | + } |
| 97 | + if (!this.addPlatformBlock(world, nextX, nextY, nextZ, isExtending)) { |
| 98 | + return false; |
| 99 | + } |
| 100 | + break; |
| 101 | + case 0: |
| 102 | + ; |
| 103 | + if ( |
| 104 | + packedPos == anchor_position || |
| 105 | + !( |
| 106 | + ((IBlockMixins)block).isStickyForBlocks(world, x, y, z, facing) && |
| 107 | + ((IBlockMixins)neighborBlock).canBeStuckTo(world, nextX, nextY, nextZ, facing, blockId) && |
| 108 | + !( |
| 109 | + ((IBlockMixins)neighborBlock).getMobilityFlag(world, nextX, nextY, nextZ) != 4 && |
| 110 | + !neighborBlock.canBlockBePulledByPiston(world, nextX, nextY, nextZ, move_direction) |
| 111 | + ) && |
| 112 | + ( |
| 113 | + facing >= 2 || |
| 114 | + ( |
| 115 | + facing == move_direction |
| 116 | + ? neighborBlock.canBlockBePushedByPiston(world, nextX, nextY, nextZ, facing) |
| 117 | + : neighborBlock.canBlockBePulledByPiston(world, nextX, nextY, nextZ, ((facing)^1)) |
| 118 | + ) |
| 119 | + ) |
| 120 | + ) |
| 121 | + ) { |
| 122 | + break; |
| 123 | + } |
| 124 | + case 2: { |
| 125 | + ; |
| 126 | + if ( |
| 127 | + facing == 1 || |
| 128 | + ((IBlockMixins)block).isStickyForBlocks(world, x, y, z, facing) |
| 129 | + ) { |
| 130 | + int i = lift_index_global; |
| 131 | + do { |
| 132 | + if (--i < LIFT_LIST_START_INDEX) { |
| 133 | + platform_blocks[lift_index_global] = packedPos; |
| 134 | + data_list[lift_index_global] = (((neighborId)&0xFFFF)|((world.getBlockMetadata(nextX, nextY, nextZ)))<<16); |
| 135 | + ++lift_index_global; |
| 136 | + break; |
| 137 | + } |
| 138 | + } while (platform_blocks[i] != packedPos); |
| 139 | + } |
| 140 | + break; |
| 141 | + } |
| 142 | + } |
| 143 | + } |
| 144 | + } while (((++facing)<=5)); |
| 145 | + return true; |
| 146 | + } |
| 147 | + public void liftBlocks(World world, int x, int y, int z, MovingAnchorEntity associatedAnchorEntity) { |
| 148 | + ; |
| 149 | + anchor_position = ((long)(source_z = z)<<12 +26|(long)((source_x = x)&0x3FFFFFF)<<12|((y)&0xFFF)); |
| 150 | + platform_index_global = PLATFORM_LIST_START_INDEX; |
| 151 | + lift_index_global = LIFT_LIST_START_INDEX; |
| 152 | + source_y = --y; |
| 153 | + if (this.addPlatformBlock(world, x, y, z, associatedAnchorEntity.motionY < 0.0D)) { |
| 154 | + long packedPos; |
| 155 | + ; |
| 156 | + for (int i = lift_index_global; --i >= LIFT_LIST_START_INDEX;) { |
| 157 | + packedPos = platform_blocks[i]; |
| 158 | + {(x)=((int)((packedPos)<<26>>(64)-26));(z)=((int)((packedPos)>>(64)-26));(y)=((int)(packedPos)<<(32)-12>>(32)-12);}; |
| 159 | + int blockId; |
| 160 | + int blockMeta; |
| 161 | + int blockState = data_list[i]; |
| 162 | + {(blockId)=((blockState)&0xFFFF);(blockMeta)=((blockState)>>>16);}; |
| 163 | + Block block = Block.blocksList[blockId]; |
| 164 | + blockMeta = ((IBlockMixins)block).adjustMetadataForPlatformMove(blockMeta); |
| 165 | + if ( |
| 166 | + //blockId != BUFFER_STOP_ID && |
| 167 | + ((IBlockMixins)block).getMobilityFlag(world, x, y, z) != 1 && |
| 168 | + !(block instanceof BlockRailBase) |
| 169 | + ) { |
| 170 | + MovingPlatformEntity lifted_entity = (MovingPlatformEntity)EntityList.createEntityOfType( |
| 171 | + MovingPlatformEntity.class, world, |
| 172 | + (double)x + 0.5D, (double)y + 0.5D, (double)z + 0.5D, |
| 173 | + associatedAnchorEntity |
| 174 | + ); |
| 175 | + ((IMovingPlatformEntityMixins)lifted_entity).setBlockId(blockId); |
| 176 | + ((IMovingPlatformEntityMixins)lifted_entity).setBlockMeta(blockMeta); |
| 177 | + world.spawnEntityInWorld(lifted_entity); |
| 178 | + } |
| 179 | + else { |
| 180 | + BlockLiftedByPlatformEntity lifted_entity = (BlockLiftedByPlatformEntity)EntityList.createEntityOfType( |
| 181 | + BlockLiftedByPlatformEntity.class, world, |
| 182 | + (double)x + 0.5D, (double)y + 0.5D, (double)z + 0.5D |
| 183 | + ); |
| 184 | + lifted_entity.setBlockID(blockId); |
| 185 | + lifted_entity.setBlockMetadata(blockMeta); |
| 186 | + world.spawnEntityInWorld(lifted_entity); |
| 187 | + } |
| 188 | + world.setBlock(x, y, z, 0, 0, 0x02 | 0x08 | 0x20 | 0x40); |
| 189 | + } |
| 190 | + ; |
| 191 | + for (int i = platform_index_global; --i >= PLATFORM_LIST_START_INDEX;) { |
| 192 | + packedPos = platform_blocks[i]; |
| 193 | + {(x)=((int)((packedPos)<<26>>(64)-26));(z)=((int)((packedPos)>>(64)-26));(y)=((int)(packedPos)<<(32)-12>>(32)-12);}; |
| 194 | + MovingPlatformEntity moving_entity = (MovingPlatformEntity)EntityList.createEntityOfType( |
| 195 | + MovingPlatformEntity.class, world, |
| 196 | + (double)x + 0.5D, (double)y + 0.5D, (double)z + 0.5D, |
| 197 | + associatedAnchorEntity |
| 198 | + ); |
| 199 | + int blockId; |
| 200 | + int blockMeta; |
| 201 | + int blockState = data_list[i]; |
| 202 | + {(blockId)=((blockState)&0xFFFF);(blockMeta)=((blockState)>>>16);}; |
| 203 | + ((IMovingPlatformEntityMixins)moving_entity).setBlockId(blockId); |
| 204 | + ((IMovingPlatformEntityMixins)moving_entity).setBlockMeta(blockMeta); |
| 205 | + world.spawnEntityInWorld(moving_entity); |
| 206 | + world.setBlock(x, y, z, 0, 0, 0x02 | 0x08 | 0x20 | 0x40); |
| 207 | + } |
| 208 | + for (int i = lift_index_global; --i >= LIFT_LIST_START_INDEX;) { |
| 209 | + // Set x,y,z to position of block in lift list |
| 210 | + packedPos = platform_blocks[i]; |
| 211 | + world.notifyBlocksOfNeighborChange(((int)((packedPos)<<26>>(64)-26)),((int)(packedPos)<<(32)-12>>(32)-12),((int)((packedPos)>>(64)-26)), ((data_list[i])&0xFFFF)); |
| 212 | + //world.setBlock(BLOCK_POS_UNPACK_ARGS(packedPos), 0, 0, UPDATE_NEIGHBORS | UPDATE_CLIENTS | UPDATE_IMMEDIATE | UPDATE_SUPPRESS_DROPS | UPDATE_MOVE_BY_PISTON); |
| 213 | + } |
| 214 | + for (int i = platform_index_global; --i >= PLATFORM_LIST_START_INDEX;) { |
| 215 | + // Set x,y,z to position of block in platform list |
| 216 | + packedPos = platform_blocks[i]; |
| 217 | + world.notifyBlocksOfNeighborChange(((int)((packedPos)<<26>>(64)-26)),((int)(packedPos)<<(32)-12>>(32)-12),((int)((packedPos)>>(64)-26)), ((data_list[i])&0xFFFF)); |
| 218 | + //world.setBlock(BLOCK_POS_UNPACK_ARGS(packedPos), 0, 0, UPDATE_NEIGHBORS | UPDATE_CLIENTS | UPDATE_IMMEDIATE | UPDATE_SUPPRESS_DROPS | UPDATE_MOVE_BY_PISTON); |
| 219 | + } |
| 220 | + } |
| 221 | + } |
| 222 | +}; |
0 commit comments