diff --git a/build.gradle b/build.gradle index 4b9c2ff7..679cf552 100644 --- a/build.gradle +++ b/build.gradle @@ -31,7 +31,7 @@ sourceCompatibility = 1.8 targetCompatibility = 1.8 minecraft { - version = "1.11-13.19.1.2188" + version = "1.11-13.19.1.2199" runDir = "run" def replacementVersion = 'MOD_VERSION = \"' + project.version + '\"' @@ -39,7 +39,7 @@ minecraft { replace("MOD_VERSION = \"@MOVINGWORLDVER@\"", replacementVersion) - mappings = "snapshot_20161202" + mappings = "snapshot_20170201" } mixin { @@ -62,17 +62,16 @@ dependencies { exclude module: 'guava' } - compile 'com.unascribed:lambdanetwork:1.0.0' - shadow 'com.unascribed:lambdanetwork:1.0.0' + compile 'io.github.elytra:concrete:0.0.6' + shadow 'io.github.elytra:concrete:0.0.6' } shadowJar { exclude 'dummyThing' - relocate 'com.unascribed.lambdanetwork', "io.github.elytra.movingworld.repackage.com.unascribed.lambdanetwork" + relocate 'io.github.elytraconcrete', "io.github.elytra.movingworld.repackage.io.github.elytra.concrete" dependencies { include(dependency('org.spongepowered:mixin')) - include(dependency('com.unascribed:lambdanetwork')) } classifier = 'full' diff --git a/src/main/java/io/github/elytra/movingworld/client/expirements/MobileRegionWorldClient.java b/src/main/java/io/github/elytra/movingworld/client/expirements/MobileRegionWorldClient.java new file mode 100644 index 00000000..01ec47f2 --- /dev/null +++ b/src/main/java/io/github/elytra/movingworld/client/expirements/MobileRegionWorldClient.java @@ -0,0 +1,1445 @@ +package io.github.elytra.movingworld.client.expirements; + +import com.google.common.base.Function; +import com.google.common.base.Predicate; +import com.google.common.collect.ImmutableSetMultimap; +import io.github.elytra.movingworld.common.experiments.MobileRegion; +import net.minecraft.block.Block; +import net.minecraft.block.material.Material; +import net.minecraft.block.state.IBlockState; +import net.minecraft.client.multiplayer.ChunkProviderClient; +import net.minecraft.client.multiplayer.WorldClient; +import net.minecraft.client.network.NetHandlerPlayClient; +import net.minecraft.crash.CrashReport; +import net.minecraft.crash.CrashReportCategory; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EnumCreatureType; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.Packet; +import net.minecraft.profiler.Profiler; +import net.minecraft.scoreboard.Scoreboard; +import net.minecraft.server.MinecraftServer; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.EnumParticleTypes; +import net.minecraft.util.SoundCategory; +import net.minecraft.util.SoundEvent; +import net.minecraft.util.math.*; +import net.minecraft.village.VillageCollection; +import net.minecraft.world.*; +import net.minecraft.world.biome.Biome; +import net.minecraft.world.biome.BiomeProvider; +import net.minecraft.world.border.WorldBorder; +import net.minecraft.world.chunk.Chunk; +import net.minecraft.world.chunk.IChunkProvider; +import net.minecraft.world.gen.structure.StructureBoundingBox; +import net.minecraft.world.storage.ISaveHandler; +import net.minecraft.world.storage.MapStorage; +import net.minecraft.world.storage.WorldInfo; +import net.minecraft.world.storage.loot.LootTableManager; +import net.minecraftforge.common.ForgeChunkManager; +import net.minecraftforge.common.capabilities.Capability; +import net.minecraftforge.fml.relauncher.ReflectionHelper; + +import javax.annotation.Nullable; +import java.lang.reflect.InvocationTargetException; +import java.util.*; +import java.util.stream.Collectors; + +/** + * A wrapper for a MobileRegion and it's associated world, + */ +public class MobileRegionWorldClient extends WorldClient { + + public WorldClient realWorld; + public WorldClient parent; + + public MobileRegion region; + + public MobileRegionWorldClient(NetHandlerPlayClient netHandler, WorldSettings settings, int dimension, EnumDifficulty difficulty, Profiler profilerIn) { + super(netHandler, settings, dimension, difficulty, profilerIn); + } + + public boolean isPosWithinRegion(BlockPos pos) { + return region.isPosWithinBounds(pos); + } + + @Override + public void initCapabilities() { + try { + ReflectionHelper.findMethod(WorldClient.class, parent, new String[]{"initCapabilities"}, Void.class).invoke(null); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } + } + + @Override + public IChunkProvider createChunkProvider() { + return parent.createChunkProvider(); + } + + @Override + public boolean isChunkLoaded(int x, int z, boolean allowEmpty) { + if (region.isChunkInRegion(x, z)) + return parent.isChunkLoaded(x, z, allowEmpty); + else + return false; + } + + @Override + public void updateWeather() { + parent.updateWeather(); + } + + @Override + public void playMoodSoundAndCheckLight(int p_147467_1_, int p_147467_2_, Chunk chunkIn) { + parent.playMoodSoundAndCheckLight(p_147467_1_, p_147467_2_, chunkIn); + } + + @Override + public void buildChunkCoordList() { + } + + @Override + public void updateBlocks() { + } + + @Override + public void tickPlayers() { + } + + @Override + public void tick() { + parent.tick(); + } + + @Override + public void invalidateBlockReceiveRegion(int x1, int y1, int z1, int x2, int y2, int z2) { + parent.invalidateBlockReceiveRegion(x1, y1, z1, x2, y2, z2); + } + + @Override + public void doPreChunk(int chunkX, int chunkZ, boolean loadChunk) { + if (region.isChunkInRegion(chunkX, chunkZ)) + parent.doPreChunk(chunkX, chunkZ, loadChunk); + } + + @Override + public boolean spawnEntity(Entity entityIn) { + return parent.spawnEntity(entityIn); + } + + @Override + public void removeEntity(Entity entityIn) { + parent.removeEntity(entityIn); + } + + @Override + public void onEntityAdded(Entity entityIn) { + parent.onEntityAdded(entityIn); + } + + @Override + public void onEntityRemoved(Entity entityIn) { + parent.onEntityRemoved(entityIn); + } + + @Override + public void addEntityToWorld(int entityID, Entity entityToSpawn) { + parent.addEntityToWorld(entityID, entityToSpawn); + } + + @Nullable + @Override + public Entity getEntityByID(int id) { + return parent.getEntityByID(id); + } + + @Override + public Entity removeEntityFromWorld(int entityID) { + return parent.removeEntityFromWorld(entityID); + } + + @Override + public boolean invalidateRegionAndSetBlock(BlockPos pos, IBlockState state) { + if (region.isPosWithinBounds(pos)) + return parent.invalidateRegionAndSetBlock(pos, state); + else + return false; + } + + @Override + public void sendQuittingDisconnectingPacket() { + } + + @Override + public void doVoidFogParticles(int posX, int posY, int posZ) { + } + + @Override + public void showBarrierParticles(int p_184153_1_, int p_184153_2_, int p_184153_3_, int p_184153_4_, Random random, boolean p_184153_6_, BlockPos.MutableBlockPos pos) { + } + + @Override + public void removeAllEntities() { + parent.removeAllEntities(); + } + + @Override + public CrashReportCategory addWorldInfoToCrashReport(CrashReport report) { + return parent.addWorldInfoToCrashReport(report); + } + + @Override + public void playSound(@Nullable EntityPlayer player, double x, double y, double z, SoundEvent soundIn, SoundCategory category, float volume, float pitch) { + Vec3d pos = new Vec3d(x, y, z); + pos = region.convertRegionPosToRealWorld(pos); + parent.playSound(player, pos.xCoord, pos.yCoord, pos.zCoord, soundIn, category, volume, pitch); + } + + @Override + public void playSound(BlockPos blockPos, SoundEvent soundIn, SoundCategory category, float volume, float pitch, boolean distanceDelay) { + Vec3d pos = new Vec3d(blockPos.getX(), blockPos.getY(), blockPos.getZ()); + pos = region.convertRegionPosToRealWorld(pos); + blockPos = new BlockPos(Math.round(pos.xCoord), Math.round(pos.yCoord), Math.round(pos.zCoord)); + parent.playSound(blockPos, soundIn, category, volume, pitch, distanceDelay); + } + + @Override + public void playSound(double x, double y, double z, SoundEvent soundIn, SoundCategory category, float volume, float pitch, boolean distanceDelay) { + Vec3d pos = new Vec3d(x, y, z); + pos = region.convertRegionPosToRealWorld(pos); + parent.playSound(pos.xCoord, pos.yCoord, pos.zCoord, soundIn, category, volume, pitch, distanceDelay); + } + + @Override + public void makeFireworks(double x, double y, double z, double motionX, double motionY, double motionZ, @Nullable NBTTagCompound compund) { + Vec3d pos = new Vec3d(x, y, z); + pos = region.convertRegionPosToRealWorld(pos); + parent.makeFireworks(pos.xCoord, pos.yCoord, pos.zCoord, motionX, motionY, motionZ, compund); + } + + @Override + public void sendPacketToServer(Packet packetIn) { + parent.sendPacketToServer(packetIn); + } + + @Override + public void setWorldScoreboard(Scoreboard scoreboardIn) { + parent.setWorldScoreboard(scoreboardIn); + } + + @Override + public ChunkProviderClient getChunkProvider() { + return parent.getChunkProvider(); + } + + @Override + public World init() { + return parent.init(); + } + + @Override + public Biome getBiome(BlockPos pos) { + pos = region.convertRegionPosToRealWorld(pos); + return realWorld.getBiome(pos); + } + + @Override + public Biome getBiomeForCoordsBody(BlockPos pos) { + pos = region.convertRegionPosToRealWorld(pos); + return realWorld.getBiomeForCoordsBody(pos); + } + + @Override + public BiomeProvider getBiomeProvider() { + return realWorld.getBiomeProvider(); + } + + @Override + public void initialize(WorldSettings settings) { + parent.initialize(settings); + } + + @Nullable + @Override + public MinecraftServer getMinecraftServer() { + return parent.getMinecraftServer(); + } + + @Override + public void setInitialSpawnLocation() { + parent.setInitialSpawnLocation(); + } + + @Override + public IBlockState getGroundAboveSeaLevel(BlockPos pos) { + return parent.getGroundAboveSeaLevel(pos); + } + + @Override + public boolean isAirBlock(BlockPos pos) { + return parent.isAirBlock(pos); + } + + @Override + public boolean isBlockLoaded(BlockPos pos) { + return parent.isBlockLoaded(pos); + } + + @Override + public boolean isBlockLoaded(BlockPos pos, boolean allowEmpty) { + return parent.isBlockLoaded(pos, allowEmpty); + } + + + @Override + public Chunk getChunkFromBlockCoords(BlockPos pos) { + if (isPosWithinRegion(pos)) + return parent.getChunkFromBlockCoords(pos); + else return null; + } + + @Override + public Chunk getChunkFromChunkCoords(int chunkX, int chunkZ) { + return parent.getChunkFromChunkCoords(chunkX, chunkZ); + } + + @Override + public boolean isChunkGeneratedAt(int x, int z) { + return parent.isChunkGeneratedAt(x, z); + } + + @Override + public boolean setBlockState(BlockPos pos, IBlockState newState, int flags) { + return parent.setBlockState(pos, newState, flags); + } + + @Override + public void markAndNotifyBlock(BlockPos pos, @Nullable Chunk chunk, IBlockState iblockstate, IBlockState newState, int flags) { + parent.markAndNotifyBlock(pos, chunk, iblockstate, newState, flags); + } + + @Override + public boolean setBlockToAir(BlockPos pos) { + return parent.setBlockToAir(pos); + } + + @Override + public boolean destroyBlock(BlockPos pos, boolean dropBlock) { + return parent.destroyBlock(pos, dropBlock); + } + + @Override + public boolean setBlockState(BlockPos pos, IBlockState state) { + return parent.setBlockState(pos, state); + } + + @Override + public void notifyBlockUpdate(BlockPos pos, IBlockState oldState, IBlockState newState, int flags) { + parent.notifyBlockUpdate(pos, oldState, newState, flags); + } + + @Override + public void notifyNeighborsRespectDebug(BlockPos pos, Block blockType, boolean p_175722_3_) { + parent.notifyNeighborsRespectDebug(pos, blockType, p_175722_3_); + } + + @Override + public void markBlocksDirtyVertical(int x1, int z1, int x2, int z2) { + parent.markBlocksDirtyVertical(x1, z1, x2, z2); + } + + @Override + public void markBlockRangeForRenderUpdate(BlockPos rangeMin, BlockPos rangeMax) { + parent.markBlockRangeForRenderUpdate(rangeMin, rangeMax); + } + + @Override + public void markBlockRangeForRenderUpdate(int x1, int y1, int z1, int x2, int y2, int z2) { + parent.markBlockRangeForRenderUpdate(x1, y1, z1, x2, y2, z2); + } + + @Override + public void updateObservingBlocksAt(BlockPos pos, Block blockType) { + parent.updateObservingBlocksAt(pos, blockType); + } + + @Override + public void notifyNeighborsOfStateChange(BlockPos pos, Block blockType, boolean updateObservers) { + parent.notifyNeighborsOfStateChange(pos, blockType, updateObservers); + } + + @Override + public void notifyNeighborsOfStateExcept(BlockPos pos, Block blockType, EnumFacing skipSide) { + parent.notifyNeighborsOfStateExcept(pos, blockType, skipSide); + } + + @Override + public void neighborChanged(BlockPos pos, Block p_190524_2_, BlockPos p_190524_3_) { + parent.neighborChanged(pos, p_190524_2_, p_190524_3_); + } + + @Override + public void observedNeighborChanged(BlockPos pos, Block p_190529_2_, BlockPos p_190529_3_) { + parent.observedNeighborChanged(pos, p_190529_2_, p_190529_3_); + } + + @Override + public boolean isBlockTickPending(BlockPos pos, Block blockType) { + return parent.isBlockTickPending(pos, blockType); + } + + @Override + public boolean canSeeSky(BlockPos pos) { + return parent.canSeeSky(pos); + } + + @Override + public boolean canBlockSeeSky(BlockPos pos) { + return parent.canBlockSeeSky(pos); + } + + @Override + public int getLight(BlockPos pos) { + return parent.getLight(pos); + } + + @Override + public int getLightFromNeighbors(BlockPos pos) { + return parent.getLightFromNeighbors(pos); + } + + @Override + public int getLight(BlockPos pos, boolean checkNeighbors) { + return parent.getLight(pos, checkNeighbors); + } + + @Override + public BlockPos getHeight(BlockPos pos) { + return parent.getHeight(pos); + } + + @Override + public int getHeight(int x, int z) { + return parent.getHeight(x, z); + } + + @Override + public int getChunksLowestHorizon(int x, int z) { + return parent.getChunksLowestHorizon(x, z); + } + + @Override + public int getLightFromNeighborsFor(EnumSkyBlock type, BlockPos pos) { + if (isPosWithinRegion(pos)) + return parent.getLightFromNeighborsFor(type, pos); + else + return 0; + } + + @Override + public int getLightFor(EnumSkyBlock type, BlockPos pos) { + if (isPosWithinRegion(pos)) + return parent.getLightFor(type, pos); + else + return 0; + } + + @Override + public void setLightFor(EnumSkyBlock type, BlockPos pos, int lightValue) { + if (isPosWithinRegion(pos)) + parent.setLightFor(type, pos, lightValue); + } + + @Override + public void notifyLightSet(BlockPos pos) { + if (isPosWithinRegion(pos)) + parent.notifyLightSet(pos); + } + + @Override + public int getCombinedLight(BlockPos pos, int lightValue) { + if (isPosWithinRegion(pos)) + return parent.getCombinedLight(pos, lightValue); + else + return 0; + } + + @Override + public float getLightBrightness(BlockPos pos) { + if (isPosWithinRegion(pos)) + return parent.getLightBrightness(pos); + else + return 0F; + } + + @Override + public IBlockState getBlockState(BlockPos pos) { + if (isPosWithinRegion(pos)) + return parent.getBlockState(pos); + else + return Blocks.AIR.getDefaultState(); + } + + @Override + public boolean isDaytime() { + return parent.isDaytime(); + } + + @Nullable + @Override + public RayTraceResult rayTraceBlocks(Vec3d start, Vec3d end) { + return parent.rayTraceBlocks(start, end); + } + + @Nullable + @Override + public RayTraceResult rayTraceBlocks(Vec3d start, Vec3d end, boolean stopOnLiquid) { + return parent.rayTraceBlocks(start, end, stopOnLiquid); + } + + @Nullable + @Override + public RayTraceResult rayTraceBlocks(Vec3d vec31, Vec3d vec32, boolean stopOnLiquid, boolean ignoreBlockWithoutBoundingBox, boolean returnLastUncollidableBlock) { + return parent.rayTraceBlocks(vec31, vec32, stopOnLiquid, ignoreBlockWithoutBoundingBox, returnLastUncollidableBlock); + } + + @Override + public void playSound(@Nullable EntityPlayer player, BlockPos pos, SoundEvent soundIn, SoundCategory category, float volume, float pitch) { + realWorld.playSound(player, pos, soundIn, category, volume, pitch); + } + + @Override + public void playRecord(BlockPos blockPositionIn, @Nullable SoundEvent soundEventIn) { + realWorld.playRecord(blockPositionIn, soundEventIn); + } + + @Override + public void spawnParticle(EnumParticleTypes particleType, double xCoord, double yCoord, double zCoord, double xSpeed, double ySpeed, double zSpeed, int... parameters) { + realWorld.spawnParticle(particleType, xCoord, yCoord, zCoord, xSpeed, ySpeed, zSpeed, parameters); + } + + @Override + public void spawnAlwaysVisibleParticle(int p_190523_1_, double p_190523_2_, double p_190523_4_, double p_190523_6_, double p_190523_8_, double p_190523_10_, double p_190523_12_, int... p_190523_14_) { + realWorld.spawnAlwaysVisibleParticle(p_190523_1_, p_190523_2_, p_190523_4_, p_190523_6_, p_190523_8_, p_190523_10_, p_190523_12_, p_190523_14_); + } + + @Override + public void spawnParticle(EnumParticleTypes particleType, boolean ignoreRange, double xCoord, double yCoord, double zCoord, double xSpeed, double ySpeed, double zSpeed, int... parameters) { + realWorld.spawnParticle(particleType, ignoreRange, xCoord, yCoord, zCoord, xSpeed, ySpeed, zSpeed, parameters); + } + + @Override + public boolean addWeatherEffect(Entity entityIn) { + return realWorld.addWeatherEffect(entityIn); + } + + @Override + public void removeEntityDangerously(Entity entityIn) { + parent.removeEntityDangerously(entityIn); + } + + @Override + public void addEventListener(IWorldEventListener listener) { + parent.addEventListener(listener); + } + + @Override + public List getCollisionBoxes(@Nullable Entity entityIn, AxisAlignedBB aabb) { + return parent.getCollisionBoxes(entityIn, aabb); + } + + @Override + public boolean isInsideBorder(WorldBorder worldBorderIn, Entity entityIn) { + return parent.isInsideBorder(worldBorderIn, entityIn); + } + + @Override + public void removeEventListener(IWorldEventListener listener) { + parent.removeEventListener(listener); + } + + @Override + public boolean collidesWithAnyBlock(AxisAlignedBB bbox) { + return parent.collidesWithAnyBlock(bbox); + } + + @Override + public int calculateSkylightSubtracted(float partialTicks) { + return parent.calculateSkylightSubtracted(partialTicks); + } + + @Override + public boolean isAreaLoaded(int xStart, int yStart, int zStart, int xEnd, int yEnd, int zEnd, boolean allowEmpty) { + BlockPos start = new BlockPos(xStart, yStart, zStart); + BlockPos end = new BlockPos(xEnd, yEnd, zEnd); + + if (isPosWithinRegion(start) && isPosWithinRegion(end)) + return parent.isAreaLoaded(xStart, yStart, zStart, xEnd, yEnd, zEnd, allowEmpty); + else + return false; + } + + @Override + public float getSunBrightnessFactor(float partialTicks) { + return realWorld.getSunBrightnessFactor(partialTicks); + } + + @Override + public float getSunBrightness(float partialTicks) { + return realWorld.getSunBrightness(partialTicks); + } + + @Override + public float getSunBrightnessBody(float partialTicks) { + return realWorld.getSunBrightnessBody(partialTicks); + } + + @Override + public Vec3d getSkyColor(Entity entityIn, float partialTicks) { + return realWorld.getSkyColor(entityIn, partialTicks); + } + + @Override + public Vec3d getSkyColorBody(Entity entityIn, float partialTicks) { + return realWorld.getSkyColorBody(entityIn, partialTicks); + } + + @Override + public float getCelestialAngle(float partialTicks) { + return realWorld.getCelestialAngle(partialTicks); + } + + @Override + public int getMoonPhase() { + return realWorld.getMoonPhase(); + } + + @Override + public float getCurrentMoonPhaseFactor() { + return realWorld.getCurrentMoonPhaseFactor(); + } + + @Override + public float getCurrentMoonPhaseFactorBody() { + return realWorld.getCurrentMoonPhaseFactorBody(); + } + + @Override + public float getCelestialAngleRadians(float partialTicks) { + return realWorld.getCelestialAngleRadians(partialTicks); + } + + @Override + public Vec3d getCloudColour(float partialTicks) { + return realWorld.getCloudColour(partialTicks); + } + + @Override + public Vec3d getCloudColorBody(float partialTicks) { + return realWorld.getCloudColorBody(partialTicks); + } + + @Override + public Vec3d getFogColor(float partialTicks) { + return realWorld.getFogColor(partialTicks); + } + + @Override + public BlockPos getPrecipitationHeight(BlockPos pos) { + return realWorld.getPrecipitationHeight(pos); + } + + @Override + public BlockPos getTopSolidOrLiquidBlock(BlockPos pos) { + return realWorld.getTopSolidOrLiquidBlock(pos); + } + + @Override + public float getStarBrightness(float partialTicks) { + return realWorld.getStarBrightness(partialTicks); + } + + @Override + public float getStarBrightnessBody(float partialTicks) { + return realWorld.getStarBrightnessBody(partialTicks); + } + + @Override + public boolean isUpdateScheduled(BlockPos pos, Block blk) { + return parent.isUpdateScheduled(pos, blk); + } + + @Override + public void scheduleUpdate(BlockPos pos, Block blockIn, int delay) { + parent.scheduleUpdate(pos, blockIn, delay); + } + + @Override + public void updateBlockTick(BlockPos pos, Block blockIn, int delay, int priority) { + parent.updateBlockTick(pos, blockIn, delay, priority); + } + + @Override + public void scheduleBlockUpdate(BlockPos pos, Block blockIn, int delay, int priority) { + parent.scheduleBlockUpdate(pos, blockIn, delay, priority); + } + + @Override + public void updateEntities() { + } + + @Override + public boolean addTileEntity(TileEntity tile) { + return parent.addTileEntity(tile); + } + + @Override + public void addTileEntities(Collection tileEntityCollection) { + parent.addTileEntities(tileEntityCollection); + } + + @Override + public void updateEntity(Entity ent) { + parent.updateEntity(ent); + } + + @Override + public void updateEntityWithOptionalForce(Entity entityIn, boolean forceUpdate) { + parent.updateEntityWithOptionalForce(entityIn, forceUpdate); + } + + @Override + public boolean checkNoEntityCollision(AxisAlignedBB bb) { + return parent.checkNoEntityCollision(bb); + } + + @Override + public boolean checkNoEntityCollision(AxisAlignedBB bb, @Nullable Entity entityIn) { + return parent.checkNoEntityCollision(bb, entityIn); + } + + @Override + public boolean checkBlockCollision(AxisAlignedBB bb) { + return parent.checkBlockCollision(bb); + } + + @Override + public boolean containsAnyLiquid(AxisAlignedBB bb) { + return parent.containsAnyLiquid(bb); + } + + @Override + public boolean isFlammableWithin(AxisAlignedBB bb) { + return parent.isFlammableWithin(bb); + } + + @Override + public boolean handleMaterialAcceleration(AxisAlignedBB bb, Material materialIn, Entity entityIn) { + return parent.handleMaterialAcceleration(bb, materialIn, entityIn); + } + + @Override + public boolean isMaterialInBB(AxisAlignedBB bb, Material materialIn) { + return parent.isMaterialInBB(bb, materialIn); + } + + @Override + public Explosion createExplosion(@Nullable Entity entityIn, double x, double y, double z, float strength, boolean isSmoking) { + return parent.createExplosion(entityIn, x, y, z, strength, isSmoking); + } + + @Override + public Explosion newExplosion(@Nullable Entity entityIn, double x, double y, double z, float strength, boolean isFlaming, boolean isSmoking) { + return parent.newExplosion(entityIn, x, y, z, strength, isFlaming, isSmoking); + } + + @Override + public float getBlockDensity(Vec3d vec, AxisAlignedBB bb) { + return parent.getBlockDensity(vec, bb); + } + + @Override + public boolean extinguishFire(@Nullable EntityPlayer player, BlockPos pos, EnumFacing side) { + return parent.extinguishFire(player, pos, side); + } + + @Override + public String getDebugLoadedEntities() { + return parent.getDebugLoadedEntities(); + } + + @Override + public String getProviderName() { + return parent.getProviderName(); + } + + @Nullable + @Override + public TileEntity getTileEntity(BlockPos pos) { + if (isPosWithinRegion(pos)) + return parent.getTileEntity(pos); + else + return null; + } + + @Override + public void setTileEntity(BlockPos pos, @Nullable TileEntity tileEntityIn) { + if (isPosWithinRegion(pos)) + parent.setTileEntity(pos, tileEntityIn); + } + + @Override + public void removeTileEntity(BlockPos pos) { + if (isPosWithinRegion(pos)) + parent.removeTileEntity(pos); + } + + @Override + public void markTileEntityForRemoval(TileEntity tileEntityIn) { + parent.markTileEntityForRemoval(tileEntityIn); + } + + @Override + public boolean isBlockFullCube(BlockPos pos) { + if (isPosWithinRegion(pos)) + return parent.isBlockFullCube(pos); + else return false; + } + + @Override + public boolean isBlockNormalCube(BlockPos pos, boolean _default) { + if (isPosWithinRegion(pos)) + return parent.isBlockNormalCube(pos, _default); + else + return false; + } + + @Override + public void calculateInitialSkylight() { + parent.calculateInitialSkylight(); + } + + @Override + public void setAllowedSpawnTypes(boolean hostile, boolean peaceful) { + parent.setAllowedSpawnTypes(hostile, peaceful); + } + + @Override + public void calculateInitialWeather() { + parent.calculateInitialWeather(); + } + + @Override + public void calculateInitialWeatherBody() { + parent.calculateInitialWeatherBody(); + } + + @Override + public void updateWeatherBody() { + parent.updateWeatherBody(); + } + + @Override + public void immediateBlockTick(BlockPos pos, IBlockState state, Random random) { + if (isPosWithinRegion(pos)) + parent.immediateBlockTick(pos, state, random); + } + + @Override + public boolean canBlockFreezeWater(BlockPos pos) { + if (isPosWithinRegion(pos)) + return parent.canBlockFreezeWater(pos); + else + return false; + } + + @Override + public boolean canBlockFreezeNoWater(BlockPos pos) { + if (isPosWithinRegion(pos)) + return parent.canBlockFreezeNoWater(pos); + else + return false; + } + + @Override + public boolean canBlockFreeze(BlockPos pos, boolean noWaterAdj) { + if (isPosWithinRegion(pos)) + return parent.canBlockFreeze(pos, noWaterAdj); + else + return false; + } + + @Override + public boolean canBlockFreezeBody(BlockPos pos, boolean noWaterAdj) { + if (isPosWithinRegion(pos)) + return parent.canBlockFreezeBody(pos, noWaterAdj); + else + return false; + } + + @Override + public boolean canSnowAt(BlockPos pos, boolean checkLight) { + if (isPosWithinRegion(pos)) { + pos = region.convertRegionPosToRealWorld(pos); + return realWorld.canSnowAt(pos, checkLight); + } else { + return false; + } + } + + @Override + public boolean canSnowAtBody(BlockPos pos, boolean checkLight) { + if (isPosWithinRegion(pos)) { + pos = region.convertRegionPosToRealWorld(pos); + return realWorld.canSnowAtBody(pos, checkLight); + } else { + return false; + } + } + + @Override + public boolean checkLight(BlockPos pos) { + if (isPosWithinRegion(pos)) + return parent.checkLight(pos); + else + return false; + } + + @Override + public boolean checkLightFor(EnumSkyBlock lightType, BlockPos pos) { + if (isPosWithinRegion(pos)) + return parent.checkLightFor(lightType, pos); + else + return false; + } + + @Override + public boolean tickUpdates(boolean runAllPending) { + return parent.tickUpdates(runAllPending); + } + + @Nullable + @Override + public List getPendingBlockUpdates(Chunk chunkIn, boolean p_72920_2_) { + return parent.getPendingBlockUpdates(chunkIn, p_72920_2_); + } + + @Nullable + @Override + public List getPendingBlockUpdates(StructureBoundingBox structureBB, boolean p_175712_2_) { + return parent.getPendingBlockUpdates(structureBB, p_175712_2_); + } + + @Override + public List getEntitiesWithinAABBExcludingEntity(@Nullable Entity entityIn, AxisAlignedBB bb) { + return realWorld.getEntitiesWithinAABBExcludingEntity(entityIn, region.convertRegionBBToRealWorld(bb)); + } + + @Override + public List getEntitiesInAABBexcluding(@Nullable Entity entityIn, AxisAlignedBB bb, @Nullable Predicate predicate) { + return realWorld.getEntitiesInAABBexcluding(entityIn, region.convertRegionBBToRealWorld(bb), predicate); + } + + @Override + public List getEntities(Class entityType, Predicate filter) { + return realWorld.getEntities(entityType, filter); + } + + @Override + public List getPlayers(Class playerType, Predicate filter) { + return realWorld.getPlayers(playerType, filter); + } + + @Override + public List getEntitiesWithinAABB(Class clazz, AxisAlignedBB bb, @Nullable Predicate filter) { + return realWorld.getEntitiesWithinAABB(clazz, region.convertRegionBBToRealWorld(bb), filter); + } + + @Override + public List getEntitiesWithinAABB(Class classEntity, AxisAlignedBB bb) { + return realWorld.getEntitiesWithinAABB(classEntity, region.convertRegionBBToRealWorld(bb)); + } + + @Nullable + @Override + public T findNearestEntityWithinAABB(Class entityType, AxisAlignedBB bb, T closestTo) { + return realWorld.findNearestEntityWithinAABB(entityType, region.convertRegionBBToRealWorld(bb), closestTo); + } + + @Override + public List getLoadedEntityList() { + return realWorld.getLoadedEntityList(); + } + + @Override + public void markChunkDirty(BlockPos pos, TileEntity unusedTileEntity) { + parent.markChunkDirty(pos, unusedTileEntity); + } + + @Override + public int countEntities(Class entityType) { + return realWorld.countEntities(entityType); + } + + @Override + public void loadEntities(Collection entityCollection) { + Collection movedEntityCollection = + entityCollection.stream().map(entity -> { + Vec3d entityPos = new Vec3d(entity.posX, entity.posY, entity.posZ); + entityPos = region.convertRegionPosToRealWorld(entityPos); + entity.setPosition(entityPos.xCoord, entityPos.yCoord, entityPos.zCoord); + return entity; + }).collect(Collectors.toList()); + + realWorld.loadEntities(movedEntityCollection); + } + + @Override + public void unloadEntities(Collection entityCollection) { + realWorld.unloadEntities(entityCollection); + } + + @Override + public boolean mayPlace(Block p_190527_1_, BlockPos pos, boolean p_190527_3_, EnumFacing p_190527_4_, @Nullable Entity p_190527_5_) { + if (isPosWithinRegion(pos)) + return realWorld.mayPlace(p_190527_1_, pos, p_190527_3_, p_190527_4_, p_190527_5_); + else + return false; + } + + @Override + public int getSeaLevel() { + return parent.getSeaLevel(); + } + + @Override + public void setSeaLevel(int seaLevelIn) { + parent.setSeaLevel(seaLevelIn); + } + + @Override + public int getStrongPower(BlockPos pos, EnumFacing direction) { + return parent.getStrongPower(pos, direction); + } + + @Override + public WorldType getWorldType() { + return parent.getWorldType(); + } + + @Override + public int getStrongPower(BlockPos pos) { + return parent.getStrongPower(pos); + } + + @Override + public boolean isSidePowered(BlockPos pos, EnumFacing side) { + return parent.isSidePowered(pos, side); + } + + @Override + public int getRedstonePower(BlockPos pos, EnumFacing facing) { + return parent.getRedstonePower(pos, facing); + } + + @Override + public boolean isBlockPowered(BlockPos pos) { + return parent.isBlockPowered(pos); + } + + @Override + public int isBlockIndirectlyGettingPowered(BlockPos pos) { + return parent.isBlockIndirectlyGettingPowered(pos); + } + + @Nullable + @Override + public EntityPlayer getClosestPlayerToEntity(Entity entityIn, double distance) { + return realWorld.getClosestPlayerToEntity(entityIn, distance); + } + + @Nullable + @Override + public EntityPlayer getNearestPlayerNotCreative(Entity entityIn, double distance) { + return realWorld.getNearestPlayerNotCreative(entityIn, distance); + } + + @Nullable + @Override + public EntityPlayer getClosestPlayer(double posX, double posY, double posZ, double distance, boolean spectator) { + Vec3d pos = new Vec3d(posX, posY, posZ); + pos = region.convertRegionPosToRealWorld(pos); + + return realWorld.getClosestPlayer(pos.xCoord, pos.yCoord, pos.zCoord, distance, spectator); + } + + @Nullable + @Override + public EntityPlayer getClosestPlayer(double x, double y, double z, double distance, Predicate predicate) { + Vec3d pos = new Vec3d(x, y, z); + pos = region.convertRegionPosToRealWorld(pos); + + return realWorld.getClosestPlayer(pos.xCoord, pos.yCoord, pos.zCoord, distance, predicate); + } + + @Override + public boolean isAnyPlayerWithinRangeAt(double x, double y, double z, double range) { + Vec3d pos = new Vec3d(x, y, z); + pos = region.convertRegionPosToRealWorld(pos); + + return realWorld.isAnyPlayerWithinRangeAt(pos.xCoord, pos.yCoord, pos.zCoord, range); + } + + @Nullable + @Override + public EntityPlayer getNearestAttackablePlayer(Entity entityIn, double maxXZDistance, double maxYDistance) { + return realWorld.getNearestAttackablePlayer(entityIn, maxXZDistance, maxYDistance); + } + + @Nullable + @Override + public EntityPlayer getNearestAttackablePlayer(BlockPos pos, double maxXZDistance, double maxYDistance) { + return realWorld.getNearestAttackablePlayer(region.convertRegionPosToRealWorld(pos), maxXZDistance, maxYDistance); + } + + @Nullable + @Override + public EntityPlayer getNearestAttackablePlayer(double x, double y, double z, double maxXZDistance, double maxYDistance, @Nullable Function playerToDouble, @Nullable Predicate p_184150_12_) { + Vec3d pos = new Vec3d(x, y, z); + pos = region.convertRegionPosToRealWorld(pos); + return parent.getNearestAttackablePlayer(pos.xCoord, pos.yCoord, pos.zCoord, maxXZDistance, maxYDistance, playerToDouble, p_184150_12_); + } + + @Nullable + @Override + public EntityPlayer getPlayerEntityByName(String name) { + return realWorld.getPlayerEntityByName(name); + } + + @Nullable + @Override + public EntityPlayer getPlayerEntityByUUID(UUID uuid) { + return realWorld.getPlayerEntityByUUID(uuid); + } + + @Override + public void checkSessionLock() throws MinecraftException { + parent.checkSessionLock(); + } + + @Override + public long getSeed() { + return parent.getSeed(); + } + + @Override + public long getTotalWorldTime() { + return realWorld.getTotalWorldTime(); + } + + @Override + public void setTotalWorldTime(long worldTime) { + realWorld.setTotalWorldTime(worldTime); + } + + @Override + public long getWorldTime() { + return realWorld.getWorldTime(); + } + + @Override + public void setWorldTime(long time) { + realWorld.setWorldTime(time); + } + + @Override + public BlockPos getSpawnPoint() { + return parent.getSpawnPoint(); + } + + @Override + public void setSpawnPoint(BlockPos pos) { + parent.setSpawnPoint(pos); + } + + @Override + public void joinEntityInSurroundings(Entity entityIn) { + Vec3d entityPos = new Vec3d(entityIn.posX, entityIn.posY, entityIn.posZ); + entityPos = region.convertRegionPosToRealWorld(entityPos); + entityIn.setPosition(entityPos.xCoord, entityPos.yCoord, entityPos.zCoord); + realWorld.joinEntityInSurroundings(entityIn); + } + + @Override + public boolean isBlockModifiable(EntityPlayer player, BlockPos pos) { + return parent.isBlockModifiable(player, pos); + } + + @Override + public boolean canMineBlockBody(EntityPlayer player, BlockPos pos) { + return parent.canMineBlockBody(player, pos); + } + + @Override + public void setEntityState(Entity entityIn, byte state) { + parent.setEntityState(entityIn, state); + } + + @Override + public void addBlockEvent(BlockPos pos, Block blockIn, int eventID, int eventParam) { + parent.addBlockEvent(pos, blockIn, eventID, eventParam); + } + + @Override + public ISaveHandler getSaveHandler() { + return parent.getSaveHandler(); + } + + @Override + public WorldInfo getWorldInfo() { + return parent.getWorldInfo(); + } + + @Override + public GameRules getGameRules() { + return realWorld.getGameRules(); + } + + @Override + public void updateAllPlayersSleepingFlag() { + realWorld.updateAllPlayersSleepingFlag(); + } + + @Override + public float getThunderStrength(float delta) { + return realWorld.getThunderStrength(delta); + } + + @Override + public void setThunderStrength(float strength) { + realWorld.setThunderStrength(strength); + } + + @Override + public float getRainStrength(float delta) { + return realWorld.getRainStrength(delta); + } + + @Override + public void setRainStrength(float strength) { + realWorld.setRainStrength(strength); + } + + @Override + public boolean isThundering() { + return realWorld.isThundering(); + } + + @Override + public boolean isRaining() { + return realWorld.isRaining(); + } + + @Override + public boolean isRainingAt(BlockPos strikePosition) { + strikePosition = region.convertRegionPosToRealWorld(strikePosition); + + return realWorld.isRainingAt(strikePosition); + } + + @Override + public boolean isBlockinHighHumidity(BlockPos pos) { + pos = region.convertRegionPosToRealWorld(pos); + + return realWorld.isBlockinHighHumidity(pos); + } + + @Nullable + @Override + public MapStorage getMapStorage() { + return parent.getMapStorage(); + } + + @Override + public void setData(String dataID, WorldSavedData worldSavedDataIn) { + parent.setData(dataID, worldSavedDataIn); + } + + @Nullable + @Override + public WorldSavedData loadData(Class clazz, String dataID) { + return parent.loadData(clazz, dataID); + } + + @Override + public int getUniqueDataId(String key) { + return parent.getUniqueDataId(key); + } + + @Override + public void playBroadcastSound(int id, BlockPos pos, int data) { + parent.playBroadcastSound(id, pos, data); + } + + @Override + public void playEvent(int type, BlockPos pos, int data) { + parent.playEvent(type, pos, data); + } + + @Override + public void playEvent(@Nullable EntityPlayer player, int type, BlockPos pos, int data) { + parent.playEvent(player, type, pos, data); + } + + @Override + public int getHeight() { + return parent.getHeight(); + } + + @Override + public int getActualHeight() { + return parent.getActualHeight(); + } + + @Override + public Random setRandomSeed(int p_72843_1_, int p_72843_2_, int p_72843_3_) { + return realWorld.setRandomSeed(p_72843_1_, p_72843_2_, p_72843_3_); + } + + @Override + public double getHorizon() { + return realWorld.getHorizon(); + } + + @Override + public void sendBlockBreakProgress(int breakerId, BlockPos pos, int progress) { + parent.sendBlockBreakProgress(breakerId, pos, progress); + } + + @Override + public Calendar getCurrentDate() { + return realWorld.getCurrentDate(); + } + + @Override + public Scoreboard getScoreboard() { + return realWorld.getScoreboard(); + } + + @Override + public void updateComparatorOutputLevel(BlockPos pos, Block blockIn) { + parent.updateComparatorOutputLevel(pos, blockIn); + } + + @Override + public DifficultyInstance getDifficultyForLocation(BlockPos pos) { + pos = region.convertRegionPosToRealWorld(pos); + return realWorld.getDifficultyForLocation(pos); + } + + @Override + public EnumDifficulty getDifficulty() { + return realWorld.getDifficulty(); + } + + @Override + public int getSkylightSubtracted() { + return realWorld.getSkylightSubtracted(); + } + + @Override + public void setSkylightSubtracted(int newSkylightSubtracted) { + realWorld.setSkylightSubtracted(newSkylightSubtracted); + } + + @Override + public int getLastLightningBolt() { + return realWorld.getLastLightningBolt(); + } + + @Override + public void setLastLightningBolt(int lastLightningBoltIn) { + realWorld.setLastLightningBolt(lastLightningBoltIn); + } + + @Override + public VillageCollection getVillageCollection() { + return parent.getVillageCollection(); + } + + @Override + public WorldBorder getWorldBorder() { + return parent.getWorldBorder(); + } + + @Override + public boolean isSpawnChunk(int x, int z) { + return parent.isSpawnChunk(x, z); + } + + @Override + public boolean isSideSolid(BlockPos pos, EnumFacing side) { + return parent.isSideSolid(pos, side); + } + + @Override + public boolean isSideSolid(BlockPos pos, EnumFacing side, boolean _default) { + return parent.isSideSolid(pos, side, _default); + } + + @Override + public ImmutableSetMultimap getPersistentChunks() { + return parent.getPersistentChunks(); + } + + @Override + public Iterator getPersistentChunkIterable(Iterator chunkIterator) { + return parent.getPersistentChunkIterable(chunkIterator); + } + + @Override + public int getBlockLightOpacity(BlockPos pos) { + return parent.getBlockLightOpacity(pos); + } + + @Override + public int countEntities(EnumCreatureType type, boolean forSpawnCount) { + return realWorld.countEntities(type, forSpawnCount); + } + + + @Override + public boolean hasCapability(Capability capability, @Nullable EnumFacing facing) { + return parent.hasCapability(capability, facing); + } + + @Nullable + @Override + public T getCapability(Capability capability, @Nullable EnumFacing facing) { + return parent.getCapability(capability, facing); + } + + @Override + public MapStorage getPerWorldStorage() { + return parent.getPerWorldStorage(); + } + + @Override + public LootTableManager getLootTableManager() { + return parent.getLootTableManager(); + } + + @Nullable + @Override + public BlockPos findNearestStructure(String p_190528_1_, BlockPos pos, boolean p_190528_3_) { + pos = region.convertRegionPosToRealWorld(pos); + + return realWorld.findNearestStructure(p_190528_1_, pos, p_190528_3_); + } +} diff --git a/src/main/java/io/github/elytra/movingworld/common/chunk/ChunkIO.java b/src/main/java/io/github/elytra/movingworld/common/chunk/ChunkIO.java index 9d5bb49c..1ef2c2ab 100644 --- a/src/main/java/io/github/elytra/movingworld/common/chunk/ChunkIO.java +++ b/src/main/java/io/github/elytra/movingworld/common/chunk/ChunkIO.java @@ -90,7 +90,7 @@ public static void read(DataInput in, MobileChunk chunk) throws IOException { } } - public static byte[] writeCompressed(MobileChunk chunk, Collection blocks) { + public static ByteBuf writeCompressed(MobileChunk chunk, Collection blocks) { ByteBuf buffer = Unpooled.buffer(); try { @@ -99,7 +99,7 @@ public static byte[] writeCompressed(MobileChunk chunk, Collection blo MovingWorldMod.LOG.error(e); } - return buffer.array(); + return buffer; } public static void writeCompressed(ByteBuf buf, MobileChunk chunk, Collection blocks) throws IOException { diff --git a/src/main/java/io/github/elytra/movingworld/common/chunk/mobilechunk/world/FakeWorld.java b/src/main/java/io/github/elytra/movingworld/common/chunk/mobilechunk/world/FakeWorld.java index 0c06d04a..d27f2c38 100644 --- a/src/main/java/io/github/elytra/movingworld/common/chunk/mobilechunk/world/FakeWorld.java +++ b/src/main/java/io/github/elytra/movingworld/common/chunk/mobilechunk/world/FakeWorld.java @@ -21,7 +21,7 @@ public class FakeWorld extends World { MobileChunk mobileChunk; private FakeWorld(boolean remote, World parentWorld) { - super(parentWorld.getSaveHandler(), parentWorld.getWorldInfo(), parentWorld.provider, parentWorld.theProfiler, remote); + super(parentWorld.getSaveHandler(), parentWorld.getWorldInfo(), parentWorld.provider, parentWorld.profiler, remote); } public static FakeWorld getFakeWorld(MobileChunk chunk) { diff --git a/src/main/java/io/github/elytra/movingworld/common/entity/EntityMovingWorld.java b/src/main/java/io/github/elytra/movingworld/common/entity/EntityMovingWorld.java index a5293c57..392e2b3a 100644 --- a/src/main/java/io/github/elytra/movingworld/common/entity/EntityMovingWorld.java +++ b/src/main/java/io/github/elytra/movingworld/common/entity/EntityMovingWorld.java @@ -1,7 +1,21 @@ package io.github.elytra.movingworld.common.entity; import com.google.common.collect.Lists; - +import io.github.elytra.movingworld.MovingWorldMod; +import io.github.elytra.movingworld.api.IMovingTile; +import io.github.elytra.movingworld.common.chunk.ChunkIO; +import io.github.elytra.movingworld.common.chunk.LocatedBlock; +import io.github.elytra.movingworld.common.chunk.MovingWorldAssemblyInteractor; +import io.github.elytra.movingworld.common.chunk.MovingWorldSizeOverflowException; +import io.github.elytra.movingworld.common.chunk.assembly.AssembleResult; +import io.github.elytra.movingworld.common.chunk.assembly.ChunkDisassembler; +import io.github.elytra.movingworld.common.chunk.mobilechunk.MobileChunk; +import io.github.elytra.movingworld.common.chunk.mobilechunk.MobileChunkClient; +import io.github.elytra.movingworld.common.chunk.mobilechunk.MobileChunkServer; +import io.github.elytra.movingworld.common.util.AABBRotator; +import io.github.elytra.movingworld.common.util.MathHelperMod; +import io.github.elytra.movingworld.common.util.Vec3dMod; +import io.netty.buffer.ByteBuf; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; @@ -31,42 +45,19 @@ import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; -import java.util.Collections; -import java.util.List; -import java.util.Objects; -import java.util.Set; -import java.util.UUID; - import javax.annotation.Nullable; - -import io.github.elytra.movingworld.MovingWorldMod; -import io.github.elytra.movingworld.api.IMovingTile; -import io.github.elytra.movingworld.common.chunk.ChunkIO; -import io.github.elytra.movingworld.common.chunk.LocatedBlock; -import io.github.elytra.movingworld.common.chunk.MovingWorldAssemblyInteractor; -import io.github.elytra.movingworld.common.chunk.MovingWorldSizeOverflowException; -import io.github.elytra.movingworld.common.chunk.assembly.AssembleResult; -import io.github.elytra.movingworld.common.chunk.assembly.ChunkDisassembler; -import io.github.elytra.movingworld.common.chunk.mobilechunk.MobileChunk; -import io.github.elytra.movingworld.common.chunk.mobilechunk.MobileChunkClient; -import io.github.elytra.movingworld.common.chunk.mobilechunk.MobileChunkServer; -import io.github.elytra.movingworld.common.util.AABBRotator; -import io.github.elytra.movingworld.common.util.MathHelperMod; -import io.github.elytra.movingworld.common.util.Vec3dMod; -import io.netty.buffer.ByteBuf; +import java.io.*; +import java.util.*; /** * All moving sections of blocks extend from this class. */ public abstract class EntityMovingWorld extends EntityBoat implements IEntityAdditionalSpawnData { - public static final DataParameter IS_FLYING = EntityDataManager.createKey(EntityMovingWorld.class, DataSerializers.BOOLEAN); - private static final DataParameter THIRTY = EntityDataManager.createKey(EntityMovingWorld.class, DataSerializers.VARINT); + public static final DataParameter IS_FLYING = EntityDataManager + .createKey(EntityMovingWorld.class, DataSerializers.BOOLEAN); + private static final DataParameter THIRTY = EntityDataManager.createKey( + EntityMovingWorld.class, DataSerializers.VARINT); public EntityPlayer controllingPassenger; public float motionYaw; @@ -127,7 +118,8 @@ public static boolean isAABBInLiquidNotFall(World world, AxisAlignedBB aabb) { IBlockState blockState = world.getBlockState(new BlockPos(x, y, z)); Block block = blockState.getBlock(); - if (block != null && (blockState.getMaterial() == Material.WATER || blockState.getMaterial() == Material.LAVA)) { + if (block != null && (blockState.getMaterial() == Material.WATER + || blockState.getMaterial() == Material.LAVA)) { int j2 = block.getMetaFromState(blockState); double d0; @@ -236,8 +228,9 @@ public MovingWorldInfo getInfo() { } public void setInfo(MovingWorldInfo movingWorldInfo) { - if (movingWorldInfo == null) + if (movingWorldInfo == null) { throw new NullPointerException("Cannot set null moving world info"); + } info = movingWorldInfo; } @@ -270,10 +263,14 @@ public EntityBoat.Type getBoatType() { public void setRotatedBoundingBox() { if (mobileChunk == null) { float hw = width / 2F; - setEntityBoundingBox(new AxisAlignedBB(posX - hw, posY, posZ - hw, posX + hw, posY + height, posZ + hw)); + setEntityBoundingBox( + new AxisAlignedBB(posX - hw, posY, posZ - hw, posX + hw, posY + height, posZ + hw)); } else { - setEntityBoundingBox(new AxisAlignedBB(posX - mobileChunk.getCenterX(), posY, posZ - mobileChunk.getCenterZ(), posX + mobileChunk.getCenterX(), posY + height, posZ + mobileChunk.getCenterZ())); - setEntityBoundingBox(AABBRotator.rotateAABBAroundY(getEntityBoundingBox(), posX, posZ, (float) Math.toRadians(rotationYaw))); + setEntityBoundingBox( + new AxisAlignedBB(posX - mobileChunk.getCenterX(), posY, posZ - mobileChunk.getCenterZ(), + posX + mobileChunk.getCenterX(), posY + height, posZ + mobileChunk.getCenterZ())); + setEntityBoundingBox(AABBRotator.rotateAABBAroundY(getEntityBoundingBox(), posX, posZ, + (float) Math.toRadians(rotationYaw))); } } @@ -283,13 +280,15 @@ public void setSize(float w, float h) { width = w; height = h; float hw = w / 2F; - setEntityBoundingBox(new AxisAlignedBB(posX - hw, posY, posZ - hw, posX + hw, posY + height, posZ + hw)); + setEntityBoundingBox( + new AxisAlignedBB(posX - hw, posY, posZ - hw, posX + hw, posY + height, posZ + hw)); } } @Override @SideOnly(Side.CLIENT) - public void setPositionAndRotationDirect(double x, double y, double z, float yaw, float pitch, int inc, boolean control) { + public void setPositionAndRotationDirect(double x, double y, double z, float yaw, float pitch, + int inc, boolean control) { if (control && this.getControllingPassenger() != null) { this.prevPosX = this.posX = x; this.prevPosY = this.posY = y; @@ -373,7 +372,8 @@ protected void handleClientUpdate() { double dz = posZ + (controlZ - posZ) / controlPosRotationIncrements; double ang = MathHelper.wrapDegrees(controlYaw - rotationYaw); rotationYaw = (float) (rotationYaw + ang / controlPosRotationIncrements); - rotationPitch = (float) (rotationPitch + (controlPitch - rotationPitch) / controlPosRotationIncrements); + rotationPitch = (float) (rotationPitch + + (controlPitch - rotationPitch) / controlPosRotationIncrements); controlPosRotationIncrements--; setPosition(dx, dy, dz); setRotation(rotationYaw, rotationPitch); @@ -397,10 +397,11 @@ protected void handleClientUpdate() { protected void handleServerUpdate(double horvel) { if (getMobileChunk() != null) { - if (!getMobileChunk().movingWorldTileEntities.isEmpty()) + if (!getMobileChunk().movingWorldTileEntities.isEmpty()) { for (IMovingTile movingWorldTileEntity : getMobileChunk().movingWorldTileEntities) { movingWorldTileEntity.tick(getMobileChunk()); } + } if (!getMobileChunk().updatableTiles.isEmpty()) { for (TileEntity tickable : Lists.newArrayList(getMobileChunk().updatableTiles)) { tickable.setWorld(mobileChunk.getFakeWorld()); @@ -436,7 +437,8 @@ protected void handleServerUpdate(double horvel) { motionY *= groundFriction; motionZ *= groundFriction; } - rotationPitch = rotationPitch + (motionYaw * getCapabilities().getBankingMultiplier() - rotationPitch) * 0.15f; + rotationPitch = rotationPitch + + (motionYaw * getCapabilities().getBankingMultiplier() - rotationPitch) * 0.15f; motionYaw *= 0.7F; rotationYaw += motionYaw; setRotatedBoundingBox(); @@ -461,8 +463,9 @@ public void handleServerUpdatePreRotation() { @Override public void updatePassenger(Entity passenger) { - if (this.isPassenger(passenger)) + if (this.isPassenger(passenger)) { updatePassengerPosition(passenger, riderDestination, 1); + } } @Override @@ -473,8 +476,9 @@ public boolean isPassenger(Entity entity) { @Override public void removePassengers() { updatePassengerPosition(controllingPassenger, riderDestination, 1); - if (controllingPassenger != null) + if (controllingPassenger != null) { controllingPassenger.dismountRidingEntity(); + } } public void updatePassengerPosition(Entity passenger, BlockPos riderDestination, int flags) { @@ -496,7 +500,9 @@ public void updatePassengerPosition(Entity passenger, BlockPos riderDestination, x1 -= 1; } - IBlockState state = mobileChunk.getBlockState(new BlockPos(x1, MathHelper.floor(y1 + getMountedYOffset() + passenger.getYOffset()), z1)); + IBlockState state = mobileChunk.getBlockState( + new BlockPos(x1, MathHelper.floor(y1 + getMountedYOffset() + passenger.getYOffset()), + z1)); if (state.isOpaqueCube()) { x1 = riderDestination.getX(); y1 = riderDestination.getY(); @@ -505,7 +511,8 @@ public void updatePassengerPosition(Entity passenger, BlockPos riderDestination, } double yOff = (flags & 2) == 2 ? 0d : getMountedYOffset(); - Vec3dMod vec = new Vec3dMod(x1 - mobileChunk.getCenterX() + 0.5d, y1 - mobileChunk.minY() + yOff, z1 - mobileChunk.getCenterZ() + 0.5d); + Vec3dMod vec = new Vec3dMod(x1 - mobileChunk.getCenterX() + 0.5d, + y1 - mobileChunk.minY() + yOff, z1 - mobileChunk.getCenterZ() + 0.5d); switch (frontDir) { case 0: vec = vec.rotateAroundZ(-pitch); @@ -522,10 +529,12 @@ public void updatePassengerPosition(Entity passenger, BlockPos riderDestination, } vec = vec.rotateAroundY(yaw); - if ((flags & 1) == 1) + if ((flags & 1) == 1) { vec.addVector(0, 0.25, 0); + } - passenger.setPosition(posX + vec.xCoord, posY + vec.yCoord + passenger.getYOffset(), posZ + vec.zCoord); + passenger.setPosition(posX + vec.xCoord, posY + vec.yCoord + passenger.getYOffset(), + posZ + vec.zCoord); this.applyYawToEntity(passenger); } @@ -543,8 +552,11 @@ public Entity getControllingPassenger() { @Override public List getPassengers() { - if (controllingPassenger != null) return Lists.newArrayList(controllingPassenger); - else return Collections.emptyList(); + if (controllingPassenger != null) { + return Lists.newArrayList(controllingPassenger); + } else { + return Collections.emptyList(); + } } @Override @@ -559,15 +571,18 @@ protected void addPassenger(Entity passenger) { if (passenger.getRidingEntity() != this) { throw new IllegalStateException("Use x.startRiding(y), not y.addPassenger(x)"); } else { - if (controllingPassenger == null && passenger != null && passenger instanceof EntityPlayer) + if (controllingPassenger == null && passenger != null + && passenger instanceof EntityPlayer) { controllingPassenger = (EntityPlayer) passenger; + } } } private boolean handleCollision(double cPosX, double cPosY, double cPosZ) { boolean didCollide = false; if (!world.isRemote) { - List list = world.getEntitiesWithinAABBExcludingEntity(this, getEntityBoundingBox().expand(0.2D, 0.0D, 0.2D)); + List list = world.getEntitiesWithinAABBExcludingEntity(this, + getEntityBoundingBox().expand(0.2D, 0.0D, 0.2D)); if (list != null && !list.isEmpty()) { didCollide = true; for (Entity entity : list) { @@ -700,7 +715,8 @@ public void alignToGrid(boolean doPosAdjustment) { rotationYaw = Math.round(rotationYaw / 90F) * 90F; rotationPitch = 0F; - Vec3d vec = new Vec3d(-mobileChunk.getCenterX(), -mobileChunk.minY(), -mobileChunk.getCenterZ()); + Vec3d vec = new Vec3d(-mobileChunk.getCenterX(), -mobileChunk.minY(), + -mobileChunk.getCenterZ()); vec = vec.rotateYaw((float) Math.toRadians(rotationYaw)); int ix = MathHelperMod.round_double(vec.xCoord + posX); @@ -715,7 +731,9 @@ public void alignToGrid(boolean doPosAdjustment) { } public boolean disassemble(boolean overwrite) { - if (world.isRemote) return true; + if (world.isRemote) { + return true; + } updatePassenger(this.getControllingPassenger()); @@ -752,7 +770,9 @@ public void dropAsItems() { blockState = mobileChunk.getBlockState(new BlockPos(i, j, k)); if (blockState.getBlock() != Blocks.AIR) { - blockState.getBlock().dropBlockAsItem(world, new BlockPos(MathHelper.floor(posX), MathHelper.floor(posY), MathHelper.floor(posZ)), blockState, 0); + blockState.getBlock().dropBlockAsItem(world, + new BlockPos(MathHelper.floor(posX), MathHelper.floor(posY), + MathHelper.floor(posZ)), blockState, 0); } } } @@ -760,9 +780,14 @@ public void dropAsItems() { } protected void fillAirBlocks(Set set, BlockPos pos) { - if (pos.getX() < mobileChunk.minX() - 1 || pos.getX() > mobileChunk.maxX() || pos.getY() < mobileChunk.minY() - 1 || pos.getY() > mobileChunk.maxY() || pos.getZ() < mobileChunk.minZ() - 1 || pos.getZ() > mobileChunk.maxZ()) + if (pos.getX() < mobileChunk.minX() - 1 || pos.getX() > mobileChunk.maxX() + || pos.getY() < mobileChunk.minY() - 1 || pos.getY() > mobileChunk.maxY() + || pos.getZ() < mobileChunk.minZ() - 1 || pos.getZ() > mobileChunk.maxZ()) { return; - if (set.contains(pos)) return; + } + if (set.contains(pos)) { + return; + } set.add(pos); if (mobileChunk.setBlockAsFilledAir(pos)) { @@ -881,7 +906,8 @@ protected void readEntityFromNBT(NBTTagCompound tag) { markerComp.getInteger("markerPosY"), markerComp.getInteger("markerPosZ")); - mobileChunk.marker = new LocatedBlock(mobileChunk.getBlockState(markerPos), mobileChunk.getTileEntity(markerPos), markerPos); + mobileChunk.marker = new LocatedBlock(mobileChunk.getBlockState(markerPos), + mobileChunk.getTileEntity(markerPos), markerPos); } info = new MovingWorldInfo(); @@ -925,9 +951,12 @@ public void writeSpawnData(ByteBuf data) { */ @Override protected void resetHeight() { - float sqrtMotion = MathHelper.sqrt(this.motionX * this.motionX * 0.20000000298023224D + this.motionY * this.motionY + this.motionZ * this.motionZ * 0.20000000298023224D) * 0.2F; + float sqrtMotion = MathHelper.sqrt( + this.motionX * this.motionX * 0.20000000298023224D + this.motionY * this.motionY + + this.motionZ * this.motionZ * 0.20000000298023224D) * 0.2F; sqrtMotion = sqrtMotion > 1.0F ? 1.0F : sqrtMotion; - this.playSound(this.getSplashSound(), sqrtMotion, 1.0F + (this.rand.nextFloat() - this.rand.nextFloat()) * 0.4F); + this.playSound(this.getSplashSound(), sqrtMotion, + 1.0F + (this.rand.nextFloat() - this.rand.nextFloat()) * 0.4F); } public abstract void writeMovingWorldSpawnData(ByteBuf data); diff --git a/src/main/java/io/github/elytra/movingworld/common/entity/MovingWorldHandlerClient.java b/src/main/java/io/github/elytra/movingworld/common/entity/MovingWorldHandlerClient.java index bd334124..a5789f7a 100644 --- a/src/main/java/io/github/elytra/movingworld/common/entity/MovingWorldHandlerClient.java +++ b/src/main/java/io/github/elytra/movingworld/common/entity/MovingWorldHandlerClient.java @@ -1,14 +1,10 @@ package io.github.elytra.movingworld.common.entity; -import com.unascribed.lambdanetwork.PendingPacket; +import io.github.elytra.movingworld.common.network.message.FarInteractMessage; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.init.Blocks; -import net.minecraft.item.ItemStack; import net.minecraft.util.EnumHand; -import io.github.elytra.movingworld.common.network.MovingWorldNetworking; - public abstract class MovingWorldHandlerClient extends MovingWorldHandlerCommon { public MovingWorldHandlerClient(EntityMovingWorld movingWorld) { super(movingWorld); @@ -17,11 +13,7 @@ public MovingWorldHandlerClient(EntityMovingWorld movingWorld) { @Override public boolean processInitialInteract(EntityPlayer player, EnumHand hand) { if (player.getDistanceSqToEntity(getMovingWorld()) >= 36D) { - PendingPacket packet = MovingWorldNetworking.NETWORK.send().packet("FarInteractMessage") - .with("dimID", getMovingWorld().world.provider.getDimension()) - .with("entityID", getMovingWorld().getEntityId()) - .with("hand", hand.ordinal()); - packet.toServer(); + new FarInteractMessage(getMovingWorld(), hand).sendToServer(); } return super.processInitialInteract(player, hand); diff --git a/src/main/java/io/github/elytra/movingworld/common/entity/MovingWorldHandlerServer.java b/src/main/java/io/github/elytra/movingworld/common/entity/MovingWorldHandlerServer.java index cc49ee03..51f4a70e 100644 --- a/src/main/java/io/github/elytra/movingworld/common/entity/MovingWorldHandlerServer.java +++ b/src/main/java/io/github/elytra/movingworld/common/entity/MovingWorldHandlerServer.java @@ -1,19 +1,18 @@ package io.github.elytra.movingworld.common.entity; +import io.github.elytra.movingworld.MovingWorldMod; +import io.github.elytra.movingworld.common.chunk.ChunkIO; +import io.github.elytra.movingworld.common.chunk.mobilechunk.MobileChunkServer; +import io.github.elytra.movingworld.common.network.message.MovingWorldBlockChangeMessage; +import io.github.elytra.movingworld.common.network.message.MovingWorldTileChangeMessage; +import io.github.elytra.movingworld.common.tile.TileMovingMarkingBlock; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumHand; import net.minecraft.util.math.BlockPos; -import io.github.elytra.movingworld.MovingWorldMod; -import io.github.elytra.movingworld.common.chunk.ChunkIO; -import io.github.elytra.movingworld.common.chunk.mobilechunk.MobileChunkServer; -import io.github.elytra.movingworld.common.network.MovingWorldNetworking; -import io.github.elytra.movingworld.common.tile.TileMovingMarkingBlock; - public abstract class MovingWorldHandlerServer extends MovingWorldHandlerCommon { protected boolean firstChunkUpdate; @@ -40,13 +39,10 @@ public void onChunkUpdate() { if (getMobileChunkServer() != null) { if (!firstChunkUpdate) { if (!getMobileChunkServer().getBlockQueue().isEmpty()) { - MovingWorldNetworking.NETWORK.send().packet("ChunkBlockUpdateMessage") - .with("dimID", getMovingWorld().world.provider.getDimension()) - .with("entityID", getMovingWorld().getEntityId()) - .with("chunk", ChunkIO.writeCompressed(getMovingWorld().getMobileChunk(), getMobileChunkServer().getBlockQueue())) - .toAllAround(getMovingWorld().world, getMovingWorld(), 64D); + new MovingWorldBlockChangeMessage(getMovingWorld(), + ChunkIO.writeCompressed(getMovingWorld().getMobileChunk(), getMobileChunkServer().getBlockQueue())).sendToAllWatching(getMovingWorld()); - MovingWorldMod.LOG.debug("MobileChunk block change detected, sending packet to all within 64 blocks of " + getMovingWorld().toString()); + MovingWorldMod.LOG.debug("MobileChunk block change detected, sending packet to all players watching " + getMovingWorld().toString()); } if (!getMobileChunkServer().getTileQueue().isEmpty()) { NBTTagCompound tagCompound = new NBTTagCompound(); @@ -66,12 +62,8 @@ public void onChunkUpdate() { } tagCompound.setTag("list", list); - MovingWorldNetworking.NETWORK.send().packet("TileEntitiesMessage") - .with("dimID", getMovingWorld().dimension) - .with("entityID", getMovingWorld().getEntityId()) - .with("tagCompound", tagCompound) - .toAllAround(getMovingWorld().world, getMovingWorld(), 64D); - MovingWorldMod.LOG.debug("MobileChunk tile change detected, sending packet to all within 64 blocks of " + getMovingWorld().toString()); + new MovingWorldTileChangeMessage(getMovingWorld(), tagCompound).sendToAllWatching(getMovingWorld()); + MovingWorldMod.LOG.debug("MobileChunk tile change detected, sending packet to all players watching " + getMovingWorld().toString()); } } getMobileChunkServer().getTileQueue().clear(); diff --git a/src/main/java/io/github/elytra/movingworld/common/experiments/MobileRegion.java b/src/main/java/io/github/elytra/movingworld/common/experiments/MobileRegion.java index f05076e9..8aecee56 100644 --- a/src/main/java/io/github/elytra/movingworld/common/experiments/MobileRegion.java +++ b/src/main/java/io/github/elytra/movingworld/common/experiments/MobileRegion.java @@ -1,13 +1,13 @@ package io.github.elytra.movingworld.common.experiments; +import net.minecraft.util.math.AxisAlignedBB; +import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.ChunkPos; +import net.minecraft.util.math.Vec3d; public class MobileRegion { - /** - * The size of a chunk, 16x16 - */ - public static int chunkSize = 16; + public double x, y, z; public ChunkPos regionMin; public ChunkPos regionMax; @@ -16,4 +16,72 @@ public MobileRegion(ChunkPos regionMin, ChunkPos regionMax) { this.regionMin = regionMin; this.regionMax = regionMax; } + + public boolean isPosWithinBounds(BlockPos pos) { + BlockPos min = minBlockPos(); + BlockPos max = maxBlockPos(); + + boolean withinMin = (pos.getX() >= min.getX()) && (pos.getY() >= min.getY()) && (pos.getZ() >= min.getZ()); + boolean withinMax = (pos.getX() <= max.getX()) && (pos.getY() <= max.getY()) && (pos.getZ() <= max.getZ()); + + return withinMin && withinMax; + } + + public boolean isChunkInRegion(int x, int z) { + return x >= regionMin.chunkXPos && x <= regionMax.chunkXPos + && z >= regionMin.chunkZPos && z <= regionMax.chunkZPos; + } + + public BlockPos minBlockPos() { + return new BlockPos(regionMin.getXStart(), 0, regionMin.getZStart()); + } + + public BlockPos maxBlockPos() { + return new BlockPos(regionMax.getXEnd(), 256 - 1, regionMax.getZEnd()); + } + + /** + * Converts a given Vec3d's position to the real position in the parent world. + * @param regionPos + * @return + */ + public Vec3d convertRegionPosToRealWorld(Vec3d regionPos) { + Vec3d adjustedPosition = new Vec3d(regionPos.xCoord - regionMin.getXStart() + x, + regionPos.yCoord + y, + regionPos.zCoord - regionMin.getZStart() + z); + + return adjustedPosition; + } + + /** + * Converts a given Vec3d's position from the real world into a position for internal region use. + * @param realWorldPos + * @return + */ + public Vec3d convertRealWorldPosToRegion(Vec3d realWorldPos) { + Vec3d adjustedPosition = new Vec3d(realWorldPos.xCoord + regionMin.getXStart() - x, + realWorldPos.yCoord - y, + realWorldPos.zCoord + regionMin.getZStart() - z); + + return adjustedPosition; + } + + public BlockPos convertRegionPosToRealWorld(BlockPos pos) { + Vec3d vec3DPos = new Vec3d(pos.getX(),pos.getY(), pos.getZ()); + vec3DPos = convertRegionPosToRealWorld(vec3DPos); + return new BlockPos(Math.round(vec3DPos.xCoord), Math.round(vec3DPos.yCoord), Math.round(vec3DPos.zCoord)); + } + + public BlockPos convertRealWorldPosToRegion(BlockPos pos) { + Vec3d vec3DPos = new Vec3d(pos.getX(),pos.getY(), pos.getZ()); + vec3DPos = convertRealWorldPosToRegion(vec3DPos); + return new BlockPos(Math.round(vec3DPos.xCoord), Math.round(vec3DPos.yCoord), Math.round(vec3DPos.zCoord)); + } + + public AxisAlignedBB convertRegionBBToRealWorld(AxisAlignedBB regionBB){ + Vec3d min = convertRegionPosToRealWorld(new Vec3d(regionBB.minX, regionBB.minY, regionBB.minZ)); + Vec3d max = convertRegionPosToRealWorld(new Vec3d(regionBB.maxX, regionBB.maxY, regionBB.maxZ)); + + return new AxisAlignedBB(min.xCoord,min.yCoord,min.zCoord, max.xCoord,max.yCoord, max.zCoord); + } } diff --git a/src/main/java/io/github/elytra/movingworld/common/experiments/MobileRegionWorldServer.java b/src/main/java/io/github/elytra/movingworld/common/experiments/MobileRegionWorldServer.java new file mode 100644 index 00000000..e27a7554 --- /dev/null +++ b/src/main/java/io/github/elytra/movingworld/common/experiments/MobileRegionWorldServer.java @@ -0,0 +1,1423 @@ +package io.github.elytra.movingworld.common.experiments; + +import com.google.common.base.Function; +import com.google.common.base.Predicate; +import com.google.common.collect.ImmutableSetMultimap; +import com.google.common.util.concurrent.ListenableFuture; +import net.minecraft.block.Block; +import net.minecraft.block.material.Material; +import net.minecraft.block.state.IBlockState; +import net.minecraft.client.multiplayer.ChunkProviderClient; +import net.minecraft.crash.CrashReport; +import net.minecraft.crash.CrashReportCategory; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityTracker; +import net.minecraft.entity.EnumCreatureType; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.Packet; +import net.minecraft.profiler.Profiler; +import net.minecraft.scoreboard.Scoreboard; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.management.PlayerChunkMap; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.*; +import net.minecraft.util.math.*; +import net.minecraft.village.VillageCollection; +import net.minecraft.world.*; +import net.minecraft.world.biome.Biome; +import net.minecraft.world.biome.BiomeProvider; +import net.minecraft.world.border.WorldBorder; +import net.minecraft.world.chunk.Chunk; +import net.minecraft.world.chunk.IChunkProvider; +import net.minecraft.world.gen.ChunkProviderServer; +import net.minecraft.world.gen.structure.StructureBoundingBox; +import net.minecraft.world.gen.structure.template.TemplateManager; +import net.minecraft.world.storage.ISaveHandler; +import net.minecraft.world.storage.MapStorage; +import net.minecraft.world.storage.WorldInfo; +import net.minecraft.world.storage.loot.LootTableManager; +import net.minecraftforge.common.ForgeChunkManager; +import net.minecraftforge.common.capabilities.Capability; +import net.minecraftforge.fml.relauncher.ReflectionHelper; +import org.spongepowered.asm.lib.tree.ClassNode; +import org.spongepowered.asm.util.ASMHelper; + +import javax.annotation.Nullable; +import java.io.File; +import java.lang.reflect.InvocationTargetException; +import java.util.*; + +/** + * Created by darkevilmac on 2/3/2017. + */ +public class MobileRegionWorldServer extends WorldServer { + + public WorldServer parent; + public MobileRegion region; + + public MobileRegionWorldServer(MinecraftServer server, ISaveHandler saveHandlerIn, WorldInfo info, int dimensionId, Profiler profilerIn) { + super(server, saveHandlerIn, info, dimensionId, profilerIn); + } + + @Override + public void initCapabilities() { + try { + ReflectionHelper.findMethod(WorldServer.class, parent, new String[]{"initCapabilities"}, Void.class).invoke(null); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } + } + + @Override + public IChunkProvider createChunkProvider() { + return parent.createChunkProvider(); + } + + @Override + public boolean isChunkLoaded(int x, int z, boolean allowEmpty) { + return parent.isChunkLoaded(x, z, allowEmpty); + } + + @Override + public void updateWeather() { + parent.updateWeather(); + } + + @Override + public void playMoodSoundAndCheckLight(int p_147467_1_, int p_147467_2_, Chunk chunkIn) { + parent.playMoodSoundAndCheckLight(p_147467_1_, p_147467_2_, chunkIn); + } + + @Override + public void wakeAllPlayers() { + parent.wakeAllPlayers(); + } + + @Override + public void playerCheckLight() { + parent.playerCheckLight(); + } + + @Override + public BlockPos adjustPosToNearbyEntity(BlockPos pos) { + return parent.adjustPosToNearbyEntity(pos); + } + + @Override + public void createBonusChest() { + parent.createBonusChest(); + } + + @Override + public void saveLevel() throws MinecraftException { + parent.saveLevel(); + } + + @Override + public void calculateInitialWeather() { + parent.calculateInitialWeather(); + } + + @Nullable + @Override + public Biome.SpawnListEntry getSpawnListEntryForTypeAt(EnumCreatureType creatureType, BlockPos pos) { + return parent.getSpawnListEntryForTypeAt(creatureType, pos); + } + + @Override + public boolean canCreatureTypeSpawnHere(EnumCreatureType creatureType, Biome.SpawnListEntry spawnListEntry, BlockPos pos) { + return parent.canCreatureTypeSpawnHere(creatureType, spawnListEntry, pos); + } + + @Override + public boolean areAllPlayersAsleep() { + return parent.areAllPlayersAsleep(); + } + + @Override + public void resetUpdateEntityTick() { + parent.resetUpdateEntityTick(); + } + + @Nullable + @Override + public BlockPos getSpawnCoordinate() { + return parent.getSpawnCoordinate(); + } + + @Override + public void saveAllChunks(boolean p_73044_1_, @Nullable IProgressUpdate progressCallback) throws MinecraftException { + parent.saveAllChunks(p_73044_1_, progressCallback); + } + + @Override + public void saveChunkData() { + parent.saveChunkData(); + } + + @Override + public void flush() { + parent.flush(); + } + + @Override + public EntityTracker getEntityTracker() { + return parent.getEntityTracker(); + } + + @Override + public PlayerChunkMap getPlayerChunkMap() { + return parent.getPlayerChunkMap(); + } + + @Override + public Teleporter getDefaultTeleporter() { + return parent.getDefaultTeleporter(); + } + + @Override + public TemplateManager getStructureTemplateManager() { + return parent.getStructureTemplateManager(); + } + + @Override + public void spawnParticle(EnumParticleTypes particleType, double xCoord, double yCoord, double zCoord, int numberOfParticles, double xOffset, double yOffset, double zOffset, double particleSpeed, int... particleArguments) { + parent.spawnParticle(particleType, xCoord, yCoord, zCoord, numberOfParticles, xOffset, yOffset, zOffset, particleSpeed, particleArguments); + } + + @Override + public void spawnParticle(EnumParticleTypes particleType, boolean longDistance, double xCoord, double yCoord, double zCoord, int numberOfParticles, double xOffset, double yOffset, double zOffset, double particleSpeed, int... particleArguments) { + parent.spawnParticle(particleType, longDistance, xCoord, yCoord, zCoord, numberOfParticles, xOffset, yOffset, zOffset, particleSpeed, particleArguments); + } + + @Override + public void spawnParticle(EntityPlayerMP player, EnumParticleTypes particle, boolean longDistance, double x, double y, double z, int count, double xOffset, double yOffset, double zOffset, double speed, int... arguments) { + parent.spawnParticle(player, particle, longDistance, x, y, z, count, xOffset, yOffset, zOffset, speed, arguments); + } + + @Nullable + @Override + public Entity getEntityFromUuid(UUID uuid) { + return parent.getEntityFromUuid(uuid); + } + + @Override + public ListenableFuture addScheduledTask(Runnable runnableToSchedule) { + return parent.addScheduledTask(runnableToSchedule); + } + + @Override + public boolean isCallingFromMinecraftThread() { + return parent.isCallingFromMinecraftThread(); + } + + @Override + public File getChunkSaveLocation() { + return parent.getChunkSaveLocation(); + } + + @Override + public void updateBlocks() { + } + + @Override + public void tickPlayers() { + } + + @Override + public void tick() { + parent.tick(); + } + + @Override + public boolean spawnEntity(Entity entityIn) { + return parent.spawnEntity(entityIn); + } + + @Override + public void removeEntity(Entity entityIn) { + parent.removeEntity(entityIn); + } + + @Override + public void onEntityAdded(Entity entityIn) { + parent.onEntityAdded(entityIn); + } + + @Override + public void onEntityRemoved(Entity entityIn) { + parent.onEntityRemoved(entityIn); + } + + @Nullable + @Override + public Entity getEntityByID(int id) { + return parent.getEntityByID(id); + } + + @Override + public void sendQuittingDisconnectingPacket() { + parent.sendQuittingDisconnectingPacket(); + } + + @Override + public CrashReportCategory addWorldInfoToCrashReport(CrashReport report) { + return parent.addWorldInfoToCrashReport(report); + } + + @Override + public void playSound(@Nullable EntityPlayer player, double x, double y, double z, SoundEvent soundIn, SoundCategory category, float volume, float pitch) { + parent.playSound(player, x, y, z, soundIn, category, volume, pitch); + } + + @Override + public void playSound(double x, double y, double z, SoundEvent soundIn, SoundCategory category, float volume, float pitch, boolean distanceDelay) { + parent.playSound(x, y, z, soundIn, category, volume, pitch, distanceDelay); + } + + @Override + public void makeFireworks(double x, double y, double z, double motionX, double motionY, double motionZ, @Nullable NBTTagCompound compund) { + parent.makeFireworks(x, y, z, motionX, motionY, motionZ, compund); + } + + @Override + public void sendPacketToServer(Packet packetIn) { + parent.sendPacketToServer(packetIn); + } + + @Override + public ChunkProviderServer getChunkProvider() { + return parent.getChunkProvider(); + } + + @Override + public World init() { + return parent.init(); + } + + @Override + public Biome getBiome(BlockPos pos) { + return parent.getBiome(pos); + } + + @Override + public Biome getBiomeForCoordsBody(BlockPos pos) { + return parent.getBiomeForCoordsBody(pos); + } + + @Override + public BiomeProvider getBiomeProvider() { + return parent.getBiomeProvider(); + } + + @Override + public void initialize(WorldSettings settings) { + parent.initialize(settings); + } + + @Nullable + @Override + public MinecraftServer getMinecraftServer() { + return parent.getMinecraftServer(); + } + + @Override + public void setInitialSpawnLocation() { + parent.setInitialSpawnLocation(); + } + + @Override + public IBlockState getGroundAboveSeaLevel(BlockPos pos) { + return parent.getGroundAboveSeaLevel(pos); + } + + @Override + public boolean isAirBlock(BlockPos pos) { + return parent.isAirBlock(pos); + } + + @Override + public boolean isBlockLoaded(BlockPos pos) { + return parent.isBlockLoaded(pos); + } + + @Override + public boolean isBlockLoaded(BlockPos pos, boolean allowEmpty) { + return parent.isBlockLoaded(pos, allowEmpty); + } + + @Override + public boolean isAreaLoaded(BlockPos center, int radius) { + return parent.isAreaLoaded(center, radius); + } + + @Override + public boolean isAreaLoaded(BlockPos center, int radius, boolean allowEmpty) { + return parent.isAreaLoaded(center, radius, allowEmpty); + } + + @Override + public boolean isAreaLoaded(BlockPos from, BlockPos to) { + return parent.isAreaLoaded(from, to); + } + + @Override + public boolean isAreaLoaded(BlockPos from, BlockPos to, boolean allowEmpty) { + return parent.isAreaLoaded(from, to, allowEmpty); + } + + @Override + public boolean isAreaLoaded(StructureBoundingBox box) { + return parent.isAreaLoaded(box); + } + + @Override + public boolean isAreaLoaded(StructureBoundingBox box, boolean allowEmpty) { + return parent.isAreaLoaded(box, allowEmpty); + } + + @Override + public Chunk getChunkFromBlockCoords(BlockPos pos) { + return parent.getChunkFromBlockCoords(pos); + } + + @Override + public Chunk getChunkFromChunkCoords(int chunkX, int chunkZ) { + return parent.getChunkFromChunkCoords(chunkX, chunkZ); + } + + @Override + public boolean isChunkGeneratedAt(int x, int z) { + return parent.isChunkGeneratedAt(x, z); + } + + @Override + public boolean setBlockState(BlockPos pos, IBlockState newState, int flags) { + return parent.setBlockState(pos, newState, flags); + } + + @Override + public void markAndNotifyBlock(BlockPos pos, @Nullable Chunk chunk, IBlockState iblockstate, IBlockState newState, int flags) { + parent.markAndNotifyBlock(pos, chunk, iblockstate, newState, flags); + } + + @Override + public boolean setBlockToAir(BlockPos pos) { + return parent.setBlockToAir(pos); + } + + @Override + public boolean destroyBlock(BlockPos pos, boolean dropBlock) { + return parent.destroyBlock(pos, dropBlock); + } + + @Override + public boolean setBlockState(BlockPos pos, IBlockState state) { + return parent.setBlockState(pos, state); + } + + @Override + public void notifyBlockUpdate(BlockPos pos, IBlockState oldState, IBlockState newState, int flags) { + parent.notifyBlockUpdate(pos, oldState, newState, flags); + } + + @Override + public void notifyNeighborsRespectDebug(BlockPos pos, Block blockType, boolean p_175722_3_) { + parent.notifyNeighborsRespectDebug(pos, blockType, p_175722_3_); + } + + @Override + public void markBlocksDirtyVertical(int x1, int z1, int x2, int z2) { + parent.markBlocksDirtyVertical(x1, z1, x2, z2); + } + + @Override + public void markBlockRangeForRenderUpdate(BlockPos rangeMin, BlockPos rangeMax) { + parent.markBlockRangeForRenderUpdate(rangeMin, rangeMax); + } + + @Override + public void markBlockRangeForRenderUpdate(int x1, int y1, int z1, int x2, int y2, int z2) { + parent.markBlockRangeForRenderUpdate(x1, y1, z1, x2, y2, z2); + } + + @Override + public void updateObservingBlocksAt(BlockPos pos, Block blockType) { + parent.updateObservingBlocksAt(pos, blockType); + } + + @Override + public void notifyNeighborsOfStateChange(BlockPos pos, Block blockType, boolean updateObservers) { + parent.notifyNeighborsOfStateChange(pos, blockType, updateObservers); + } + + @Override + public void notifyNeighborsOfStateExcept(BlockPos pos, Block blockType, EnumFacing skipSide) { + parent.notifyNeighborsOfStateExcept(pos, blockType, skipSide); + } + + @Override + public void neighborChanged(BlockPos pos, Block p_190524_2_, BlockPos p_190524_3_) { + parent.neighborChanged(pos, p_190524_2_, p_190524_3_); + } + + @Override + public void observedNeighborChanged(BlockPos pos, Block p_190529_2_, BlockPos p_190529_3_) { + parent.observedNeighborChanged(pos, p_190529_2_, p_190529_3_); + } + + @Override + public boolean isBlockTickPending(BlockPos pos, Block blockType) { + return parent.isBlockTickPending(pos, blockType); + } + + @Override + public boolean canSeeSky(BlockPos pos) { + return parent.canSeeSky(pos); + } + + @Override + public boolean canBlockSeeSky(BlockPos pos) { + return parent.canBlockSeeSky(pos); + } + + @Override + public int getLight(BlockPos pos) { + return parent.getLight(pos); + } + + @Override + public int getLightFromNeighbors(BlockPos pos) { + return parent.getLightFromNeighbors(pos); + } + + @Override + public int getLight(BlockPos pos, boolean checkNeighbors) { + return parent.getLight(pos, checkNeighbors); + } + + @Override + public BlockPos getHeight(BlockPos pos) { + return parent.getHeight(pos); + } + + @Override + public int getHeight(int x, int z) { + return parent.getHeight(x, z); + } + + @Override + public int getChunksLowestHorizon(int x, int z) { + return parent.getChunksLowestHorizon(x, z); + } + + @Override + public int getLightFromNeighborsFor(EnumSkyBlock type, BlockPos pos) { + return parent.getLightFromNeighborsFor(type, pos); + } + + @Override + public int getLightFor(EnumSkyBlock type, BlockPos pos) { + return parent.getLightFor(type, pos); + } + + @Override + public void setLightFor(EnumSkyBlock type, BlockPos pos, int lightValue) { + parent.setLightFor(type, pos, lightValue); + } + + @Override + public void notifyLightSet(BlockPos pos) { + parent.notifyLightSet(pos); + } + + @Override + public int getCombinedLight(BlockPos pos, int lightValue) { + return parent.getCombinedLight(pos, lightValue); + } + + @Override + public float getLightBrightness(BlockPos pos) { + return parent.getLightBrightness(pos); + } + + @Override + public IBlockState getBlockState(BlockPos pos) { + return parent.getBlockState(pos); + } + + @Override + public boolean isDaytime() { + return parent.isDaytime(); + } + + @Nullable + @Override + public RayTraceResult rayTraceBlocks(Vec3d start, Vec3d end) { + return parent.rayTraceBlocks(start, end); + } + + @Nullable + @Override + public RayTraceResult rayTraceBlocks(Vec3d start, Vec3d end, boolean stopOnLiquid) { + return parent.rayTraceBlocks(start, end, stopOnLiquid); + } + + @Nullable + @Override + public RayTraceResult rayTraceBlocks(Vec3d vec31, Vec3d vec32, boolean stopOnLiquid, boolean ignoreBlockWithoutBoundingBox, boolean returnLastUncollidableBlock) { + return parent.rayTraceBlocks(vec31, vec32, stopOnLiquid, ignoreBlockWithoutBoundingBox, returnLastUncollidableBlock); + } + + @Override + public void playSound(@Nullable EntityPlayer player, BlockPos pos, SoundEvent soundIn, SoundCategory category, float volume, float pitch) { + parent.playSound(player, pos, soundIn, category, volume, pitch); + } + + @Override + public void playRecord(BlockPos blockPositionIn, @Nullable SoundEvent soundEventIn) { + parent.playRecord(blockPositionIn, soundEventIn); + } + + @Override + public void spawnParticle(EnumParticleTypes particleType, double xCoord, double yCoord, double zCoord, double xSpeed, double ySpeed, double zSpeed, int... parameters) { + parent.spawnParticle(particleType, xCoord, yCoord, zCoord, xSpeed, ySpeed, zSpeed, parameters); + } + + @Override + public void spawnAlwaysVisibleParticle(int p_190523_1_, double p_190523_2_, double p_190523_4_, double p_190523_6_, double p_190523_8_, double p_190523_10_, double p_190523_12_, int... p_190523_14_) { + parent.spawnAlwaysVisibleParticle(p_190523_1_, p_190523_2_, p_190523_4_, p_190523_6_, p_190523_8_, p_190523_10_, p_190523_12_, p_190523_14_); + } + + @Override + public void spawnParticle(EnumParticleTypes particleType, boolean ignoreRange, double xCoord, double yCoord, double zCoord, double xSpeed, double ySpeed, double zSpeed, int... parameters) { + parent.spawnParticle(particleType, ignoreRange, xCoord, yCoord, zCoord, xSpeed, ySpeed, zSpeed, parameters); + } + + @Override + public boolean addWeatherEffect(Entity entityIn) { + return parent.addWeatherEffect(entityIn); + } + + @Override + public void removeEntityDangerously(Entity entityIn) { + parent.removeEntityDangerously(entityIn); + } + + @Override + public void addEventListener(IWorldEventListener listener) { + parent.addEventListener(listener); + } + + @Override + public List getCollisionBoxes(@Nullable Entity entityIn, AxisAlignedBB aabb) { + return parent.getCollisionBoxes(entityIn, aabb); + } + + @Override + public boolean isInsideBorder(WorldBorder worldBorderIn, Entity entityIn) { + return parent.isInsideBorder(worldBorderIn, entityIn); + } + + @Override + public void removeEventListener(IWorldEventListener listener) { + parent.removeEventListener(listener); + } + + @Override + public boolean collidesWithAnyBlock(AxisAlignedBB bbox) { + return parent.collidesWithAnyBlock(bbox); + } + + @Override + public int calculateSkylightSubtracted(float partialTicks) { + return parent.calculateSkylightSubtracted(partialTicks); + } + + @Override + public float getSunBrightnessFactor(float partialTicks) { + return parent.getSunBrightnessFactor(partialTicks); + } + + @Override + public float getSunBrightness(float partialTicks) { + return parent.getSunBrightness(partialTicks); + } + + @Override + public float getSunBrightnessBody(float partialTicks) { + return parent.getSunBrightnessBody(partialTicks); + } + + @Override + public Vec3d getSkyColor(Entity entityIn, float partialTicks) { + return parent.getSkyColor(entityIn, partialTicks); + } + + @Override + public Vec3d getSkyColorBody(Entity entityIn, float partialTicks) { + return parent.getSkyColorBody(entityIn, partialTicks); + } + + @Override + public float getCelestialAngle(float partialTicks) { + return parent.getCelestialAngle(partialTicks); + } + + @Override + public int getMoonPhase() { + return parent.getMoonPhase(); + } + + @Override + public float getCurrentMoonPhaseFactor() { + return parent.getCurrentMoonPhaseFactor(); + } + + @Override + public float getCurrentMoonPhaseFactorBody() { + return parent.getCurrentMoonPhaseFactorBody(); + } + + @Override + public float getCelestialAngleRadians(float partialTicks) { + return parent.getCelestialAngleRadians(partialTicks); + } + + @Override + public Vec3d getCloudColour(float partialTicks) { + return parent.getCloudColour(partialTicks); + } + + @Override + public Vec3d getCloudColorBody(float partialTicks) { + return parent.getCloudColorBody(partialTicks); + } + + @Override + public Vec3d getFogColor(float partialTicks) { + return parent.getFogColor(partialTicks); + } + + @Override + public BlockPos getPrecipitationHeight(BlockPos pos) { + return parent.getPrecipitationHeight(pos); + } + + @Override + public BlockPos getTopSolidOrLiquidBlock(BlockPos pos) { + return parent.getTopSolidOrLiquidBlock(pos); + } + + @Override + public float getStarBrightness(float partialTicks) { + return parent.getStarBrightness(partialTicks); + } + + @Override + public float getStarBrightnessBody(float partialTicks) { + return parent.getStarBrightnessBody(partialTicks); + } + + @Override + public boolean isUpdateScheduled(BlockPos pos, Block blk) { + return parent.isUpdateScheduled(pos, blk); + } + + @Override + public void scheduleUpdate(BlockPos pos, Block blockIn, int delay) { + parent.scheduleUpdate(pos, blockIn, delay); + } + + @Override + public void updateBlockTick(BlockPos pos, Block blockIn, int delay, int priority) { + parent.updateBlockTick(pos, blockIn, delay, priority); + } + + @Override + public void scheduleBlockUpdate(BlockPos pos, Block blockIn, int delay, int priority) { + parent.scheduleBlockUpdate(pos, blockIn, delay, priority); + } + + @Override + public void updateEntities() { + parent.updateEntities(); + } + + @Override + public boolean addTileEntity(TileEntity tile) { + return parent.addTileEntity(tile); + } + + @Override + public void addTileEntities(Collection tileEntityCollection) { + parent.addTileEntities(tileEntityCollection); + } + + @Override + public void updateEntity(Entity ent) { + parent.updateEntity(ent); + } + + @Override + public void updateEntityWithOptionalForce(Entity entityIn, boolean forceUpdate) { + parent.updateEntityWithOptionalForce(entityIn, forceUpdate); + } + + @Override + public boolean checkNoEntityCollision(AxisAlignedBB bb) { + return parent.checkNoEntityCollision(bb); + } + + @Override + public boolean checkNoEntityCollision(AxisAlignedBB bb, @Nullable Entity entityIn) { + return parent.checkNoEntityCollision(bb, entityIn); + } + + @Override + public boolean checkBlockCollision(AxisAlignedBB bb) { + return parent.checkBlockCollision(bb); + } + + @Override + public boolean containsAnyLiquid(AxisAlignedBB bb) { + return parent.containsAnyLiquid(bb); + } + + @Override + public boolean isFlammableWithin(AxisAlignedBB bb) { + return parent.isFlammableWithin(bb); + } + + @Override + public boolean handleMaterialAcceleration(AxisAlignedBB bb, Material materialIn, Entity entityIn) { + return parent.handleMaterialAcceleration(bb, materialIn, entityIn); + } + + @Override + public boolean isMaterialInBB(AxisAlignedBB bb, Material materialIn) { + return parent.isMaterialInBB(bb, materialIn); + } + + @Override + public Explosion createExplosion(@Nullable Entity entityIn, double x, double y, double z, float strength, boolean isSmoking) { + return parent.createExplosion(entityIn, x, y, z, strength, isSmoking); + } + + @Override + public Explosion newExplosion(@Nullable Entity entityIn, double x, double y, double z, float strength, boolean isFlaming, boolean isSmoking) { + return parent.newExplosion(entityIn, x, y, z, strength, isFlaming, isSmoking); + } + + @Override + public float getBlockDensity(Vec3d vec, AxisAlignedBB bb) { + return parent.getBlockDensity(vec, bb); + } + + @Override + public boolean extinguishFire(@Nullable EntityPlayer player, BlockPos pos, EnumFacing side) { + return parent.extinguishFire(player, pos, side); + } + + @Override + public String getDebugLoadedEntities() { + return parent.getDebugLoadedEntities(); + } + + @Override + public String getProviderName() { + return parent.getProviderName(); + } + + @Nullable + @Override + public TileEntity getTileEntity(BlockPos pos) { + return parent.getTileEntity(pos); + } + + @Override + public void setTileEntity(BlockPos pos, @Nullable TileEntity tileEntityIn) { + parent.setTileEntity(pos, tileEntityIn); + } + + @Override + public void removeTileEntity(BlockPos pos) { + parent.removeTileEntity(pos); + } + + @Override + public void markTileEntityForRemoval(TileEntity tileEntityIn) { + parent.markTileEntityForRemoval(tileEntityIn); + } + + @Override + public boolean isBlockFullCube(BlockPos pos) { + return parent.isBlockFullCube(pos); + } + + @Override + public boolean isBlockNormalCube(BlockPos pos, boolean _default) { + return parent.isBlockNormalCube(pos, _default); + } + + @Override + public void calculateInitialSkylight() { + parent.calculateInitialSkylight(); + } + + @Override + public void setAllowedSpawnTypes(boolean hostile, boolean peaceful) { + parent.setAllowedSpawnTypes(hostile, peaceful); + } + + @Override + public void calculateInitialWeatherBody() { + parent.calculateInitialWeatherBody(); + } + + @Override + public void updateWeatherBody() { + parent.updateWeatherBody(); + } + + @Override + public void immediateBlockTick(BlockPos pos, IBlockState state, Random random) { + parent.immediateBlockTick(pos, state, random); + } + + @Override + public boolean canBlockFreezeWater(BlockPos pos) { + return parent.canBlockFreezeWater(pos); + } + + @Override + public boolean canBlockFreezeNoWater(BlockPos pos) { + return parent.canBlockFreezeNoWater(pos); + } + + @Override + public boolean canBlockFreeze(BlockPos pos, boolean noWaterAdj) { + return parent.canBlockFreeze(pos, noWaterAdj); + } + + @Override + public boolean canBlockFreezeBody(BlockPos pos, boolean noWaterAdj) { + return parent.canBlockFreezeBody(pos, noWaterAdj); + } + + @Override + public boolean canSnowAt(BlockPos pos, boolean checkLight) { + return parent.canSnowAt(pos, checkLight); + } + + @Override + public boolean canSnowAtBody(BlockPos pos, boolean checkLight) { + return parent.canSnowAtBody(pos, checkLight); + } + + @Override + public boolean checkLight(BlockPos pos) { + return parent.checkLight(pos); + } + + @Override + public boolean checkLightFor(EnumSkyBlock lightType, BlockPos pos) { + return parent.checkLightFor(lightType, pos); + } + + @Override + public boolean tickUpdates(boolean runAllPending) { + return parent.tickUpdates(runAllPending); + } + + @Nullable + @Override + public List getPendingBlockUpdates(Chunk chunkIn, boolean p_72920_2_) { + return parent.getPendingBlockUpdates(chunkIn, p_72920_2_); + } + + @Nullable + @Override + public List getPendingBlockUpdates(StructureBoundingBox structureBB, boolean p_175712_2_) { + return parent.getPendingBlockUpdates(structureBB, p_175712_2_); + } + + @Override + public List getEntitiesWithinAABBExcludingEntity(@Nullable Entity entityIn, AxisAlignedBB bb) { + return parent.getEntitiesWithinAABBExcludingEntity(entityIn, bb); + } + + @Override + public List getEntitiesInAABBexcluding(@Nullable Entity entityIn, AxisAlignedBB boundingBox, @Nullable Predicate predicate) { + return super.getEntitiesInAABBexcluding(entityIn, boundingBox, predicate); + } + + @Override + public List getEntities(Class entityType, Predicate filter) { + return super.getEntities(entityType, filter); + } + + @Override + public List getPlayers(Class playerType, Predicate filter) { + return super.getPlayers(playerType, filter); + } + + @Override + public List getEntitiesWithinAABB(Class clazz, AxisAlignedBB aabb, @Nullable Predicate filter) { + return super.getEntitiesWithinAABB(clazz, aabb, filter); + } + + @Override + public List getEntitiesWithinAABB(Class classEntity, AxisAlignedBB bb) { + return parent.getEntitiesWithinAABB(classEntity, bb); + } + + @Nullable + @Override + public T findNearestEntityWithinAABB(Class entityType, AxisAlignedBB aabb, T closestTo) { + return parent.findNearestEntityWithinAABB(entityType, aabb, closestTo); + } + + @Override + public List getLoadedEntityList() { + return parent.getLoadedEntityList(); + } + + @Override + public void markChunkDirty(BlockPos pos, TileEntity unusedTileEntity) { + parent.markChunkDirty(pos, unusedTileEntity); + } + + @Override + public int countEntities(Class entityType) { + return parent.countEntities(entityType); + } + + @Override + public void loadEntities(Collection entityCollection) { + parent.loadEntities(entityCollection); + } + + @Override + public void unloadEntities(Collection entityCollection) { + parent.unloadEntities(entityCollection); + } + + @Override + public boolean mayPlace(Block p_190527_1_, BlockPos p_190527_2_, boolean p_190527_3_, EnumFacing p_190527_4_, @Nullable Entity p_190527_5_) { + return parent.mayPlace(p_190527_1_, p_190527_2_, p_190527_3_, p_190527_4_, p_190527_5_); + } + + @Override + public int getSeaLevel() { + return parent.getSeaLevel(); + } + + @Override + public void setSeaLevel(int seaLevelIn) { + parent.setSeaLevel(seaLevelIn); + } + + @Override + public int getStrongPower(BlockPos pos, EnumFacing direction) { + return parent.getStrongPower(pos, direction); + } + + @Override + public WorldType getWorldType() { + return parent.getWorldType(); + } + + @Override + public int getStrongPower(BlockPos pos) { + return parent.getStrongPower(pos); + } + + @Override + public boolean isSidePowered(BlockPos pos, EnumFacing side) { + return parent.isSidePowered(pos, side); + } + + @Override + public int getRedstonePower(BlockPos pos, EnumFacing facing) { + return parent.getRedstonePower(pos, facing); + } + + @Override + public boolean isBlockPowered(BlockPos pos) { + return parent.isBlockPowered(pos); + } + + @Override + public int isBlockIndirectlyGettingPowered(BlockPos pos) { + return parent.isBlockIndirectlyGettingPowered(pos); + } + + @Nullable + @Override + public EntityPlayer getClosestPlayerToEntity(Entity entityIn, double distance) { + return parent.getClosestPlayerToEntity(entityIn, distance); + } + + @Nullable + @Override + public EntityPlayer getNearestPlayerNotCreative(Entity entityIn, double distance) { + return parent.getNearestPlayerNotCreative(entityIn, distance); + } + + @Nullable + @Override + public EntityPlayer getClosestPlayer(double posX, double posY, double posZ, double distance, boolean spectator) { + return parent.getClosestPlayer(posX, posY, posZ, distance, spectator); + } + + @Nullable + @Override + public EntityPlayer getClosestPlayer(double x, double y, double z, double p_190525_7_, Predicate p_190525_9_) { + return parent.getClosestPlayer(x, y, z, p_190525_7_, p_190525_9_); + } + + @Override + public boolean isAnyPlayerWithinRangeAt(double x, double y, double z, double range) { + return parent.isAnyPlayerWithinRangeAt(x, y, z, range); + } + + @Nullable + @Override + public EntityPlayer getNearestAttackablePlayer(Entity entityIn, double maxXZDistance, double maxYDistance) { + return parent.getNearestAttackablePlayer(entityIn, maxXZDistance, maxYDistance); + } + + @Nullable + @Override + public EntityPlayer getNearestAttackablePlayer(BlockPos pos, double maxXZDistance, double maxYDistance) { + return parent.getNearestAttackablePlayer(pos, maxXZDistance, maxYDistance); + } + + @Nullable + @Override + public EntityPlayer getNearestAttackablePlayer(double posX, double posY, double posZ, double maxXZDistance, double maxYDistance, @Nullable Function playerToDouble, @Nullable Predicate p_184150_12_) { + return parent.getNearestAttackablePlayer(posX, posY, posZ, maxXZDistance, maxYDistance, playerToDouble, p_184150_12_); + } + + @Nullable + @Override + public EntityPlayer getPlayerEntityByName(String name) { + return parent.getPlayerEntityByName(name); + } + + @Nullable + @Override + public EntityPlayer getPlayerEntityByUUID(UUID uuid) { + return parent.getPlayerEntityByUUID(uuid); + } + + @Override + public void checkSessionLock() throws MinecraftException { + parent.checkSessionLock(); + } + + @Override + public long getSeed() { + return parent.getSeed(); + } + + @Override + public long getTotalWorldTime() { + return parent.getTotalWorldTime(); + } + + @Override + public void setTotalWorldTime(long worldTime) { + parent.setTotalWorldTime(worldTime); + } + + @Override + public long getWorldTime() { + return parent.getWorldTime(); + } + + @Override + public void setWorldTime(long time) { + parent.setWorldTime(time); + } + + @Override + public BlockPos getSpawnPoint() { + return parent.getSpawnPoint(); + } + + @Override + public void setSpawnPoint(BlockPos pos) { + parent.setSpawnPoint(pos); + } + + @Override + public void joinEntityInSurroundings(Entity entityIn) { + parent.joinEntityInSurroundings(entityIn); + } + + @Override + public boolean isBlockModifiable(EntityPlayer player, BlockPos pos) { + return parent.isBlockModifiable(player, pos); + } + + @Override + public boolean canMineBlockBody(EntityPlayer player, BlockPos pos) { + return parent.canMineBlockBody(player, pos); + } + + @Override + public void setEntityState(Entity entityIn, byte state) { + parent.setEntityState(entityIn, state); + } + + @Override + public void addBlockEvent(BlockPos pos, Block blockIn, int eventID, int eventParam) { + parent.addBlockEvent(pos, blockIn, eventID, eventParam); + } + + @Override + public ISaveHandler getSaveHandler() { + return parent.getSaveHandler(); + } + + @Override + public WorldInfo getWorldInfo() { + return parent.getWorldInfo(); + } + + @Override + public GameRules getGameRules() { + return parent.getGameRules(); + } + + @Override + public void updateAllPlayersSleepingFlag() { + parent.updateAllPlayersSleepingFlag(); + } + + @Override + public float getThunderStrength(float delta) { + return parent.getThunderStrength(delta); + } + + @Override + public void setThunderStrength(float strength) { + parent.setThunderStrength(strength); + } + + @Override + public float getRainStrength(float delta) { + return parent.getRainStrength(delta); + } + + @Override + public void setRainStrength(float strength) { + parent.setRainStrength(strength); + } + + @Override + public boolean isThundering() { + return parent.isThundering(); + } + + @Override + public boolean isRaining() { + return parent.isRaining(); + } + + @Override + public boolean isRainingAt(BlockPos strikePosition) { + return parent.isRainingAt(strikePosition); + } + + @Override + public boolean isBlockinHighHumidity(BlockPos pos) { + return parent.isBlockinHighHumidity(pos); + } + + @Nullable + @Override + public MapStorage getMapStorage() { + return parent.getMapStorage(); + } + + @Override + public void setData(String dataID, WorldSavedData worldSavedDataIn) { + parent.setData(dataID, worldSavedDataIn); + } + + @Nullable + @Override + public WorldSavedData loadData(Class clazz, String dataID) { + return parent.loadData(clazz, dataID); + } + + @Override + public int getUniqueDataId(String key) { + return parent.getUniqueDataId(key); + } + + @Override + public void playBroadcastSound(int id, BlockPos pos, int data) { + parent.playBroadcastSound(id, pos, data); + } + + @Override + public void playEvent(int type, BlockPos pos, int data) { + parent.playEvent(type, pos, data); + } + + @Override + public void playEvent(@Nullable EntityPlayer player, int type, BlockPos pos, int data) { + parent.playEvent(player, type, pos, data); + } + + @Override + public int getHeight() { + return parent.getHeight(); + } + + @Override + public int getActualHeight() { + return parent.getActualHeight(); + } + + @Override + public Random setRandomSeed(int p_72843_1_, int p_72843_2_, int p_72843_3_) { + return parent.setRandomSeed(p_72843_1_, p_72843_2_, p_72843_3_); + } + + @Override + public double getHorizon() { + return parent.getHorizon(); + } + + @Override + public void sendBlockBreakProgress(int breakerId, BlockPos pos, int progress) { + parent.sendBlockBreakProgress(breakerId, pos, progress); + } + + @Override + public Calendar getCurrentDate() { + return parent.getCurrentDate(); + } + + @Override + public Scoreboard getScoreboard() { + return parent.getScoreboard(); + } + + @Override + public void updateComparatorOutputLevel(BlockPos pos, Block blockIn) { + parent.updateComparatorOutputLevel(pos, blockIn); + } + + @Override + public DifficultyInstance getDifficultyForLocation(BlockPos pos) { + return parent.getDifficultyForLocation(pos); + } + + @Override + public EnumDifficulty getDifficulty() { + return parent.getDifficulty(); + } + + @Override + public int getSkylightSubtracted() { + return parent.getSkylightSubtracted(); + } + + @Override + public void setSkylightSubtracted(int newSkylightSubtracted) { + parent.setSkylightSubtracted(newSkylightSubtracted); + } + + @Override + public int getLastLightningBolt() { + return parent.getLastLightningBolt(); + } + + @Override + public void setLastLightningBolt(int lastLightningBoltIn) { + parent.setLastLightningBolt(lastLightningBoltIn); + } + + @Override + public VillageCollection getVillageCollection() { + return parent.getVillageCollection(); + } + + @Override + public WorldBorder getWorldBorder() { + return parent.getWorldBorder(); + } + + @Override + public boolean isSpawnChunk(int x, int z) { + return parent.isSpawnChunk(x, z); + } + + @Override + public boolean isSideSolid(BlockPos pos, EnumFacing side) { + return parent.isSideSolid(pos, side); + } + + @Override + public boolean isSideSolid(BlockPos pos, EnumFacing side, boolean _default) { + return parent.isSideSolid(pos, side, _default); + } + + @Override + public ImmutableSetMultimap getPersistentChunks() { + return parent.getPersistentChunks(); + } + + @Override + public Iterator getPersistentChunkIterable(Iterator chunkIterator) { + return parent.getPersistentChunkIterable(chunkIterator); + } + + @Override + public int getBlockLightOpacity(BlockPos pos) { + return parent.getBlockLightOpacity(pos); + } + + @Override + public int countEntities(EnumCreatureType type, boolean forSpawnCount) { + return parent.countEntities(type, forSpawnCount); + } + + + @Override + public boolean hasCapability(Capability capability, @Nullable EnumFacing facing) { + return parent.hasCapability(capability, facing); + } + + @Nullable + @Override + public T getCapability(Capability capability, @Nullable EnumFacing facing) { + return parent.getCapability(capability, facing); + } + + @Override + public MapStorage getPerWorldStorage() { + return parent.getPerWorldStorage(); + } + + @Override + public LootTableManager getLootTableManager() { + return parent.getLootTableManager(); + } + + @Nullable + @Override + public BlockPos findNearestStructure(String p_190528_1_, BlockPos p_190528_2_, boolean p_190528_3_) { + return parent.findNearestStructure(p_190528_1_, p_190528_2_, p_190528_3_); + } +} \ No newline at end of file diff --git a/src/main/java/io/github/elytra/movingworld/common/experiments/RegionPool.java b/src/main/java/io/github/elytra/movingworld/common/experiments/RegionPool.java index 7a1b6b67..6a2a8a73 100644 --- a/src/main/java/io/github/elytra/movingworld/common/experiments/RegionPool.java +++ b/src/main/java/io/github/elytra/movingworld/common/experiments/RegionPool.java @@ -10,6 +10,7 @@ */ public class RegionPool { + // Pools sorted by dimension id. public static final HashMap POOLS = new HashMap<>(); public final HashMap regions = new HashMap<>(); diff --git a/src/main/java/io/github/elytra/movingworld/common/experiments/entity/EntityMobileRegion.java b/src/main/java/io/github/elytra/movingworld/common/experiments/entity/EntityMobileRegion.java new file mode 100644 index 00000000..f91ffc44 --- /dev/null +++ b/src/main/java/io/github/elytra/movingworld/common/experiments/entity/EntityMobileRegion.java @@ -0,0 +1,30 @@ +package io.github.elytra.movingworld.common.experiments.entity; + +import net.minecraft.entity.Entity; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.world.World; + +/** + * Experimental MobileRegion entity. + */ +public class EntityMobileRegion extends Entity { + + public EntityMobileRegion(World worldIn) { + super(worldIn); + } + + @Override + protected void entityInit() { + + } + + @Override + protected void readEntityFromNBT(NBTTagCompound compound) { + + } + + @Override + protected void writeEntityToNBT(NBTTagCompound compound) { + + } +} diff --git a/src/main/java/io/github/elytra/movingworld/common/network/MovingWorldNetworking.java b/src/main/java/io/github/elytra/movingworld/common/network/MovingWorldNetworking.java index 90e9c97e..43fbc0e4 100644 --- a/src/main/java/io/github/elytra/movingworld/common/network/MovingWorldNetworking.java +++ b/src/main/java/io/github/elytra/movingworld/common/network/MovingWorldNetworking.java @@ -1,188 +1,30 @@ package io.github.elytra.movingworld.common.network; -import com.unascribed.lambdanetwork.DataType; -import com.unascribed.lambdanetwork.LambdaNetwork; -import com.unascribed.lambdanetwork.LambdaNetworkBuilder; - -import net.minecraft.entity.Entity; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.EnumHand; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import net.minecraftforge.common.DimensionManager; -import net.minecraftforge.fml.relauncher.Side; - -import java.io.IOException; - +import io.github.elytra.concrete.NetworkContext; import io.github.elytra.movingworld.MovingWorldMod; -import io.github.elytra.movingworld.common.chunk.ChunkIO; -import io.github.elytra.movingworld.common.chunk.mobilechunk.MobileChunkClient; -import io.github.elytra.movingworld.common.entity.EntityMovingWorld; -import io.github.elytra.movingworld.common.tile.TileMovingMarkingBlock; -import io.netty.buffer.ByteBuf; -import io.netty.buffer.Unpooled; +import io.github.elytra.movingworld.common.network.message.*; public class MovingWorldNetworking { - public static LambdaNetwork NETWORK; + public static NetworkContext NETWORK; public static void setupNetwork() { //Init net code with builder. MovingWorldMod.LOG.info("Setting up network..."); - MovingWorldNetworking.NETWORK = registerPackets(LambdaNetwork.builder().channel("MovingWorld")).build(); + MovingWorldNetworking.NETWORK = registerPackets(); MovingWorldMod.LOG.info("Setup network! " + MovingWorldNetworking.NETWORK.toString()); } - private static LambdaNetworkBuilder registerPackets(LambdaNetworkBuilder builder) { - builder = builder.packet("FarInteractMessage").boundTo(Side.SERVER) - .with(DataType.INT, "dimID") - .with(DataType.INT, "entityID") - .with(DataType.INT, "hand") - .handledBy((entityPlayer, token) -> { - World world = DimensionManager.getWorld(token.getInt("dimID")); - if (world != null) { - Entity unCast = world.getEntityByID(token.getInt("entityID")); - - if (unCast != null && unCast instanceof EntityMovingWorld) { - EntityMovingWorld movingWorld = (EntityMovingWorld) unCast; - EnumHand hand = EnumHand.values()[token.getInt("hand")]; - entityPlayer.interactOn(movingWorld, hand); - } - } - }); - - builder = builder.packet("ChunkBlockUpdateMessage").boundTo(Side.CLIENT) - .with(DataType.INT, "dimID") - .with(DataType.INT, "entityID") - .with(DataType.ARBITRARY, "chunk").handledOnMainThreadBy((entityPlayer, token) -> { - ByteBuf buf = Unpooled.wrappedBuffer(token.getData("chunk")); - World world = DimensionManager.getWorld(token.getInt("dimID")); - if (world != null) { - Entity unCast = world.getEntityByID(token.getInt("entityID")); - - if (unCast != null && unCast instanceof EntityMovingWorld) { - EntityMovingWorld movingWorld = (EntityMovingWorld) unCast; - try { - ChunkIO.readCompressed(buf, movingWorld.getMobileChunk()); - } catch (IOException e) { - MovingWorldMod.LOG.error(e); - } - } - } - }); - - builder = builder.packet("TileEntitiesMessage").boundTo(Side.CLIENT) - .with(DataType.INT, "dimID") - .with(DataType.INT, "entityID") - .with(DataType.NBT_COMPOUND, "tagCompound").handledOnMainThreadBy((entityPlayer, token) -> { - NBTTagCompound tagCompound = token.getNBT("tagCompound"); - World world = DimensionManager.getWorld(token.getInt("dimID")); - if (world != null) { - Entity unCast = world.getEntityByID(token.getInt("entityID")); - - if (unCast != null && unCast instanceof EntityMovingWorld) { - EntityMovingWorld movingWorld = (EntityMovingWorld) unCast; - - if (movingWorld != null && tagCompound != null && movingWorld.getMobileChunk() != null && - movingWorld.getMobileChunk() instanceof MobileChunkClient) { - NBTTagList list = tagCompound.getTagList("list", 10); - for (int i = 0; i < list.tagCount(); i++) { - NBTTagCompound nbt = list.getCompoundTagAt(i); - if (nbt == null) continue; - int x = nbt.getInteger("x"); - int y = nbt.getInteger("y"); - int z = nbt.getInteger("z"); - BlockPos pos = new BlockPos(x, y, z); - try { - TileEntity te = movingWorld.getMobileChunk().getTileEntity(pos); - if (te != null) - te.readFromNBT(nbt); - } catch (Exception e) { - e.printStackTrace(); - } - } - ((MobileChunkClient) movingWorld.getMobileChunk()).getRenderer().markDirty(); - } - } - } - }); + private static NetworkContext registerPackets() { + NetworkContext context = NetworkContext.forChannel("MovingWorld"); - builder = builder.packet("RequestMovingWorldDataMessage").boundTo(Side.SERVER) - .with(DataType.INT, "dimID") - .with(DataType.INT, "entityID") - .handledOnMainThreadBy((entityPlayer, token) -> { - World world = DimensionManager.getWorld(token.getInt("dimID")); - if (world != null) { - Entity unCast = world.getEntityByID(token.getInt("entityID")); + context.register(FarInteractMessage.class); + context.register(MovingWorldBlockChangeMessage.class); + context.register(MovingWorldTileChangeMessage.class); + context.register(MovingWorldDataRequestMessage.class); + context.register(MovingWorldClientActionMessage.class); - if (unCast != null && unCast instanceof EntityMovingWorld) { - EntityMovingWorld movingWorld = (EntityMovingWorld) unCast; - - NBTTagCompound tagCompound = new NBTTagCompound(); - NBTTagList list = new NBTTagList(); - for (TileEntity te : movingWorld.getMobileChunk().chunkTileEntityMap.values()) { - NBTTagCompound nbt = new NBTTagCompound(); - if (te instanceof TileMovingMarkingBlock) { - ((TileMovingMarkingBlock) te).writeNBTForSending(nbt); - } else { - te.writeToNBT(nbt); - } - list.appendTag(nbt); - } - tagCompound.setTag("list", list); - - NETWORK.send().packet("TileEntitiesMessage") - .with("dimID", token.getInt("dimID")) - .with("entityID", token.getInt("entityID")) - .with("tagCompound", tagCompound) - .to(entityPlayer); - } - } - }); - - builder = builder.packet("MovingWorldClientActionMessage").boundTo(Side.SERVER) - .with(DataType.INT, "dimID") - .with(DataType.INT, "entityID") - .with(DataType.BYTE, "action").handledOnMainThreadBy((entityPlayer, token) -> { - MovingWorldClientAction action = MovingWorldClientAction.fromByte((byte) token.getInt("action")); - World world = DimensionManager.getWorld(token.getInt("dimID")); - if (world != null) { - Entity unCast = world.getEntityByID(token.getInt("entityID")); - - if (unCast != null && unCast instanceof EntityMovingWorld) { - EntityMovingWorld movingWorld = (EntityMovingWorld) unCast; - - if (movingWorld != null && movingWorld.getControllingPassenger().getEntityId() == entityPlayer.getEntityId()) { - switch (action) { - case DISASSEMBLE: - movingWorld.alignToGrid(true); - movingWorld.updatePassengerPosition(entityPlayer, movingWorld.riderDestination, 1); - movingWorld.removePassengers(); - movingWorld.disassemble(false); - break; - case DISASSEMBLEWITHOVERWRITE: - movingWorld.alignToGrid(true); - movingWorld.updatePassengerPosition(entityPlayer, movingWorld.riderDestination, 1); - movingWorld.removePassengers(); - movingWorld.disassemble(true); - break; - case ALIGN: - movingWorld.alignToGrid(true); - break; - default: - break; - } - } - } - } - - }); - - return builder; + return context; } - } diff --git a/src/main/java/io/github/elytra/movingworld/common/network/marshallers/EntityMarshaller.java b/src/main/java/io/github/elytra/movingworld/common/network/marshallers/EntityMarshaller.java new file mode 100644 index 00000000..f25762c5 --- /dev/null +++ b/src/main/java/io/github/elytra/movingworld/common/network/marshallers/EntityMarshaller.java @@ -0,0 +1,34 @@ +package io.github.elytra.movingworld.common.network.marshallers; + +import io.github.elytra.concrete.Marshaller; +import io.netty.buffer.ByteBuf; +import net.minecraft.entity.Entity; +import net.minecraft.world.World; +import net.minecraftforge.common.DimensionManager; + +public class EntityMarshaller implements Marshaller { + + public static final String MARSHALLER_NAME = "io.github.elytra.movingworld.common.network.marshallers.EntityMarshaller"; + public static final EntityMarshaller INSTANCE = new EntityMarshaller(); + + @Override + public Entity unmarshal(ByteBuf in) { + if (in.readBoolean()) { + World world = DimensionManager.getWorld(in.readInt()); + return world.getEntityByID(in.readInt()); + } else { + return null; + } + } + + @Override + public void marshal(ByteBuf out, Entity entity) { + if (entity != null) { + out.writeBoolean(true); + out.writeInt(entity.world.provider.getDimension()); + out.writeInt(entity.getEntityId()); + } else { + out.writeBoolean(false); + } + } +} diff --git a/src/main/java/io/github/elytra/movingworld/common/network/message/FarInteractMessage.java b/src/main/java/io/github/elytra/movingworld/common/network/message/FarInteractMessage.java new file mode 100644 index 00000000..d0eeaded --- /dev/null +++ b/src/main/java/io/github/elytra/movingworld/common/network/message/FarInteractMessage.java @@ -0,0 +1,37 @@ +package io.github.elytra.movingworld.common.network.message; + +import io.github.elytra.concrete.Message; +import io.github.elytra.concrete.NetworkContext; +import io.github.elytra.concrete.annotation.field.MarshalledAs; +import io.github.elytra.concrete.annotation.type.ReceivedOn; +import io.github.elytra.movingworld.common.entity.EntityMovingWorld; +import io.github.elytra.movingworld.common.network.MovingWorldNetworking; +import io.github.elytra.movingworld.common.network.marshallers.EntityMarshaller; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.EnumHand; +import net.minecraftforge.fml.relauncher.Side; + +@ReceivedOn(Side.SERVER) +public class FarInteractMessage extends Message { + + @MarshalledAs(EntityMarshaller.MARSHALLER_NAME) + public EntityMovingWorld movingWorld; + public EnumHand hand; + + public FarInteractMessage(NetworkContext ctx) { + super(ctx); + } + + public FarInteractMessage(EntityMovingWorld movingWorld, EnumHand hand) { + super(MovingWorldNetworking.NETWORK); + + this.movingWorld = movingWorld; + this.hand = hand; + } + + @Override + protected void handle(EntityPlayer entityPlayer) { + entityPlayer.interactOn(movingWorld, hand); + } +} diff --git a/src/main/java/io/github/elytra/movingworld/common/network/message/MovingWorldBlockChangeMessage.java b/src/main/java/io/github/elytra/movingworld/common/network/message/MovingWorldBlockChangeMessage.java new file mode 100644 index 00000000..4a933500 --- /dev/null +++ b/src/main/java/io/github/elytra/movingworld/common/network/message/MovingWorldBlockChangeMessage.java @@ -0,0 +1,51 @@ +package io.github.elytra.movingworld.common.network.message; + +import io.github.elytra.concrete.Message; +import io.github.elytra.concrete.NetworkContext; +import io.github.elytra.concrete.annotation.field.MarshalledAs; +import io.github.elytra.concrete.annotation.type.ReceivedOn; +import io.github.elytra.movingworld.MovingWorldMod; +import io.github.elytra.movingworld.common.chunk.ChunkIO; +import io.github.elytra.movingworld.common.entity.EntityMovingWorld; +import io.github.elytra.movingworld.common.network.MovingWorldNetworking; +import io.github.elytra.movingworld.common.network.marshallers.EntityMarshaller; +import io.netty.buffer.ByteBuf; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraftforge.fml.relauncher.Side; + +import java.io.IOException; + +/** + * Sends MobileChunk block data to clients. + */ +@ReceivedOn(Side.CLIENT) +public class MovingWorldBlockChangeMessage extends Message { + + @MarshalledAs(EntityMarshaller.MARSHALLER_NAME) + public EntityMovingWorld movingWorld; + public ByteBuf compressedChunkData; + + public MovingWorldBlockChangeMessage(NetworkContext ctx) { + super(ctx); + } + + public MovingWorldBlockChangeMessage(EntityMovingWorld movingWorld, ByteBuf compressedChunkData) { + super(MovingWorldNetworking.NETWORK); + this.movingWorld = movingWorld; + this.compressedChunkData = compressedChunkData; + } + + @Override + protected void handle(EntityPlayer sender) { + if (movingWorld == null || movingWorld.getMobileChunk() == null || compressedChunkData == null) + return; + + try { + compressedChunkData.resetReaderIndex(); + compressedChunkData.resetWriterIndex(); + ChunkIO.readCompressed(compressedChunkData, movingWorld.getMobileChunk()); + } catch (IOException e) { + MovingWorldMod.LOG.error(e); + } + } +} diff --git a/src/main/java/io/github/elytra/movingworld/common/network/message/MovingWorldClientActionMessage.java b/src/main/java/io/github/elytra/movingworld/common/network/message/MovingWorldClientActionMessage.java new file mode 100644 index 00000000..f99e5148 --- /dev/null +++ b/src/main/java/io/github/elytra/movingworld/common/network/message/MovingWorldClientActionMessage.java @@ -0,0 +1,61 @@ +package io.github.elytra.movingworld.common.network.message; + +import io.github.elytra.concrete.Message; +import io.github.elytra.concrete.NetworkContext; +import io.github.elytra.concrete.annotation.field.MarshalledAs; +import io.github.elytra.concrete.annotation.type.ReceivedOn; +import io.github.elytra.movingworld.common.entity.EntityMovingWorld; +import io.github.elytra.movingworld.common.network.MovingWorldClientAction; +import io.github.elytra.movingworld.common.network.MovingWorldNetworking; +import io.github.elytra.movingworld.common.network.marshallers.EntityMarshaller; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraftforge.fml.relauncher.Side; + +/** + * Created by darkevilmac on 1/29/2017. + */ +@ReceivedOn(Side.SERVER) +public class MovingWorldClientActionMessage extends Message { + + @MarshalledAs(EntityMarshaller.MARSHALLER_NAME) + public EntityMovingWorld movingWorld; + public MovingWorldClientAction action; + + public MovingWorldClientActionMessage(NetworkContext ctx) { + super(ctx); + } + + public MovingWorldClientActionMessage(EntityMovingWorld movingWorld, MovingWorldClientAction action) { + super(MovingWorldNetworking.NETWORK); + this.movingWorld = movingWorld; + this.action = action; + } + + + @Override + protected void handle(EntityPlayer sender) { + if (movingWorld == null || sender != movingWorld.getControllingPassenger()) + return; + + switch (action) { + case DISASSEMBLE: + movingWorld.alignToGrid(true); + movingWorld.updatePassengerPosition(sender, movingWorld.riderDestination, 1); + movingWorld.removePassengers(); + movingWorld.disassemble(false); + break; + case DISASSEMBLEWITHOVERWRITE: + movingWorld.alignToGrid(true); + movingWorld.updatePassengerPosition(sender, movingWorld.riderDestination, 1); + movingWorld.removePassengers(); + movingWorld.disassemble(true); + break; + case ALIGN: + movingWorld.alignToGrid(true); + break; + default: + break; + } + } + +} diff --git a/src/main/java/io/github/elytra/movingworld/common/network/message/MovingWorldDataRequestMessage.java b/src/main/java/io/github/elytra/movingworld/common/network/message/MovingWorldDataRequestMessage.java new file mode 100644 index 00000000..dcd4f16b --- /dev/null +++ b/src/main/java/io/github/elytra/movingworld/common/network/message/MovingWorldDataRequestMessage.java @@ -0,0 +1,56 @@ +package io.github.elytra.movingworld.common.network.message; + +import io.github.elytra.concrete.Message; +import io.github.elytra.concrete.NetworkContext; +import io.github.elytra.concrete.annotation.field.MarshalledAs; +import io.github.elytra.concrete.annotation.type.ReceivedOn; +import io.github.elytra.movingworld.common.entity.EntityMovingWorld; +import io.github.elytra.movingworld.common.network.MovingWorldNetworking; +import io.github.elytra.movingworld.common.network.marshallers.EntityMarshaller; +import io.github.elytra.movingworld.common.tile.TileMovingMarkingBlock; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.fml.relauncher.Side; + +/** + * Created by darkevilmac on 1/29/2017. + */ +@ReceivedOn(Side.SERVER) +public class MovingWorldDataRequestMessage extends Message { + + @MarshalledAs(EntityMarshaller.MARSHALLER_NAME) + public EntityMovingWorld movingWorld; + + public MovingWorldDataRequestMessage(NetworkContext ctx) { + super(ctx); + } + + public MovingWorldDataRequestMessage(EntityMovingWorld movingWorld) { + super(MovingWorldNetworking.NETWORK); + this.movingWorld = movingWorld; + } + + @Override + protected void handle(EntityPlayer sender) { + if (movingWorld == null) + return; + + NBTTagCompound tagCompound = new NBTTagCompound(); + NBTTagList list = new NBTTagList(); + for (TileEntity te : movingWorld.getMobileChunk().chunkTileEntityMap.values()) { + NBTTagCompound nbt = new NBTTagCompound(); + if (te instanceof TileMovingMarkingBlock) { + ((TileMovingMarkingBlock) te).writeNBTForSending(nbt); + } else { + te.writeToNBT(nbt); + } + list.appendTag(nbt); + } + tagCompound.setTag("list", list); + + // https://goo.gl/6VyCqo + new MovingWorldTileChangeMessage(movingWorld, tagCompound).sendTo(sender); + } +} diff --git a/src/main/java/io/github/elytra/movingworld/common/network/message/MovingWorldTileChangeMessage.java b/src/main/java/io/github/elytra/movingworld/common/network/message/MovingWorldTileChangeMessage.java new file mode 100644 index 00000000..2c5014e1 --- /dev/null +++ b/src/main/java/io/github/elytra/movingworld/common/network/message/MovingWorldTileChangeMessage.java @@ -0,0 +1,61 @@ +package io.github.elytra.movingworld.common.network.message; + +import io.github.elytra.concrete.Message; +import io.github.elytra.concrete.NetworkContext; +import io.github.elytra.concrete.annotation.field.MarshalledAs; +import io.github.elytra.concrete.annotation.type.ReceivedOn; +import io.github.elytra.movingworld.common.chunk.mobilechunk.MobileChunkClient; +import io.github.elytra.movingworld.common.entity.EntityMovingWorld; +import io.github.elytra.movingworld.common.network.MovingWorldNetworking; +import io.github.elytra.movingworld.common.network.marshallers.EntityMarshaller; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.math.BlockPos; +import net.minecraftforge.fml.relauncher.Side; + +/** + * Sends tile entity data in a MobileChunk to clients. + */ +@ReceivedOn(Side.CLIENT) +public class MovingWorldTileChangeMessage extends Message { + + @MarshalledAs(EntityMarshaller.MARSHALLER_NAME) + public EntityMovingWorld movingWorld; + public NBTTagCompound tileData; + + public MovingWorldTileChangeMessage(NetworkContext ctx) { + super(ctx); + } + + public MovingWorldTileChangeMessage(EntityMovingWorld movingWorld, NBTTagCompound tileData) { + super(MovingWorldNetworking.NETWORK); + this.movingWorld = movingWorld; + this.tileData = tileData; + } + + @Override + protected void handle(EntityPlayer sender) { + if (movingWorld == null && tileData == null && movingWorld.getMobileChunk() == null) + return; + + NBTTagList list = tileData.getTagList("list", 10); + for (int i = 0; i < list.tagCount(); i++) { + NBTTagCompound nbt = list.getCompoundTagAt(i); + if (nbt == null) continue; + int x = nbt.getInteger("x"); + int y = nbt.getInteger("y"); + int z = nbt.getInteger("z"); + BlockPos pos = new BlockPos(x, y, z); + try { + TileEntity te = movingWorld.getMobileChunk().getTileEntity(pos); + if (te != null) + te.readFromNBT(nbt); + } catch (Exception e) { + e.printStackTrace(); + } + } + ((MobileChunkClient) movingWorld.getMobileChunk()).getRenderer().markDirty(); + } +} diff --git a/src/main/resources/MovingWorld_at.cfg b/src/main/resources/MovingWorld_at.cfg index 1eb4ac56..6364d861 100644 --- a/src/main/resources/MovingWorld_at.cfg +++ b/src/main/resources/MovingWorld_at.cfg @@ -3,4 +3,17 @@ public net.minecraft.tileentity.TileEntity field_145854_h # blockType public net.minecraft.tileentity.TileEntity field_190562_f # REGISTRY public net.minecraft.client.renderer.entity.RenderManager field_78725_b # renderPosX public net.minecraft.client.renderer.entity.RenderManager field_78726_c # renderPosY -public net.minecraft.client.renderer.entity.RenderManager field_78723_d # renderPosZ \ No newline at end of file +public net.minecraft.client.renderer.entity.RenderManager field_78723_d # renderPosZ + +# Expose all methods and fields in world classes, we do weird shit to worlds so we need it ALL exposed. +public net.minecraft.world.World * +public net.minecraft.client.multiplayer.WorldClient * +public net.minecraft.world.WorldServer * +public net.minecraft.world.WorldServerMulti * +public net.minecraft.world.demo.DemoWorldServer * + +public net.minecraft.world.World *() +public net.minecraft.client.multiplayer.WorldClient *() +public net.minecraft.world.WorldServer *() +public net.minecraft.world.WorldServerMulti *() +public net.minecraft.world.demo.DemoWorldServer *() \ No newline at end of file