|
| 1 | +package com.fox2code.foxloader.client.mixins; |
| 2 | + |
| 3 | +import net.minecraft.src.game.MathHelper; |
| 4 | +import net.minecraft.src.game.block.Block; |
| 5 | +import net.minecraft.src.game.entity.Entity; |
| 6 | +import net.minecraft.src.game.level.NetherPortalHandler; |
| 7 | +import net.minecraft.src.game.level.World; |
| 8 | +import org.spongepowered.asm.mixin.Mixin; |
| 9 | +import org.spongepowered.asm.mixin.Overwrite; |
| 10 | + |
| 11 | +@Mixin(NetherPortalHandler.class) |
| 12 | +public class MixinNetherPortalHandler { |
| 13 | + /** |
| 14 | + * Backport 2.9 NetherPortalHandler to 2.8.1 |
| 15 | + * |
| 16 | + * @author Fox2Code |
| 17 | + * @reason Just a hotfix |
| 18 | + */ |
| 19 | + @Overwrite |
| 20 | + public boolean useExistingPortal(World world, Entity entity) { |
| 21 | + short size = 0; |
| 22 | + if (world.worldProvider != null) { |
| 23 | + size = (short) (world.worldProvider.isHellWorld ? 16 : 128); |
| 24 | + } |
| 25 | + byte ysize = 64; |
| 26 | + double tol = -1.0D; |
| 27 | + int clsx = 0; |
| 28 | + int clsy = 0; |
| 29 | + int clsz = 0; |
| 30 | + int xpos = MathHelper.floor_double(entity.posX); |
| 31 | + int ypos = MathHelper.floor_double(entity.posY); |
| 32 | + int zpos = MathHelper.floor_double(entity.posZ); |
| 33 | + double cposy; |
| 34 | + for (int xiter = xpos - size; xiter <= xpos + size; ++xiter) { |
| 35 | + double cposx = (double) xiter + 0.5D - entity.posX; |
| 36 | + |
| 37 | + for (int ziter = zpos - size; ziter <= zpos + size; ++ziter) { |
| 38 | + double cposz = (double) ziter + 0.5D - entity.posZ; |
| 39 | + |
| 40 | + for (int yiter = ypos + ysize; yiter > ypos - ysize; yiter -= 3) { |
| 41 | + if (world.getBlockId(xiter, yiter, ziter) == Block.portal.blockID) { |
| 42 | + while (world.getBlockId(xiter, yiter - 1, ziter) == Block.portal.blockID) { |
| 43 | + --yiter; |
| 44 | + } |
| 45 | + |
| 46 | + cposy = (double) yiter + 0.5D - entity.posY; |
| 47 | + double distance = cposx * cposx + cposy * cposy + cposz * cposz; |
| 48 | + if (tol < 0.0D || distance < tol) { |
| 49 | + tol = distance; |
| 50 | + clsx = xiter; |
| 51 | + clsy = yiter; |
| 52 | + clsz = ziter; |
| 53 | + break; |
| 54 | + } |
| 55 | + } |
| 56 | + } |
| 57 | + } |
| 58 | + } |
| 59 | + |
| 60 | + if (tol >= 0.0D) { |
| 61 | + double closestx = (double) clsx + 0.5D; |
| 62 | + double closesty = (double) clsy + 0.5D; |
| 63 | + cposy = (double) clsz + 0.5D;//this variable shall now be nknown as closestz |
| 64 | + if (world.getBlockId(clsx - 1, clsy, clsz) == Block.portal.blockID) { |
| 65 | + closestx -= 0.5D; |
| 66 | + } |
| 67 | + |
| 68 | + if (world.getBlockId(clsx + 1, clsy, clsz) == Block.portal.blockID) { |
| 69 | + closestx += 0.5D; |
| 70 | + } |
| 71 | + |
| 72 | + if (world.getBlockId(clsx, clsy, clsz - 1) == Block.portal.blockID) { |
| 73 | + cposy -= 0.5D; |
| 74 | + } |
| 75 | + |
| 76 | + if (world.getBlockId(clsx, clsy, clsz + 1) == Block.portal.blockID) { |
| 77 | + cposy += 0.5D; |
| 78 | + } |
| 79 | + |
| 80 | + entity.setLocationAndAngles(closestx, closesty, cposy, entity.rotationYaw, 0.0F); |
| 81 | + entity.motionX = entity.motionY = entity.motionZ = 0.0D; |
| 82 | + return true; |
| 83 | + } else { |
| 84 | + return false; |
| 85 | + } |
| 86 | + } |
| 87 | + |
| 88 | + /** |
| 89 | + * Backport 2.9 NetherPortalHandler to 2.8.1 |
| 90 | + * |
| 91 | + * @author Fox2Code |
| 92 | + * @reason Just a hotfix |
| 93 | + */ |
| 94 | + @Overwrite |
| 95 | + public boolean makeNewPortal(World world, Entity entity) { |
| 96 | + byte size = 16; |
| 97 | + double distance = -1.0D; |
| 98 | + int cenx = MathHelper.floor_double(entity.posX); |
| 99 | + int ceny = MathHelper.floor_double(entity.posY); |
| 100 | + int cenz = MathHelper.floor_double(entity.posZ); |
| 101 | + int closestx = cenx; |
| 102 | + int closesty = ceny; |
| 103 | + int closestz = cenz; |
| 104 | + int rvidfk = 0; |
| 105 | + int rval = world.rand.nextInt(4); |
| 106 | + |
| 107 | + int xiter; |
| 108 | + double cposx; |
| 109 | + int ziter; |
| 110 | + double cposz; |
| 111 | + int yiter; |
| 112 | + int rvtr; |
| 113 | + int rvtrodd; |
| 114 | + int rvtreven; |
| 115 | + int acx; |
| 116 | + int acz; |
| 117 | + int acy; |
| 118 | + int srx; |
| 119 | + int sry; |
| 120 | + double cposy; |
| 121 | + double cdist; |
| 122 | + int fcount = 0; |
| 123 | + int ccount = 0; |
| 124 | + for (xiter = cenx - size; xiter <= cenx + size; ++xiter) {//preliminary scan for good terrain |
| 125 | + cposx = (double) xiter + 0.5D - entity.posX; |
| 126 | + |
| 127 | + for (ziter = cenz - size; ziter <= cenz + size; ++ziter) { |
| 128 | + cposz = (double) ziter + 0.5D - entity.posZ; |
| 129 | + |
| 130 | + reattemptPreliminary: |
| 131 | + for (yiter = ceny; yiter <= ceny + size; yiter++) { |
| 132 | + if (fcount > 100) { |
| 133 | + break; |
| 134 | + } |
| 135 | + if (world.isAirBlock(xiter, yiter, ziter)) { |
| 136 | + while (yiter > ceny - size - 16 && world.isAirBlock(xiter, yiter - 1, ziter)) { |
| 137 | + --yiter; |
| 138 | + fcount++; |
| 139 | + } |
| 140 | + |
| 141 | + for (rvtr = rval; rvtr < rval + 4; ++rvtr) { |
| 142 | + rvtrodd = rvtr % 2; |
| 143 | + rvtreven = 1 - rvtrodd; |
| 144 | + if (rvtr % 4 >= 2) { |
| 145 | + rvtrodd = -rvtrodd; |
| 146 | + rvtreven = -rvtreven; |
| 147 | + } |
| 148 | + for (acx = 0; acx < 4; ++acx) { |
| 149 | + for (acz = 0; acz < 4; ++acz) { |
| 150 | + for (acy = -1; acy < 4; ++acy) { |
| 151 | + srx = xiter + (acz - 1) * rvtrodd + acx * rvtreven; |
| 152 | + sry = yiter + acy; |
| 153 | + int srz = ziter + (acz - 1) * rvtreven - acx * rvtrodd; |
| 154 | + if ((acy < 0 && !world.getBlockMaterial(srx, sry, srz) |
| 155 | + .isSolid()) || (acy > -1 && !world.isAirBlock(srx, sry, srz))) { |
| 156 | + fcount++; |
| 157 | + //if (fcount<10) { |
| 158 | + continue reattemptPreliminary; |
| 159 | + //} |
| 160 | + } |
| 161 | + } |
| 162 | + } |
| 163 | + } |
| 164 | + ccount++; |
| 165 | + cposy = (double) yiter + 0.5D - entity.posY; |
| 166 | + cdist = cposx * cposx + cposy * cposy + cposz * cposz; |
| 167 | + if (distance < 0.0D || cdist < distance) { |
| 168 | + distance = cdist; |
| 169 | + closestx = xiter; |
| 170 | + closesty = yiter; |
| 171 | + closestz = ziter; |
| 172 | + rvidfk = rvtr % 4; |
| 173 | + } |
| 174 | + } |
| 175 | + } else { |
| 176 | + fcount++; |
| 177 | + break; |
| 178 | + } |
| 179 | + } |
| 180 | + } |
| 181 | + } |
| 182 | + if (fcount > 100 && ccount == 0) { |
| 183 | + distance = -1.0D; |
| 184 | + } |
| 185 | + |
| 186 | + int locx = closestx; |
| 187 | + int locy = closesty; |
| 188 | + ziter = closestz; |
| 189 | + int rvidfkodd = rvidfk % 2; |
| 190 | + int rvidfkeven = rvidfkodd ^ 1; |
| 191 | + if (rvidfk % 4 >= 2) { |
| 192 | + rvidfkodd = -rvidfkodd; |
| 193 | + rvidfkeven = -rvidfkeven; |
| 194 | + } |
| 195 | + int md = rvidfkeven + 1; |
| 196 | + |
| 197 | + boolean obi; |
| 198 | + if (distance < 0.0D) { |
| 199 | + locx = cenx; |
| 200 | + ziter = cenz; |
| 201 | + if (closesty < 70) { |
| 202 | + closesty = 70; |
| 203 | + } |
| 204 | + |
| 205 | + locy = closesty; |
| 206 | + |
| 207 | + for (yiter = -1; yiter <= 1; ++yiter) { |
| 208 | + for (rvtr = 1; rvtr < 3; ++rvtr) { |
| 209 | + for (rvtrodd = -1; rvtrodd < 3; ++rvtrodd) { |
| 210 | + rvtreven = locx + (rvtr - 1) * rvidfkodd + yiter * rvidfkeven; |
| 211 | + acx = locy + rvtrodd; |
| 212 | + acz = ziter + (rvtr - 1) * rvidfkeven - yiter * rvidfkodd; |
| 213 | + obi = rvtrodd < 0; |
| 214 | + world.setBlockWithNotify(rvtreven, acx, acz, obi ? Block.obsidian.blockID : 0); |
| 215 | + } |
| 216 | + } |
| 217 | + } |
| 218 | + } |
| 219 | + |
| 220 | + for (yiter = 0; yiter < 4; ++yiter) { |
| 221 | + world.editingBlocks = true; |
| 222 | + |
| 223 | + for (rvtr = 0; rvtr < 4; ++rvtr) { |
| 224 | + for (rvtrodd = -1; rvtrodd < 4; ++rvtrodd) { |
| 225 | + rvtreven = locx + (rvtr - 1) * rvidfkodd; |
| 226 | + acx = locy + rvtrodd; |
| 227 | + acz = ziter + (rvtr - 1) * rvidfkeven; |
| 228 | + obi = rvtr == 0 || rvtr == 3 || rvtrodd == -1 || rvtrodd == 3; |
| 229 | + if (obi) { |
| 230 | + world.setBlockWithNotify(rvtreven, acx, acz, Block.obsidian.blockID); |
| 231 | + } else { |
| 232 | + world.setBlockAndMetadataWithNotify(rvtreven, acx, acz, Block.portal.blockID, md); |
| 233 | + } |
| 234 | + } |
| 235 | + } |
| 236 | + |
| 237 | + world.editingBlocks = false; |
| 238 | + |
| 239 | + for (rvtr = 0; rvtr < 4; ++rvtr) { |
| 240 | + for (rvtrodd = -1; rvtrodd < 4; ++rvtrodd) { |
| 241 | + rvtreven = locx + (rvtr - 1) * rvidfkodd; |
| 242 | + acx = locy + rvtrodd; |
| 243 | + acz = ziter + (rvtr - 1) * rvidfkeven; |
| 244 | + world.notifyBlocksOfNeighborChange(rvtreven, acx, acz, world.getBlockId(rvtreven, acx, acz)); |
| 245 | + } |
| 246 | + } |
| 247 | + } |
| 248 | + |
| 249 | + return true; |
| 250 | + } |
| 251 | +} |
0 commit comments