From ed2242fc11aa9121f04b69a3090fc11dfdb5eb88 Mon Sep 17 00:00:00 2001 From: katzenpapst Date: Sun, 4 Jun 2017 00:18:47 +0200 Subject: [PATCH 1/6] shuttle saves dock position --- .../entity/spaceship/EntityShuttle.java | 163 ++++++++++++++---- .../de/katzenpapst/amunra/vec/Vector3int.java | 7 + .../katzenpapst/amunra/world/WorldHelper.java | 63 +++++++ 3 files changed, 198 insertions(+), 35 deletions(-) diff --git a/src/main/java/de/katzenpapst/amunra/entity/spaceship/EntityShuttle.java b/src/main/java/de/katzenpapst/amunra/entity/spaceship/EntityShuttle.java index 219d85a8..adc25080 100755 --- a/src/main/java/de/katzenpapst/amunra/entity/spaceship/EntityShuttle.java +++ b/src/main/java/de/katzenpapst/amunra/entity/spaceship/EntityShuttle.java @@ -14,15 +14,18 @@ import de.katzenpapst.amunra.tile.TileEntityShuttleDock; import de.katzenpapst.amunra.vec.Vector3int; import de.katzenpapst.amunra.world.ShuttleDockHandler; +import de.katzenpapst.amunra.world.WorldHelper; import io.netty.buffer.ByteBuf; +import micdoodle8.mods.galacticraft.api.prefab.entity.EntitySpaceshipBase; import micdoodle8.mods.galacticraft.api.prefab.entity.EntityTieredRocket; import micdoodle8.mods.galacticraft.api.tile.IFuelDock; import micdoodle8.mods.galacticraft.api.vector.Vector3; import micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider; +import micdoodle8.mods.galacticraft.api.world.IZeroGDimension; import micdoodle8.mods.galacticraft.core.GalacticraftCore; import micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats; +import micdoodle8.mods.galacticraft.core.tile.TileEntityMulti; import micdoodle8.mods.galacticraft.core.util.ConfigManagerCore; -import net.minecraft.block.Block; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; @@ -46,12 +49,7 @@ public class EntityShuttle extends EntityTieredRocket { // so, apparently, there is no real way to figure out when an entity has been dismounted protected Entity prevRiddenByEntity = null; - // NOW TRY THIS - // first two bits: num chetsts - // next two bits: num tanks - // 3 chests and 3 tanks won't be possible, maybe reserve it for the creative rocket - // I'll simply won't use prefueled - + protected Vector3int dockPosition = null; public EntityShuttle(World par1World) { super(par1World); @@ -347,6 +345,19 @@ protected void repositionDismountedPlayer(Entity player) { // return new Vector3(this.posX, this.posY, this.posZ); } + + protected boolean isSafeForPlayer(double x, double y, double z) + { + int y1 = (int)y; + + + return WorldHelper.isNonSolid(worldObj, (int)x, y1, (int)z) && WorldHelper.isNonSolid(worldObj, (int)x, y1+1, (int)z) && WorldHelper.isSolid(worldObj, (int)x, y1-1, (int)z, true); + + //return true; + //this.worldObj.isAirBlock(x, y, y); + } + + protected void tryFindAnotherDock() { Vector3int dock = ShuttleDockHandler.findAvailableDock(this.worldObj.provider.dimensionId); if(dock != null) { @@ -397,12 +408,6 @@ public void onUpdate() // handle player dismounting if(!worldObj.isRemote) { - /*if(playerRepositionTicks > 0) { - playerRepositionTicks--; - - repositionDismountedPlayer(repositioningEntity); - }*/ - if(prevRiddenByEntity != riddenByEntity) { if(riddenByEntity == null && prevRiddenByEntity != null) { // seems like someone just dismounted @@ -502,9 +507,9 @@ public void onUpdate() } if(this.launchPhase == EnumLaunchPhase.UNIGNITED.ordinal()) { - if(!doKnowOnWhatImStanding) { - checkStandingPosition(); - } + + checkStandingPosition(); + } } @@ -521,34 +526,108 @@ protected void checkStandingPosition() if(this.worldObj.isRemote) { return; } + + // recheck this from time to time anyway + if(doKnowOnWhatImStanding && this.ticksExisted % 40 != 0) { + return; + } + if(this.getLandingPad() != null) { doKnowOnWhatImStanding = true; } else { + if(dockPosition != null) { + TileEntity tile = worldObj.getTileEntity(dockPosition.x, dockPosition.y, dockPosition.z); + if(tile != null) { + if(tile instanceof IFuelDock) { + this.setPad((IFuelDock) tile); + this.landEntity(tile); + dockPosition = null; + return; + } else { + // something went wrong + dockPosition = null; + } + } + } + + boolean isInZeroG = false; + if(this.worldObj.provider instanceof IZeroGDimension) { + isInZeroG = true; + } + // let's look downward - for(int iy=0;iy<5;iy++) { + //this.posY is about 3 blocks above the baseline + int bX = (int)(this.posX-0.5D); + int bY = (int)(this.posY-0.5D-1); + int bZ = (int)(this.posZ-0.5D); + + Vector3int highest = WorldHelper.getHighestNonEmptyBlock(worldObj, bX-1, bX+1, bY-5, bY, bZ-1, bZ+1); + + if(highest != null) { + TileEntity tileBelow = worldObj.getTileEntity(highest.x, highest.y, highest.z); + IFuelDock dockTile = null; + if(tileBelow != null) { + if (tileBelow instanceof TileEntityMulti) { + tileBelow = ((TileEntityMulti)tileBelow).getMainBlockTile(); + } + if(tileBelow instanceof IFuelDock) { + dockTile = (IFuelDock)tileBelow; + } + } + if(dockTile != null) { + isOnBareGround = false; + doKnowOnWhatImStanding = true; + if(this.getLandingPad() != dockTile) { + //((IFuelDock) dockTile).dockEntity(this); + this.landEntity((TileEntity)dockTile); + //this.setPad(dockTile); + } + } else { + isOnBareGround = true; + doKnowOnWhatImStanding = true; + if(!isInZeroG) { + adjustGroundPosition(highest.y); + } + } + } else { + if(!isInZeroG) { + // make the rocket land + this.setLanding(); + } + } + } + } - int bX = (int)(this.posX-0.5D); - int bY = (int)(this.posY-0.5D-iy); - int bZ = (int)(this.posZ-0.5D); + @Override + public void landEntity(int x, int y, int z) + { + TileEntity tile = this.worldObj.getTileEntity(x, y, z); - Block b = worldObj.getBlock(bX, bY, bZ); - //int meta = worldObj.getBlockMetadata((int)(this.posX-0.5D), (int)(this.posY-0.5D-iy), (int)(this.posZ-0.5D)); + landEntity(tile); + } - if(b.isAir(worldObj, bX, bY, bZ)) { - continue; - } else { - // whatever it is, it determines where we are - TileEntity tileBelow = worldObj.getTileEntity(bX, bY, bZ); - if(tileBelow == null || !(tileBelow instanceof IFuelDock)) { - isOnBareGround = true; - doKnowOnWhatImStanding = true; - adjustGroundPosition(bY); - } else { - isOnBareGround = false; - doKnowOnWhatImStanding = true; + public void landEntity(TileEntity tile) + { + + if (tile instanceof IFuelDock) + { + IFuelDock dock = (IFuelDock) tile; + + if (this.isDockValid(dock)) + { + if (!this.worldObj.isRemote) + { + //Drop any existing rocket on the landing pad + if (dock.getDockedEntity() instanceof EntitySpaceshipBase && dock.getDockedEntity() != this) + { + ((EntitySpaceshipBase)dock.getDockedEntity()).dropShipAsItem(); + ((EntitySpaceshipBase)dock.getDockedEntity()).setDead(); } - break; + + this.setPad(dock); } + + this.onRocketLand(tile.xCoord, tile.yCoord, tile.zCoord); } } } @@ -671,6 +750,13 @@ public List getCargoContents() protected void writeEntityToNBT(NBTTagCompound nbt) { nbt.setInteger("NumTanks", numTanks); + + if(this.getLandingPad() != null) { + Vector3int pos = new Vector3int((TileEntity) this.getLandingPad()); + nbt.setTag("dockPosition", pos.toNBT()); + //pos.toNBT() + } + super.writeEntityToNBT(nbt); } @@ -681,6 +767,13 @@ protected void readEntityFromNBT(NBTTagCompound nbt) //this.shuttleMode = EnumShuttleMode.values()[nbt.getInteger("ShuttleMode")]; //this.setShuttleMode(shuttleMode); this.numTanks = nbt.getInteger("NumTanks"); + if(nbt.hasKey("dockPosition")) { + NBTTagCompound dockPosNbt = nbt.getCompoundTag("dockPosition"); + if(dockPosNbt != null) { + dockPosition = new Vector3int(dockPosNbt); + } + } + super.readEntityFromNBT(nbt); } diff --git a/src/main/java/de/katzenpapst/amunra/vec/Vector3int.java b/src/main/java/de/katzenpapst/amunra/vec/Vector3int.java index 91ffcfc0..71c69246 100755 --- a/src/main/java/de/katzenpapst/amunra/vec/Vector3int.java +++ b/src/main/java/de/katzenpapst/amunra/vec/Vector3int.java @@ -3,6 +3,7 @@ import micdoodle8.mods.galacticraft.api.vector.BlockVec3; import micdoodle8.mods.galacticraft.api.vector.Vector3; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; public class Vector3int { @@ -28,6 +29,12 @@ public Vector3int(NBTTagCompound nbt) { this.z = nbt.getInteger("z"); } + public Vector3int(TileEntity tile) { + this.x = tile.xCoord; + this.y = tile.yCoord; + this.z = tile.zCoord; + } + public NBTTagCompound toNBT() { NBTTagCompound nbt = new NBTTagCompound(); diff --git a/src/main/java/de/katzenpapst/amunra/world/WorldHelper.java b/src/main/java/de/katzenpapst/amunra/world/WorldHelper.java index be241f78..1a09b470 100755 --- a/src/main/java/de/katzenpapst/amunra/world/WorldHelper.java +++ b/src/main/java/de/katzenpapst/amunra/world/WorldHelper.java @@ -7,6 +7,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; +import de.katzenpapst.amunra.vec.Vector3int; import micdoodle8.mods.galacticraft.api.prefab.core.BlockMetaPair; public class WorldHelper { @@ -111,4 +112,66 @@ public static void setBlockIfFree(World worldObj, int x, int y, int z, Block blo worldObj.setBlock(x, y, z, block, meta, 3); } } + + /** + * Returns true if the given block can be walked through. Will probably return false for fluids, too + * + * @param worldObj + * @param x + * @param y + * @param z + * @param checkTop + * @return + */ + public static boolean isSolid(World worldObj, int x, int y, int z, boolean checkTop) { + Block b = worldObj.getBlock(x, y, z); + if(checkTop) { + return worldObj.doesBlockHaveSolidTopSurface(worldObj, x, y, z); + } + // getBlocksMovement returns true when the block does NOT block movement... + return !b.getBlocksMovement(worldObj, x, y, z) && b.getMaterial().isSolid(); + } + + /** + * Returns true if the given block can be walked through + * @param worldObj + * @param x + * @param y + * @param z + * @return + */ + public static boolean isSolid(World worldObj, int x, int y, int z) { + return isSolid(worldObj, x, y, z, false); + } + + /** + * Checks if given block is safe to place the player + * @param worldObj + * @param x + * @param y + * @param z + * @return + */ + public static boolean isNonSolid(World worldObj, int x, int y, int z) { + Block b = worldObj.getBlock(x, y, z); + + // so apparently block.getBlocksMovement does the opposite of what one might expect... + + return b.isAir(worldObj, x, y, z) || (b.getBlocksMovement(worldObj, x, y, z) && !b.getMaterial().isLiquid() && !b.getMaterial().isSolid()); + } + + public static Vector3int getHighestNonEmptyBlock(World world, int minX, int maxX, int minY, int maxY, int minZ, int maxZ) { + + for(int y = maxY; y >= minY; y--) { + for(int x=minX; x<=maxX; x++) { + for(int z=minZ; z<=maxZ; z++) { + if(!isNonSolid(world, x, y, z)) { + return new Vector3int(x, y, z); + } + } + } + } + + return null; + } } From eb5ca942b44a63b9af12b4056e9b5b88f20cbaa3 Mon Sep 17 00:00:00 2001 From: katzenpapst Date: Sat, 3 Jun 2017 16:42:35 +0200 Subject: [PATCH 2/6] improved shuttle dismounting --- .../entity/spaceship/EntityShuttle.java | 22 ++++++++++++++----- .../katzenpapst/amunra/world/WorldHelper.java | 2 +- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/main/java/de/katzenpapst/amunra/entity/spaceship/EntityShuttle.java b/src/main/java/de/katzenpapst/amunra/entity/spaceship/EntityShuttle.java index adc25080..7092803d 100755 --- a/src/main/java/de/katzenpapst/amunra/entity/spaceship/EntityShuttle.java +++ b/src/main/java/de/katzenpapst/amunra/entity/spaceship/EntityShuttle.java @@ -339,22 +339,32 @@ protected void repositionDismountedPlayer(Entity player) { //player.setPositionAndRotation(pos.x, pos.y, pos.z, 0, 0); //player.setPosition(pos.x, pos.y, pos.z); } else { - - ((EntityPlayer)player).setPositionAndUpdate(this.posX, this.posY-this.getYOffset(), this.posZ - 2.5D); + // try not doing this? + // check for safe positions + int xPos = (int)(this.posX - 0.5D); + int yPos = (int)(this.posY-this.getYOffset()); + int zPos = (int)(this.posZ - 0.5D); + + if(this.isSafeForPlayer(xPos, yPos, zPos - 2)) { + ((EntityPlayer)player).setPositionAndUpdate(this.posX, yPos, this.posZ - 2); + } else if(this.isSafeForPlayer(xPos, yPos, zPos + 2)) { + ((EntityPlayer)player).setPositionAndUpdate(this.posX, yPos, this.posZ + 2); + } else if(this.isSafeForPlayer(xPos - 2, yPos, zPos)) { + ((EntityPlayer)player).setPositionAndUpdate(this.posX - 2, yPos, this.posZ); + } else if(this.isSafeForPlayer(xPos + 2, yPos, zPos)) { + ((EntityPlayer)player).setPositionAndUpdate(this.posX + 2, yPos, this.posZ); + } } // return new Vector3(this.posX, this.posY, this.posZ); } + protected boolean isSafeForPlayer(double x, double y, double z) { int y1 = (int)y; - return WorldHelper.isNonSolid(worldObj, (int)x, y1, (int)z) && WorldHelper.isNonSolid(worldObj, (int)x, y1+1, (int)z) && WorldHelper.isSolid(worldObj, (int)x, y1-1, (int)z, true); - - //return true; - //this.worldObj.isAirBlock(x, y, y); } diff --git a/src/main/java/de/katzenpapst/amunra/world/WorldHelper.java b/src/main/java/de/katzenpapst/amunra/world/WorldHelper.java index 1a09b470..d825fe94 100755 --- a/src/main/java/de/katzenpapst/amunra/world/WorldHelper.java +++ b/src/main/java/de/katzenpapst/amunra/world/WorldHelper.java @@ -108,7 +108,7 @@ public static void setFireToBlock(World worldObj, int x, int y, int z, double fr public static void setBlockIfFree(World worldObj, int x, int y, int z, Block block, int meta) { Block old = worldObj.getBlock(x, y, z); if(old == Blocks.air) { - System.out.println("setting "+x+"/"+y+"/"+z+" on fire"); + //System.out.println("setting "+x+"/"+y+"/"+z+" on fire"); worldObj.setBlock(x, y, z, block, meta, 3); } } From cede0b476f28ff5fceb7b7871fa3303c9f46d636 Mon Sep 17 00:00:00 2001 From: katzenpapst Date: Mon, 12 Jun 2017 23:07:51 +0200 Subject: [PATCH 3/6] potentially fixed #43, made the mehen belt brighter --- .../katzenpapst/amunra/proxy/ServerProxy.java | 12 ++- .../AmunRaAsteroidsChunkProvider.java | 85 ++++++++++++++++--- .../world/mehen/MehenChunkProvider.java | 10 +++ 3 files changed, 89 insertions(+), 18 deletions(-) diff --git a/src/main/java/de/katzenpapst/amunra/proxy/ServerProxy.java b/src/main/java/de/katzenpapst/amunra/proxy/ServerProxy.java index 9e10a3d0..0c357d69 100755 --- a/src/main/java/de/katzenpapst/amunra/proxy/ServerProxy.java +++ b/src/main/java/de/katzenpapst/amunra/proxy/ServerProxy.java @@ -10,10 +10,14 @@ public class ServerProxy extends ARSidedProxy { @Override public void preInit(FMLPreInitializationEvent event) { - MinecraftServer s = MinecraftServer.getServer(); - if(s.isDedicatedServer() && !s.isServerInOnlineMode() && AmunRa.config.mothershipUserMatchUUID) { - GCLog.info("Server running in offline mode. Setting \"matchUsersByUUID\" to false"); - AmunRa.config.mothershipUserMatchUUID = false; + try { + MinecraftServer s = MinecraftServer.getServer(); + if(s.isDedicatedServer() && !s.isServerInOnlineMode() && AmunRa.config.mothershipUserMatchUUID) { + GCLog.info("Server running in offline mode. Setting \"matchUsersByUUID\" to false"); + AmunRa.config.mothershipUserMatchUUID = false; + } + } catch (NullPointerException e) { + GCLog.info("Could not detect whenever server is in online mode. If it's not, please manually set \"matchUsersByUUID\" to false"); } } diff --git a/src/main/java/de/katzenpapst/amunra/world/asteroidWorld/AmunRaAsteroidsChunkProvider.java b/src/main/java/de/katzenpapst/amunra/world/asteroidWorld/AmunRaAsteroidsChunkProvider.java index 982b51d7..5b6f193b 100755 --- a/src/main/java/de/katzenpapst/amunra/world/asteroidWorld/AmunRaAsteroidsChunkProvider.java +++ b/src/main/java/de/katzenpapst/amunra/world/asteroidWorld/AmunRaAsteroidsChunkProvider.java @@ -631,6 +631,31 @@ public boolean chunkExists(int par1, int par2) return true; } + /** + * + * @param world + * @param x start x + * @param y + * @param z + * @param maxLength how far to look max + * @param isAir if true, counts air blocks, if false, counts the NOT airblocks + * @return + */ + protected int getCountInNegXDirection(IChunkProvider world, int x, int y, int z, int maxLength, boolean isAir) + { + int count = 0; + + for(int i=0; i 0 /*|| ((xPos & 15) > 2 ? flagZDChunk : flagXZDChunk)*/) && (chunk.getBlock(x - 3, y, z - 1) instanceof BlockAir)) count++; - if ((z < 15/* || ((xPos & 15) > 2 ? flagZUChunk : flagXZUChunk)*/) && (chunk.getBlock(x - 3, y, z + 1) instanceof BlockAir)) count++; + if ((z > 0 ) && (chunk.getBlock(x - 3, y, z - 1) instanceof BlockAir)) count++; + if ((z < 15) && (chunk.getBlock(x - 3, y, z + 1) instanceof BlockAir)) count++; } - if (/*flagXChunk || */x > 3) + if (x > 3) { if ((chunk.getBlock(x - 4, y, z) instanceof BlockAir)) count+=2; if ((chunk.getBlock(x - 4, y + 1, z) instanceof BlockAir)) count++; if ((chunk.getBlock(x - 4, y + 1, z) instanceof BlockAir)) count++; - if ((z > 0/* || ((xPos & 15) > 3 ? flagZDChunk : flagXZDChunk)*/) && !(chunk.getBlock(x - 4, y, z - 1) instanceof BlockAir)) count++; - if ((z < 15/* || ((xPos & 15) > 3 ? flagZUChunk : flagXZUChunk)*/) && !(chunk.getBlock(x - 4, y, z + 1) instanceof BlockAir)) count++; + if ((z > 0) && !(chunk.getBlock(x - 4, y, z - 1) instanceof BlockAir)) count++; + if ((z < 15) && !(chunk.getBlock(x - 4, y, z + 1) instanceof BlockAir)) count++; } - if (count > 12) count = 12; - chunk.func_150807_a(x - 1, y & 15, z, GCBlocks.brightAir, 15 - count); + // this does something about light, again? + //if (count > 12) count = 12; + count = adjustBrightnessValue(count); + // making the 15 in 15-count lower means brighter? + //count = 0; + // func_150807_a -> 15 = darkest, 0 => brightest + chunk.func_150807_a(x - 1, y, z, GCBlocks.brightAir, 15 - count); ExtendedBlockStorage extendedblockstorage = chunk.getBlockStorageArray()[y >> 4]; if (extendedblockstorage != null) { - extendedblockstorage.setExtBlocklightValue(x - 1, y & 15, z, count); + // here it seems to be the opposite + extendedblockstorage.setExtBlocklightValue(x - 1, y & 15, z, count + 2); } } } @@ -880,6 +923,20 @@ public void generateSkylightMap(Chunk chunk, int cx, int cz) chunk.isModified = true; } + /** + * higher values = lighter dimension. Probably should not exceed 12 + * @param count + * @return + */ + protected int adjustBrightnessValue(int count) + { + count += 2; + + if (count > 12) count = 12; + + return count; + } + @Override public boolean saveChunks(boolean par1, IProgressUpdate par2IProgressUpdate) { diff --git a/src/main/java/de/katzenpapst/amunra/world/mehen/MehenChunkProvider.java b/src/main/java/de/katzenpapst/amunra/world/mehen/MehenChunkProvider.java index fade894d..8c0690ba 100755 --- a/src/main/java/de/katzenpapst/amunra/world/mehen/MehenChunkProvider.java +++ b/src/main/java/de/katzenpapst/amunra/world/mehen/MehenChunkProvider.java @@ -45,4 +45,14 @@ protected void initBlockTypes() { addBlockToHandler(coreHandler, ARBlocks.blockDarkmatter, 1, .05); } + @Override + protected int adjustBrightnessValue(int count) + { + count += 8; + + if (count > 12) count = 12; + + return count; + } + } From b8057d07a2ecac0a7c1865273aef1e98d3f59047 Mon Sep 17 00:00:00 2001 From: katzenpapst Date: Thu, 15 Jun 2017 17:55:10 +0200 Subject: [PATCH 4/6] began overhauling the permission system --- .../AbstractBlockMothershipRestricted.java | 2 +- .../MothershipEngineBoosterBase.java | 24 +++++++++--- .../MothershipEngineJetBase.java | 11 ++---- .../client/gui/GuiShuttleSelection.java | 14 ------- .../client/gui/tabs/TabMothershipUsage.java | 9 +++++ .../amunra/mothership/Mothership.java | 18 +++++++-- .../mothership/MothershipWorldProvider.java | 8 ++++ .../amunra/network/packet/PacketSimpleAR.java | 39 ++++++++++++++++++- .../tile/TileEntityMothershipSettings.java | 3 -- .../resources/assets/amunra/lang/en_US.lang | 3 +- 10 files changed, 95 insertions(+), 36 deletions(-) create mode 100755 src/main/java/de/katzenpapst/amunra/client/gui/tabs/TabMothershipUsage.java diff --git a/src/main/java/de/katzenpapst/amunra/block/machine/AbstractBlockMothershipRestricted.java b/src/main/java/de/katzenpapst/amunra/block/machine/AbstractBlockMothershipRestricted.java index 3fb63925..e31d1b0a 100755 --- a/src/main/java/de/katzenpapst/amunra/block/machine/AbstractBlockMothershipRestricted.java +++ b/src/main/java/de/katzenpapst/amunra/block/machine/AbstractBlockMothershipRestricted.java @@ -34,7 +34,7 @@ public boolean onMachineActivated(World world, int x, int y, int z, EntityPlayer { if(world.provider instanceof MothershipWorldProvider) { - if( ((MothershipWorldProvider)world.provider).isPlayerOwner(entityPlayer) ) { + if( ((MothershipWorldProvider)world.provider).isPlayerUsagePermitted(entityPlayer) ) { openGui(world, x, y, z, entityPlayer); return true; diff --git a/src/main/java/de/katzenpapst/amunra/block/machine/mothershipEngine/MothershipEngineBoosterBase.java b/src/main/java/de/katzenpapst/amunra/block/machine/mothershipEngine/MothershipEngineBoosterBase.java index 13110c3f..07abd6bd 100755 --- a/src/main/java/de/katzenpapst/amunra/block/machine/mothershipEngine/MothershipEngineBoosterBase.java +++ b/src/main/java/de/katzenpapst/amunra/block/machine/mothershipEngine/MothershipEngineBoosterBase.java @@ -4,7 +4,7 @@ import cpw.mods.fml.relauncher.SideOnly; import de.katzenpapst.amunra.AmunRa; import de.katzenpapst.amunra.GuiIds; -import de.katzenpapst.amunra.block.SubBlockMachine; +import de.katzenpapst.amunra.block.machine.AbstractBlockMothershipRestricted; import de.katzenpapst.amunra.vec.Vector3int; import micdoodle8.mods.galacticraft.core.util.GCCoreUtil; import de.katzenpapst.amunra.tile.TileEntityMothershipEngineAbstract; @@ -17,7 +17,7 @@ import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; -public class MothershipEngineBoosterBase extends SubBlockMachine { +public class MothershipEngineBoosterBase extends AbstractBlockMothershipRestricted { protected String activeTextureName; protected IIcon activeBlockIcon; @@ -42,16 +42,28 @@ public boolean onMachineActivated(World world, int x, int y, int z, EntityPlayer TileEntityMothershipEngineBooster tile = (TileEntityMothershipEngineBooster)leTile; if(tile.hasMaster()) { + return super.onMachineActivated(world, x, y, z, entityPlayer, side, hitX, hitY, hitZ); + } + return false; + } + + + + @Override + protected void openGui(World world, int x, int y, int z, EntityPlayer entityPlayer) { + // try this + if(world.isRemote) { + return; + } + TileEntity leTile = world.getTileEntity(x, y, z); + if(leTile != null) { + TileEntityMothershipEngineBooster tile = (TileEntityMothershipEngineBooster)leTile; Vector3int pos = tile.getMasterPosition(); entityPlayer.openGui(AmunRa.instance, GuiIds.GUI_MS_ROCKET_ENGINE, world, pos.x, pos.y, pos.z); - return true; } - return false; } - - @Override public boolean hasTileEntity(int metadata) { return true; diff --git a/src/main/java/de/katzenpapst/amunra/block/machine/mothershipEngine/MothershipEngineJetBase.java b/src/main/java/de/katzenpapst/amunra/block/machine/mothershipEngine/MothershipEngineJetBase.java index 9a2491c4..4b6fcc10 100755 --- a/src/main/java/de/katzenpapst/amunra/block/machine/mothershipEngine/MothershipEngineJetBase.java +++ b/src/main/java/de/katzenpapst/amunra/block/machine/mothershipEngine/MothershipEngineJetBase.java @@ -6,7 +6,7 @@ import cpw.mods.fml.relauncher.SideOnly; import de.katzenpapst.amunra.AmunRa; import de.katzenpapst.amunra.GuiIds; -import de.katzenpapst.amunra.block.SubBlockMachine; +import de.katzenpapst.amunra.block.machine.AbstractBlockMothershipRestricted; import de.katzenpapst.amunra.item.ItemDamagePair; import de.katzenpapst.amunra.tile.TileEntityMothershipEngineAbstract; import micdoodle8.mods.galacticraft.core.util.GCCoreUtil; @@ -18,7 +18,7 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; -public abstract class MothershipEngineJetBase extends SubBlockMachine { +public abstract class MothershipEngineJetBase extends AbstractBlockMothershipRestricted { protected String iconTexture; @@ -109,13 +109,10 @@ public boolean renderAsNormalBlock() return false; } + @Override - public boolean onMachineActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ) - { - // do the isRemote thing here, too? + protected void openGui(World world, int x, int y, int z, EntityPlayer entityPlayer) { entityPlayer.openGui(AmunRa.instance, GuiIds.GUI_MS_ROCKET_ENGINE, world, x, y, z); - return true; - // return false; } @Override diff --git a/src/main/java/de/katzenpapst/amunra/client/gui/GuiShuttleSelection.java b/src/main/java/de/katzenpapst/amunra/client/gui/GuiShuttleSelection.java index 5485d35f..fdf1225f 100755 --- a/src/main/java/de/katzenpapst/amunra/client/gui/GuiShuttleSelection.java +++ b/src/main/java/de/katzenpapst/amunra/client/gui/GuiShuttleSelection.java @@ -357,18 +357,6 @@ protected boolean teleportToSelectedBody() } else { - if(this.selectedBody instanceof Mothership) { - // check if user is allowed - Mothership curMS = (Mothership)this.selectedBody; - // even if the player is not permitted, he will be still allowed to return - int playerDim = mc.thePlayer.worldObj.provider.dimensionId; - if(curMS.getDimensionID() != playerDim && !((Mothership)this.selectedBody).isPlayerPermitted(this.mc.thePlayer)) { - this.showMessageBox( - GCCoreUtil.translate("gui.message.mothership.permissionError"), - GCCoreUtil.translateWithFormat("gui.message.mothership.notAllowed", curMS.getOwner().getName())); - return false; - } - } dimensionID = this.selectedBody.getDimensionID(); } /* @@ -381,8 +369,6 @@ protected boolean teleportToSelectedBody() } */ AmunRa.packetPipeline.sendToServer(new PacketSimpleAR(PacketSimpleAR.EnumSimplePacket.S_TELEPORT_SHUTTLE, new Object[] { dimensionID })); - //TODO Some type of clientside "in Space" holding screen here while waiting for the server to do the teleport - //(Otherwise the client will be returned to the destination he was in until now, which looks weird) mc.displayGuiScreen(null); return true; } diff --git a/src/main/java/de/katzenpapst/amunra/client/gui/tabs/TabMothershipUsage.java b/src/main/java/de/katzenpapst/amunra/client/gui/tabs/TabMothershipUsage.java new file mode 100755 index 00000000..a470d719 --- /dev/null +++ b/src/main/java/de/katzenpapst/amunra/client/gui/tabs/TabMothershipUsage.java @@ -0,0 +1,9 @@ +package de.katzenpapst.amunra.client.gui.tabs; + +public class TabMothershipUsage { + + public TabMothershipUsage() { + // TODO Auto-generated constructor stub + } + +} diff --git a/src/main/java/de/katzenpapst/amunra/mothership/Mothership.java b/src/main/java/de/katzenpapst/amunra/mothership/Mothership.java index 7d88bf69..4326d116 100755 --- a/src/main/java/de/katzenpapst/amunra/mothership/Mothership.java +++ b/src/main/java/de/katzenpapst/amunra/mothership/Mothership.java @@ -557,25 +557,37 @@ public boolean isPlayerOwner(PlayerID player) { return owner.equals(player); } + public boolean isPlayerUsagePermitted(EntityPlayer player) { + + if(player.capabilities.isCreativeMode) { + return true; + } + + return this.isPlayerLandingPermitted(player);//for now + } + /** * Returns whenever the given player is permitted to land on this mothership * * @param player * @return */ - public boolean isPlayerPermitted(EntityPlayer player) { + public boolean isPlayerLandingPermitted(EntityPlayer player) { + + if(player.capabilities.isCreativeMode) { + return true; + } PlayerID playerId = new PlayerID(player); switch(this.permMode) { case ALL: return true; - case NONE: - return this.isPlayerOwner(playerId); case BLACKLIST: return this.isPlayerOwner(playerId) || !this.playerSet.contains(playerId); case WHITELIST: return this.isPlayerOwner(playerId) || this.playerSet.contains(playerId); + case NONE: default: return this.isPlayerOwner(playerId); } diff --git a/src/main/java/de/katzenpapst/amunra/mothership/MothershipWorldProvider.java b/src/main/java/de/katzenpapst/amunra/mothership/MothershipWorldProvider.java index 0ac5476a..e4b9df4e 100755 --- a/src/main/java/de/katzenpapst/amunra/mothership/MothershipWorldProvider.java +++ b/src/main/java/de/katzenpapst/amunra/mothership/MothershipWorldProvider.java @@ -907,6 +907,14 @@ public boolean isPlayerOwner(EntityPlayer player) return mothershipObj.isPlayerOwner(player); } + public boolean isPlayerLandingPermitted(EntityPlayer player) { + return mothershipObj.isPlayerLandingPermitted(player); + } + + public boolean isPlayerUsagePermitted(EntityPlayer player) { + return mothershipObj.isPlayerUsagePermitted(player); + } + @Override public float getGravity() { return 0.075F; diff --git a/src/main/java/de/katzenpapst/amunra/network/packet/PacketSimpleAR.java b/src/main/java/de/katzenpapst/amunra/network/packet/PacketSimpleAR.java index 4c2eae9e..443a35fd 100755 --- a/src/main/java/de/katzenpapst/amunra/network/packet/PacketSimpleAR.java +++ b/src/main/java/de/katzenpapst/amunra/network/packet/PacketSimpleAR.java @@ -218,7 +218,21 @@ public static enum EnumSimplePacket * - mothership_id * - nbt_data */ - C_MOTHERSHIP_SETTINGS_CHANGED(Side.CLIENT, Integer.class, NBTTagCompound.class); + C_MOTHERSHIP_SETTINGS_CHANGED(Side.CLIENT, Integer.class, NBTTagCompound.class), + + /** + * Tells the client that a previous S_TELEPORT_SHUTTLE has failed because of a permission error + * params: + * - owner_name + */ + C_TELEPORT_SHUTTLE_PERMISSION_ERROR(Side.CLIENT, String.class), + + /** + * Tells the client that a previous S_TELEPORT_SHUTTLE has failed for any other random reason + * params: + * - error_msg + */ + C_TELEPORT_SHUTTLE_FAIL(Side.CLIENT, String.class); @@ -464,6 +478,15 @@ public void handleClientSide(EntityPlayer player) ((GuiMothershipSettings)FMLClientHandler.instance().getClient().currentScreen).mothershipResponsePacketRecieved(); } break; + case C_TELEPORT_SHUTTLE_PERMISSION_ERROR: + if(FMLClientHandler.instance().getClient().currentScreen instanceof GuiShuttleSelection) { + String owner = (String) this.data.get(0); + ((GuiShuttleSelection)FMLClientHandler.instance().getClient().currentScreen).showMessageBox( + GCCoreUtil.translate("gui.message.mothership.permissionError"), + GCCoreUtil.translateWithFormat("gui.message.mothership.notAllowed", owner) + ); + } + break; default: break; } // end of case @@ -505,14 +528,28 @@ public void handleServerSide(EntityPlayer player) final Integer dim = ((Integer) this.data.get(0)); GCLog.info("Will teleport to (" + dim.toString() + ")"); + if (playerBase.worldObj instanceof WorldServer) { + mShip = TickHandlerServer.mothershipData.getByDimensionId(dim); + // check if the target is a mothership + if(mShip != null) { + // if the player is currently not on the target MS, check permissions + if(playerBase.dimension != dim && !mShip.isPlayerLandingPermitted(playerBase)) { + AmunRa.packetPipeline.sendTo(new PacketSimpleAR(PacketSimpleAR.EnumSimplePacket.C_TELEPORT_SHUTTLE_PERMISSION_ERROR, + mShip.getOwner().getName() + ), playerBase); + return; + } + } + world = (WorldServer) playerBase.worldObj; // replace this now ShuttleTeleportHelper.transferEntityToDimension(playerBase, dim, world); stats.teleportCooldown = 10; GalacticraftCore.packetPipeline.sendTo(new PacketSimple(PacketSimple.EnumSimplePacket.C_CLOSE_GUI, new Object[] { }), playerBase); + } } catch (final Exception e) diff --git a/src/main/java/de/katzenpapst/amunra/tile/TileEntityMothershipSettings.java b/src/main/java/de/katzenpapst/amunra/tile/TileEntityMothershipSettings.java index c9a61940..9eb5fe90 100755 --- a/src/main/java/de/katzenpapst/amunra/tile/TileEntityMothershipSettings.java +++ b/src/main/java/de/katzenpapst/amunra/tile/TileEntityMothershipSettings.java @@ -84,9 +84,6 @@ public boolean isUseableByPlayer(EntityPlayer par1EntityPlayer) { return false; } - if(!((MothershipWorldProvider)worldObj.provider).isPlayerOwner(par1EntityPlayer)) { - return false; - } return this.worldObj.getTileEntity(this.xCoord, this.yCoord, this.zCoord) == this && par1EntityPlayer.getDistanceSq(this.xCoord + 0.5D, this.yCoord + 0.5D, this.zCoord + 0.5D) <= 64.0D; diff --git a/src/main/resources/assets/amunra/lang/en_US.lang b/src/main/resources/assets/amunra/lang/en_US.lang index 06fe59ff..4081d12e 100755 --- a/src/main/resources/assets/amunra/lang/en_US.lang +++ b/src/main/resources/assets/amunra/lang/en_US.lang @@ -261,6 +261,7 @@ gui.message.mothership.notAllowed=You are not allowed to land on this mothership gui.message.mothership.permissionError=Permission error gui.message.mothership.chat.wrongUser=You are not allowed to use this mothership. gui.message.mothership.chat.notOnShip=This must be placed on a mothership. +gui.message.shuttle.transferFailed=Shuttle Transfer failed gui.message.dock.status.obstructed=There are blocks in the way.$Shuttles cannot dock here. gui.message.dock.status.occupied=A shuttle is docked here. gui.message.dock.status.free=This dock is vacant. @@ -277,7 +278,7 @@ info.message.celestialbodysearch.none=No celestial bodies matching '%s' found info.message.celestialbodysearch.some=Found %s celestial bodies matching '%s': - +gui.message.misc.generalErrorCaption=Error gui.message.misc.planet=Planet gui.message.misc.star=Star gui.message.misc.moon=Moon From ec68829a63b2979ef0a67c4d2766ad4bb0a7bf01 Mon Sep 17 00:00:00 2001 From: katzenpapst Date: Wed, 21 Jun 2017 23:35:58 +0200 Subject: [PATCH 5/6] permission system fixed. closes #41 --- .../amunra/client/gui/GuiContainerTabbed.java | 2 +- .../client/gui/GuiMothershipSettings.java | 10 +- .../amunra/client/gui/elements/TabButton.java | 54 +++++----- ...ission.java => AbstractPermissionTab.java} | 92 ++++++------------ .../amunra/client/gui/tabs/AbstractTab.java | 5 + .../client/gui/tabs/TabMothershipLanding.java | 83 ++++++++++++++++ .../client/gui/tabs/TabMothershipUsage.java | 79 ++++++++++++++- .../amunra/mothership/Mothership.java | 92 ++++++++++++++---- .../amunra/network/packet/PacketSimpleAR.java | 31 ++++-- .../resources/assets/amunra/lang/de_DE.lang | 4 + .../resources/assets/amunra/lang/en_US.lang | 4 + .../resources/assets/amunra/lang/pl_PL.lang | 22 +++-- .../resources/assets/amunra/lang/ru_RU.lang | 4 + .../amunra/textures/blocks/controller.png | Bin 4077 -> 4074 bytes .../textures/gui/landing-permission.png | Bin 0 -> 626 bytes .../amunra/textures/gui/usage-permission.png | Bin 0 -> 845 bytes 16 files changed, 348 insertions(+), 134 deletions(-) rename src/main/java/de/katzenpapst/amunra/client/gui/tabs/{TabMothershipPermission.java => AbstractPermissionTab.java} (67%) create mode 100755 src/main/java/de/katzenpapst/amunra/client/gui/tabs/TabMothershipLanding.java create mode 100755 src/main/resources/assets/amunra/textures/gui/landing-permission.png create mode 100755 src/main/resources/assets/amunra/textures/gui/usage-permission.png diff --git a/src/main/java/de/katzenpapst/amunra/client/gui/GuiContainerTabbed.java b/src/main/java/de/katzenpapst/amunra/client/gui/GuiContainerTabbed.java index 4615c98b..bc6ab8f2 100755 --- a/src/main/java/de/katzenpapst/amunra/client/gui/GuiContainerTabbed.java +++ b/src/main/java/de/katzenpapst/amunra/client/gui/GuiContainerTabbed.java @@ -47,7 +47,7 @@ public int addTab(AbstractTab tab) final int guiY = (this.height - this.ySize) / 2; // add button - TabButton test = new TabButton(TAB_BTN_OFFSET+newIndex, guiX-27, guiY+6 + newIndex*28, tab.getTooltip(), tab.getIcon()); + TabButton test = new TabButton(TAB_BTN_OFFSET+newIndex, guiX-27, guiY+6 + newIndex*28, tab.getTooltip(), tab.getTooltipDescription(), tab.getIcon()); this.buttonList.add(test); this.tabButtons.add(test); diff --git a/src/main/java/de/katzenpapst/amunra/client/gui/GuiMothershipSettings.java b/src/main/java/de/katzenpapst/amunra/client/gui/GuiMothershipSettings.java index 33a9052d..81a9c22d 100755 --- a/src/main/java/de/katzenpapst/amunra/client/gui/GuiMothershipSettings.java +++ b/src/main/java/de/katzenpapst/amunra/client/gui/GuiMothershipSettings.java @@ -7,7 +7,8 @@ import de.katzenpapst.amunra.AmunRa; import de.katzenpapst.amunra.client.gui.tabs.AbstractTab; import de.katzenpapst.amunra.client.gui.tabs.TabMothershipCustom; -import de.katzenpapst.amunra.client.gui.tabs.TabMothershipPermission; +import de.katzenpapst.amunra.client.gui.tabs.TabMothershipLanding; +import de.katzenpapst.amunra.client.gui.tabs.TabMothershipUsage; import de.katzenpapst.amunra.inventory.ContainerMothershipSettings; import de.katzenpapst.amunra.mothership.Mothership; import de.katzenpapst.amunra.network.packet.PacketSimpleAR; @@ -30,8 +31,6 @@ public interface IMothershipSettingsTab { private final TileEntityMothershipSettings tile; private Mothership ship; - private int customizeTabIndex; - protected List mothershipTextures; public GuiMothershipSettings(InventoryPlayer par1InventoryPlayer, TileEntityMothershipSettings tile) { @@ -83,8 +82,9 @@ public void initGui() { super.initGui(); - customizeTabIndex = this.addTab(new TabMothershipCustom(tile, this, mc, width, height, xSize, ySize)); - this.addTab(new TabMothershipPermission(tile, this, mc, width, height, xSize, ySize)); + this.addTab(new TabMothershipCustom(tile, this, mc, width, height, xSize, ySize)); + this.addTab(new TabMothershipLanding(tile, this, mc, width, height, xSize, ySize)); + this.addTab(new TabMothershipUsage(tile, this, mc, width, height, xSize, ySize)); } diff --git a/src/main/java/de/katzenpapst/amunra/client/gui/elements/TabButton.java b/src/main/java/de/katzenpapst/amunra/client/gui/elements/TabButton.java index c697c9c9..9f9bf588 100755 --- a/src/main/java/de/katzenpapst/amunra/client/gui/elements/TabButton.java +++ b/src/main/java/de/katzenpapst/amunra/client/gui/elements/TabButton.java @@ -1,11 +1,14 @@ package de.katzenpapst.amunra.client.gui.elements; +import java.util.List; + import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL12; import cpw.mods.fml.client.FMLClientHandler; import de.katzenpapst.amunra.AmunRa; import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.client.renderer.RenderHelper; @@ -20,6 +23,8 @@ public class TabButton extends GuiButton { protected final ResourceLocation texture; + protected String extraInfo = null; + public TabButton(int id, int xPos, int yPos, String displayString, ResourceLocation texture) { super(id, xPos, yPos, displayString); @@ -28,6 +33,12 @@ public TabButton(int id, int xPos, int yPos, String displayString, ResourceLocat this.texture = texture; } + public TabButton(int id, int xPos, int yPos, String displayString, String infoString, ResourceLocation texture) { + this(id, xPos, yPos, displayString, texture); + + extraInfo = infoString; + } + /** * Draws this button to the screen. */ @@ -106,44 +117,26 @@ public void drawTooltip(int mouseX, int mouseY) GL11.glDisable(GL11.GL_DEPTH_TEST); boolean withinRegion = mouseX >= this.xPosition && mouseY >= this.yPosition && mouseX < this.xPosition + this.width && mouseY < this.yPosition + this.height; - + List extraStrings = null; if (this.displayString != null && !this.displayString.isEmpty() && withinRegion) { + FontRenderer fontRenderer = FMLClientHandler.instance().getClient().fontRenderer; int stringWidth = FMLClientHandler.instance().getClient().fontRenderer.getStringWidth(displayString); - /*Iterator iterator = this.tooltipStrings.iterator(); - while (iterator.hasNext()) - { - String s = iterator.next(); - int l = FMLClientHandler.instance().getClient().fontRenderer.getStringWidth(s); - if (l > k) - { - k = l; - } - }*/ int tooltipX = mouseX + 12; int tooltipY = mouseY - 12; int stringHeight = 8; -/* - if (this.tooltipStrings.size() > 1) - { - k1 += (this.tooltipStrings.size() - 1) * 10; - } - if (i1 + k > this.parentWidth) - { - i1 -= 28 + k; + if(this.extraInfo != null) { + stringWidth = Math.max(stringWidth, 150); + extraStrings = fontRenderer.listFormattedStringToWidth(extraInfo, stringWidth); + stringHeight += extraStrings.size() * 10; } - if (this.parentGui.getTooltipOffset(par2, par3) > 0) - { - j1 -= k1 + 9; - } -*/ this.zLevel = 300.0F; //GuiElementInfoRegion.itemRenderer.zLevel = 300.0F; int colorSomething = -267386864; @@ -159,7 +152,18 @@ public void drawTooltip(int mouseX, int mouseY) this.drawGradientRect(tooltipX - 3, tooltipY - 3, tooltipX + stringWidth + 3, tooltipY - 3 + 1, otherColorSomething, otherColorSomething); this.drawGradientRect(tooltipX - 3, tooltipY + stringHeight + 2, tooltipX + stringWidth + 3, tooltipY + stringHeight + 3, j2, j2); - FMLClientHandler.instance().getClient().fontRenderer.drawStringWithShadow(displayString, tooltipX, tooltipY, -1); + fontRenderer.drawStringWithShadow(displayString, tooltipX, tooltipY, -1); + + //EnumColor.RED + + + if(extraStrings != null) { + for(int i=0;i playerIdList = new HashSet(); + //protected Set playerIdList = new HashSet(); + protected List playerIdList = new ArrayList(); - private Map permissionModeMap = new HashMap(); + protected Map permissionModeMap = new HashMap(); - private String error = ""; - private float errorTime = 0; + protected String error = ""; + protected float errorTime = 0; - public TabMothershipPermission(TileEntityMothershipSettings tile, GuiMothershipSettings parent, Minecraft mc, int width, int height, int xSize, int ySize) { + public AbstractPermissionTab(TileEntityMothershipSettings tile, GuiMothershipSettings parent, Minecraft mc, int width, int height, int xSize, int ySize) { super(parent, mc, width, height, xSize, ySize); this.tile = tile; @@ -57,12 +52,17 @@ public TabMothershipPermission(TileEntityMothershipSettings tile, GuiMothershipS permissionModeMap.put(Mothership.PermissionMode.BLACKLIST, GCCoreUtil.translate("tile.mothershipSettings.permission.blacklist")); } + protected abstract void addUsername(Mothership mothership, String userName); + + protected abstract void removeUsernameFromList(int position); + @Override public boolean actionPerformed(GuiButton btn) { if(btn == addBtn) { // - AmunRa.packetPipeline.sendToServer(new PacketSimpleAR(EnumSimplePacket.S_ADD_MOTHERSHIP_PLAYER, this.tile.getMothership().getID(), textBoxUsername.text)); + // AmunRa.packetPipeline.sendToServer(new PacketSimpleAR(EnumSimplePacket.S_ADD_MOTHERSHIP_PLAYER, this.tile.getMothership().getID(), textBoxUsername.text)); + addUsername(this.tile.getMothership(), textBoxUsername.text); textBoxUsername.text = ""; addBtn.enabled = false; return true; @@ -70,9 +70,8 @@ public boolean actionPerformed(GuiButton btn) if(btn == rmBtn) { int selection = selectBox.getSelectedStringIndex(); if(selection != -1) { - playerIdList.remove(selection); + removeUsernameFromList(selection); selectBox.clearSelection(); - tile.getMothership().setPlayerSet(playerIdList); applyData(); } return true; @@ -80,23 +79,14 @@ public boolean actionPerformed(GuiButton btn) return false; } - public void resetData() { - Mothership.PermissionMode pm = this.tile.getMothership().getPermissionMode(); - modeDropdown.selectedOption = pm.ordinal(); - playerIdList = this.tile.getMothership().getPlayerList(); - selectBox.clear(); - for(PlayerID pid: playerIdList) { - selectBox.addString(pid.getName()); - } - } + abstract public void resetData(); @Override public void mothershipResponsePacketRecieved() { - // T resetData(); } - private String[] getDropdownOptions() { + protected String[] getDropdownOptions() { int num = Mothership.PermissionMode.values().length; String[] result = new String[num]; @@ -107,10 +97,8 @@ private String[] getDropdownOptions() { return result; } - private void applyData() { + protected void applyData() { GuiMothershipSettings actualParent = ((GuiMothershipSettings) this.parent); - /*tile.getMothership().setPlayerList(playerIdList); - tile.getMothership().setPermissionMode(mode);*/ actualParent.sendMothershipSettingsPacket(); } @@ -170,16 +158,6 @@ protected void drawExtraScreenElements(int mouseX, int mouseY, float ticks) this.fontRendererObj.drawString(GCCoreUtil.translate("container.inventory"), guiX+8, guiY+this.ySize - 94, 4210752); } - @Override - public ResourceLocation getIcon() { - return icon; - } - - @Override - public String getTooltip() { - return GCCoreUtil.translate("tile.mothershipSettings.permission"); - } - // DROPDOWN SHIT @Override public boolean canBeClickedBy(GuiElementDropdown dropdown, EntityPlayer player) { @@ -187,19 +165,7 @@ public boolean canBeClickedBy(GuiElementDropdown dropdown, EntityPlayer player) } @Override - public void onSelectionChanged(GuiElementDropdown dropdown, int selection) { - if(dropdown == modeDropdown) { - PermissionMode mode = PermissionMode.values()[selection]; - tile.getMothership().setPermissionMode(mode); - this.applyData(); - } - - } - - @Override - public int getInitialSelection(GuiElementDropdown dropdown) { - return this.tile.getMothership().getPermissionMode().ordinal(); - } + abstract public int getInitialSelection(GuiElementDropdown dropdown); @Override public void onIntruderInteraction() { @@ -221,7 +187,6 @@ public void onTextChanged(GuiElementTextBox textBox, String newText) { @Override public String getInitialText(GuiElementTextBox textBox) { return ""; - //return ""; } @Override @@ -246,4 +211,5 @@ public void mothershipOperationFailed(String message) { errorTime = 60.0F; } + } diff --git a/src/main/java/de/katzenpapst/amunra/client/gui/tabs/AbstractTab.java b/src/main/java/de/katzenpapst/amunra/client/gui/tabs/AbstractTab.java index 051d0570..f85e99e5 100755 --- a/src/main/java/de/katzenpapst/amunra/client/gui/tabs/AbstractTab.java +++ b/src/main/java/de/katzenpapst/amunra/client/gui/tabs/AbstractTab.java @@ -260,4 +260,9 @@ public void onTabActivated() {} abstract public ResourceLocation getIcon(); abstract public String getTooltip(); + + public String getTooltipDescription() + { + return null; + } } diff --git a/src/main/java/de/katzenpapst/amunra/client/gui/tabs/TabMothershipLanding.java b/src/main/java/de/katzenpapst/amunra/client/gui/tabs/TabMothershipLanding.java new file mode 100755 index 00000000..a7460840 --- /dev/null +++ b/src/main/java/de/katzenpapst/amunra/client/gui/tabs/TabMothershipLanding.java @@ -0,0 +1,83 @@ +package de.katzenpapst.amunra.client.gui.tabs; + +import de.katzenpapst.amunra.AmunRa; +import de.katzenpapst.amunra.client.gui.GuiMothershipSettings; +import de.katzenpapst.amunra.helper.PlayerID; +import de.katzenpapst.amunra.mothership.Mothership; +import de.katzenpapst.amunra.mothership.Mothership.PermissionMode; +import de.katzenpapst.amunra.network.packet.PacketSimpleAR; +import de.katzenpapst.amunra.network.packet.PacketSimpleAR.EnumSimplePacket; +import de.katzenpapst.amunra.tile.TileEntityMothershipSettings; +import micdoodle8.mods.galacticraft.core.client.gui.element.GuiElementDropdown; +import micdoodle8.mods.galacticraft.core.util.GCCoreUtil; +import net.minecraft.client.Minecraft; +import net.minecraft.util.ResourceLocation; + +public class TabMothershipLanding extends AbstractPermissionTab { + + protected static final ResourceLocation icon = new ResourceLocation(AmunRa.ASSETPREFIX, "textures/gui/landing-permission.png"); + + public TabMothershipLanding(TileEntityMothershipSettings tile, GuiMothershipSettings parent, Minecraft mc, int width, int height, int xSize, int ySize) { + super(tile, parent, mc, width, height, xSize, ySize); + } + + @Override + public void resetData() { + Mothership.PermissionMode pm = this.tile.getMothership().getLandingPermissionMode(); + modeDropdown.selectedOption = pm.ordinal(); + playerIdList.clear(); + + Mothership m = this.tile.getMothership(); + + playerIdList.addAll(m.getPlayerListLanding()); + selectBox.clear(); + for(PlayerID pid: playerIdList) { + selectBox.addString(pid.getName()); + } + } + + @Override + public ResourceLocation getIcon() { + return icon; + } + + @Override + public String getTooltip() { + return GCCoreUtil.translate("tile.mothershipSettings.permissionLand"); + } + + @Override + public void onSelectionChanged(GuiElementDropdown dropdown, int selection) { + if(dropdown == modeDropdown) { + PermissionMode mode = PermissionMode.values()[selection]; + tile.getMothership().setLandingPermissionMode(mode); + this.applyData(); + } + + } + + @Override + public int getInitialSelection(GuiElementDropdown dropdown) { + return this.tile.getMothership().getLandingPermissionMode().ordinal(); + } + + @Override + protected void addUsername(Mothership mothership, String userName) { + AmunRa.packetPipeline.sendToServer(new PacketSimpleAR( + EnumSimplePacket.S_ADD_MOTHERSHIP_PLAYER, + this.tile.getMothership().getID(), + textBoxUsername.text, 0)); + } + + @Override + protected void removeUsernameFromList(int position) { + playerIdList.remove(position); + tile.getMothership().setPlayerListLanding(playerIdList); + } + + @Override + public String getTooltipDescription() + { + return GCCoreUtil.translate("tile.mothershipSettings.permissionLandDesc"); + } +} diff --git a/src/main/java/de/katzenpapst/amunra/client/gui/tabs/TabMothershipUsage.java b/src/main/java/de/katzenpapst/amunra/client/gui/tabs/TabMothershipUsage.java index a470d719..e46a3308 100755 --- a/src/main/java/de/katzenpapst/amunra/client/gui/tabs/TabMothershipUsage.java +++ b/src/main/java/de/katzenpapst/amunra/client/gui/tabs/TabMothershipUsage.java @@ -1,9 +1,82 @@ package de.katzenpapst.amunra.client.gui.tabs; -public class TabMothershipUsage { +import de.katzenpapst.amunra.AmunRa; +import de.katzenpapst.amunra.client.gui.GuiMothershipSettings; +import de.katzenpapst.amunra.helper.PlayerID; +import de.katzenpapst.amunra.mothership.Mothership; +import de.katzenpapst.amunra.mothership.Mothership.PermissionMode; +import de.katzenpapst.amunra.network.packet.PacketSimpleAR; +import de.katzenpapst.amunra.network.packet.PacketSimpleAR.EnumSimplePacket; +import de.katzenpapst.amunra.tile.TileEntityMothershipSettings; +import micdoodle8.mods.galacticraft.core.client.gui.element.GuiElementDropdown; +import micdoodle8.mods.galacticraft.core.util.GCCoreUtil; +import net.minecraft.client.Minecraft; +import net.minecraft.util.ResourceLocation; - public TabMothershipUsage() { - // TODO Auto-generated constructor stub +public class TabMothershipUsage extends AbstractPermissionTab { + + protected static final ResourceLocation icon = new ResourceLocation(AmunRa.ASSETPREFIX, "textures/gui/usage-permission.png"); + + public TabMothershipUsage(TileEntityMothershipSettings tile, GuiMothershipSettings parent, Minecraft mc, int width, int height, int xSize, int ySize) { + super(tile, parent, mc, width, height, xSize, ySize); + } + + @Override + public void resetData() { + Mothership.PermissionMode pm = this.tile.getMothership().getUsagePermissionMode(); + modeDropdown.selectedOption = pm.ordinal(); + playerIdList.clear(); + + Mothership m = this.tile.getMothership(); + + playerIdList.addAll(m.getPlayerListUsage()); + selectBox.clear(); + for(PlayerID pid: playerIdList) { + selectBox.addString(pid.getName()); + } + } + + @Override + public ResourceLocation getIcon() { + return icon; + } + + @Override + public String getTooltip() { + return GCCoreUtil.translate("tile.mothershipSettings.permissionUse"); } + @Override + public void onSelectionChanged(GuiElementDropdown dropdown, int selection) { + if(dropdown == modeDropdown) { + PermissionMode mode = PermissionMode.values()[selection]; + tile.getMothership().setUsagePermissionMode(mode); + this.applyData(); + } + } + + @Override + public int getInitialSelection(GuiElementDropdown dropdown) { + return this.tile.getMothership().getUsagePermissionMode().ordinal(); + } + + @Override + protected void addUsername(Mothership mothership, String userName) { + AmunRa.packetPipeline.sendToServer(new PacketSimpleAR( + EnumSimplePacket.S_ADD_MOTHERSHIP_PLAYER, + this.tile.getMothership().getID(), + textBoxUsername.text, 1)); + } + + @Override + protected void removeUsernameFromList(int position) { + playerIdList.remove(position); + tile.getMothership().setPlayerListUsage(playerIdList); + } + + @Override + public String getTooltipDescription() + { + return GCCoreUtil.translate("tile.mothershipSettings.permissionUseDesc"); + } } diff --git a/src/main/java/de/katzenpapst/amunra/mothership/Mothership.java b/src/main/java/de/katzenpapst/amunra/mothership/Mothership.java index 4326d116..122313b1 100755 --- a/src/main/java/de/katzenpapst/amunra/mothership/Mothership.java +++ b/src/main/java/de/katzenpapst/amunra/mothership/Mothership.java @@ -43,9 +43,11 @@ public enum PermissionMode { // protected List playerList = new ArrayList(); - protected Set playerSet = new HashSet(); + protected Set playerSetLanding = new HashSet(); + protected Set playerSetUsage = new HashSet(); - protected PermissionMode permMode = PermissionMode.NONE; + protected PermissionMode permModeLanding = PermissionMode.NONE; + protected PermissionMode permModeUsage = PermissionMode.NONE; protected PlayerID owner; @@ -93,24 +95,47 @@ public boolean setParent(CelestialBody parent) { return true; } - public Set getPlayerList() { - return playerSet; + public Set getPlayerListLanding() { + return playerSetLanding; } - public void addPlayerToList(PlayerID pi) { - playerSet.add(pi); + public void addPlayerToListLanding(PlayerID pi) { + playerSetLanding.add(pi); } - public void setPlayerSet(Set list) { - playerSet = list; + public void setPlayerListLanding(Collection list) { + playerSetLanding.clear(); + playerSetLanding.addAll(list); + //playerSetLanding = list; } - public PermissionMode getPermissionMode() { - return this.permMode; + public Set getPlayerListUsage() { + return playerSetUsage; } - public void setPermissionMode(PermissionMode mode) { - this.permMode = mode; + public void addPlayerToListUsage(PlayerID pi) { + playerSetUsage.add(pi); + } + + public void setPlayerListUsage(Collection list) { + playerSetUsage.clear(); + playerSetUsage.addAll(list); + } + + public PermissionMode getLandingPermissionMode() { + return this.permModeLanding; + } + + public void setLandingPermissionMode(PermissionMode mode) { + this.permModeLanding = mode; + } + + public PermissionMode getUsagePermissionMode() { + return this.permModeUsage; + } + + public void setUsagePermissionMode(PermissionMode mode) { + this.permModeUsage = mode; } @Override @@ -492,17 +517,30 @@ public void readSettingsFromNBT(NBTTagCompound data) { } NBTTagList list = data.getTagList("playerList", Constants.NBT.TAG_COMPOUND); - playerSet.clear(); + playerSetLanding = new HashSet(); //playerList.clear(); for(int i=0;i(); + for(int i=0;in(KW?2k{udY5ZlI-=s6@9SDwbA=DMD;vs2Dr2bm&B-W=N%U>d*m%7#NYV zF<3%k03iWVCqR{|BGG>&X&lE+;<`9a{N6i;yZ2%{wwtujTi(0h-Ti*w``!2VyWfei ze|Sa%Na@h4Icf;c-RUVeO(TR1*K4h5wVI$cDl$xKr-`E?00xN1K|5ETI&v3&|G)BLl)>-S-gvq(!q7N*{m+3wMGbG z6&fQ_Iz8n=NGlT|7$GFS@7i@LG^n+Yf7X77Y$A0O041bEsbRF%oH)J6WCqq7X3{T3 zJ3E>+-$u!N&t0-xvlCU+e1H9_ZN6vbpS=iA?isn?1R&|wahwQJIw*tMLkLOy=K_uz zChgY9rY1?NRlar0yM_ZGfuZi!4fO0qSo$5B4aiSHHJDh(_dTSeP?4b#>q^ZVf2naw zl~o#yP}*$LaJPCZ-fuqymH;OTjYlvNwZs(&Aq)uvVtx63jnOkF*?PQc7RrY+^~gg~hwJg>z^-&Dw^ zCMj*2m~AvS_`Y57g-_X6`{9eue)Xx%UM3PeuZ6OSOu0781#w=gtQruNRi+AO;O!4~ z6%}WR-CP)GyMAQ`rsqs&lJ%6;;^(f1tOj}q9=2wSS#IUeQhzE z7`uL}ui^TSfA$0rJAY~ye~2Yw0Hl8Hvf)s1mP9&FI(wYT>O+W)r}dks-_yxVK{Gw4 z0Uf)!paDG(nrOB|7R(_Sv*Yb!;oNA}=;&IX%oIYK(oqq6{-SSM4R zZ=mm-3i}jiVS0}Gwado+{W2p0A*A5|_6iMdv3Aapu9c8onglhTm z-ZKjnyhtkUG8}LqnK?#0`5GIQC36JvWRA`1GS%|mgDaeN#e(w92=D- zQ;RaB~s#xH8Ed$^caljatM21FCj-x_iBo0MPxpcTN z_-Pi+4St$MbI*O6d0wmYX*Q9{zw*avSe9>8mmr7)Q!QeyX}yOZTa6k*n7TeTo~F6= slzMF~1S*6uAnUttJs~~ z990mDb)f3OEHB@Wnw+{QNHEi1rzpJQf(_S=cwQ|#5Bx_^&XB^9NsMX4pHkVLUL?mSL zi9FM8U&Ka4P?bn5V4+$K>4^pt0#s{Fe|!DICjoGTNh}Z<`0~UinjAJ{! z9Pzgp&5m%yS>Y@HXJNu68!xuR7!9>2Wt`IE`j=poxrgZE`lJUf1Jz? zkT0xIB1wL;Ldh?;7ktolY}hc^DJU&LGKGkSIt3?+Q4siic5w^$>}kr6S3=O9hA*Df z1xKTk;#Rto0xJonb;wtY7gnD(U41eFfhkmszY0N>fAVjuhdXg6dL|8|A^+5Pgxy%DBO=&#FF~-!dtVyx zw>l~=es{mE0p5kFf4U(d5F3iYPeMPm(}fBQq#38TvZ-`W?* zHde})(T4T)tr zakJU=e(xmskZVnCn!rM2%5m5qv z?|(gUE4}`(37b+o;l};I%kV(s!^Tk+f?&_|11|{!mgSiE_oQ%aI}roJbNfuYl$z}R zG)v~XKh2W4u1_;n!b3Ma&H9EWUi#xS?22ukZ9YVzOaN2_QAJhv;bX6|Zdxfx;Cf?J v{SC^+<=9XWBSA&>-+CfVMp#Y~f3L*9{#gPvE%&QC00000NkvXXu0mjfj?slS diff --git a/src/main/resources/assets/amunra/textures/gui/landing-permission.png b/src/main/resources/assets/amunra/textures/gui/landing-permission.png new file mode 100755 index 0000000000000000000000000000000000000000..91ef705cd45f787594e46091131f281ad9c77cea GIT binary patch literal 626 zcmV-&0*(ENP)1MJR>O%nG)zd)Ts(zpr4kiv}{7Y0KxAsFHm2@%L(90ZB+ z2mTxP2OI)!5-VNs>J&ExxD4$p0uER$iBtr7y?(ONr&4SUnErk2HxVI5Lf9K3}+A=LI+JKY_90{5g6~o5etG#mnQvZ(S%53&x6Qfaa*AI@e ztwj6+oOU{$&b)g;#3Gdzgm}|uG8gla^E~f!-j4$#j4;Ar$XPC~29ZzAT;@&V=`jC( z6ULbRAgr}RuOst|w`BhEFH)Udl9M`Nj1hXSUNJ{SC9?}F6vitcLKHP=ho5M?e0Zc2 zUoQ?|*Dc)Xd2tuas@ZqK?MFT{e}inkfKrN7QnEQ8$H`EgyTDTwaU=P0qoF8D3uGBD3&S|$0u>U z9C0V48%HRm_uNPm!sa$%81Sb4&rpeJj1hbLi-=zP4+#LMnPrNlN%CXkfDlD35KvkZ zg#lq}hq`?*Y!wZxf&&6-W|_Kuz|8!0{Ng#r{4(9R0}9e4A=rJ##*2I8r>_!ju6Qa&d(9%)TuS114-yQ9;JyX)WQlIFYckW zgO|+{w_7we9+N3mi3Tisebn;;+1Z^@!G|?LG3ba}>)Js+B60 zc6@3M=z~QlB;6QEQ}V?U)3Zx#Z9b!BF5pkq@D~<|5Sl@7Hd~M+T~G><6iEfw^#E`x zQ+RS7<%S?BtuQ|vQe@Zsv616@ayZPL*w%ILjuZJwk6$B<@Wb#w X?)XHxZnx^n00000NkvXXu0mjf{se%W literal 0 HcmV?d00001 From 07a55a373f7461e09a3d3920d70abc14db9bdf4b Mon Sep 17 00:00:00 2001 From: katzenpapst Date: Fri, 23 Jun 2017 22:27:53 +0200 Subject: [PATCH 6/6] version --- build.gradle | 2 +- changelog.txt | 7 +++++++ src/main/java/de/katzenpapst/amunra/AmunRa.java | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 4fe22ce4..3d7c8a95 100755 --- a/build.gradle +++ b/build.gradle @@ -30,7 +30,7 @@ apply plugin: 'forge' -version = "0.4.7" +version = "0.4.8" group = "de.katzenpapst.amunra" // http://maven.apache.org/guides/mini/guide-naming-conventions.html archivesBaseName = "AmunRa-GC" def gc_version = "3.0.12.498" diff --git a/changelog.txt b/changelog.txt index 9f45bcd6..fcd21f84 100755 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,10 @@ +=== 0.4.8 === +- shuttle saves dock position +- improved shuttle dismounting +- potentially fixed a crash with servers like Thermos or KCauldron +- made the mehen belt slightly brighter +- permissions for mothership landing and control are now separate + === 0.4.7 === - minimal GC version is build 498 - made the Artificial Gravity Generator work using the new events diff --git a/src/main/java/de/katzenpapst/amunra/AmunRa.java b/src/main/java/de/katzenpapst/amunra/AmunRa.java index c929c52e..2610658e 100755 --- a/src/main/java/de/katzenpapst/amunra/AmunRa.java +++ b/src/main/java/de/katzenpapst/amunra/AmunRa.java @@ -102,7 +102,7 @@ public class AmunRa { public static final String MODID = "GalacticraftAmunRa"; public static final String MODNAME = "Amun-Ra"; - public static final String VERSION = "0.4.7"; + public static final String VERSION = "0.4.8"; public static ARChannelHandler packetPipeline;