use of micdoodle8.mods.galacticraft.core.inventory.InventoryExtended in project Galacticraft by micdoodle8.
the class CommandGCInv method processCommand.
@Override
public void processCommand(ICommandSender sender, String[] args) throws CommandException {
if (CommandGCInv.firstuse) {
CommandGCInv.firstuse = false;
CommandGCInv.initialise();
}
if (args.length == 2) {
try {
EntityPlayerMP thePlayer = PlayerUtil.getPlayerBaseServerFromPlayerUsername(args[1], true);
if (thePlayer != null && !thePlayer.isDead && thePlayer.worldObj != null) {
GCPlayerStats stats = GCPlayerStats.get(thePlayer);
if (args[0].equalsIgnoreCase("drop")) {
InventoryExtended gcInventory = stats.getExtendedInventory();
gcInventory.dropExtendedItems(thePlayer);
} else if (args[0].equalsIgnoreCase("save")) {
InventoryExtended gcInventory = stats.getExtendedInventory();
ItemStack[] saveinv = new ItemStack[gcInventory.getSizeInventory()];
for (int i = 0; i < gcInventory.getSizeInventory(); i++) {
saveinv[i] = gcInventory.getStackInSlot(i);
gcInventory.setInventorySlotContents(i, null);
}
CommandGCInv.savedata.put(args[1].toLowerCase(), saveinv);
CommandGCInv.dontload.add(args[1].toLowerCase());
CommandGCInv.writefile();
System.out.println("[GCInv] Saving and clearing GC inventory slots of " + PlayerUtil.getName(thePlayer));
} else if (args[0].equalsIgnoreCase("restore")) {
ItemStack[] saveinv = CommandGCInv.savedata.get(args[1].toLowerCase());
CommandGCInv.dontload.remove(args[1].toLowerCase());
if (saveinv == null) {
System.out.println("[GCInv] Tried to restore but player " + PlayerUtil.getName(thePlayer) + " had no saved GC inventory items.");
return;
}
CommandGCInv.doLoad(thePlayer);
} else if (args[0].equalsIgnoreCase("clear")) {
InventoryExtended gcInventory = stats.getExtendedInventory();
for (int i = 0; i < gcInventory.getSizeInventory(); i++) {
gcInventory.setInventorySlotContents(i, null);
}
} else {
throw new WrongUsageException("Invalid GCInv command. Usage: " + this.getCommandUsage(sender), new Object[0]);
}
} else {
// inventory already)
if (args[0].equalsIgnoreCase("restore")) {
ItemStack[] saveinv = CommandGCInv.savedata.get(args[1].toLowerCase());
if (saveinv != null) {
System.out.println("[GCInv] Restore command for offline player " + args[1] + ", setting to restore GCInv on next login.");
CommandGCInv.dontload.remove(args[1].toLowerCase());
// Now it can autoload on next player logon
return;
}
}
// No player found, and not a 'restore' command
if (args[0].equalsIgnoreCase("clear") || args[0].equalsIgnoreCase("save") || args[0].equalsIgnoreCase("drop")) {
System.out.println("GCInv command: player " + args[1] + " not found.");
} else {
throw new WrongUsageException("Invalid GCInv command. Usage: " + this.getCommandUsage(sender), new Object[0]);
}
}
} catch (final Exception e) {
System.out.println(e.toString());
e.printStackTrace();
}
} else {
throw new WrongUsageException("Not enough command arguments! Usage: " + this.getCommandUsage(sender), new Object[0]);
}
}
use of micdoodle8.mods.galacticraft.core.inventory.InventoryExtended in project Galacticraft by micdoodle8.
the class CommandGCInv method doLoad.
public static void doLoad(EntityPlayerMP thePlayer) {
String theName = PlayerUtil.getName(thePlayer).toLowerCase();
if (!CommandGCInv.dontload.contains(theName)) // This is a simple flag: if the playername is in dontload then no
// restore command has yet been run.
// Dontload resets to nothing on server restart so that all will
// auto-restore on a server restart.
{
ItemStack[] saveinv = CommandGCInv.savedata.get(theName);
InventoryExtended gcInventory = GCPlayerStats.get(thePlayer).getExtendedInventory();
for (int i = 0; i < gcInventory.getSizeInventory(); i++) {
gcInventory.setInventorySlotContents(i, saveinv[i]);
}
CommandGCInv.savedata.remove(theName);
CommandGCInv.writefile();
System.out.println("[GCInv] Restored GC inventory slots of " + PlayerUtil.getName(thePlayer));
} else {
System.out.println("[GCInv] Player " + PlayerUtil.getName(thePlayer) + " was spawned without restoring the GCInv save. Run /gcinv restore playername to restore it.");
}
}
use of micdoodle8.mods.galacticraft.core.inventory.InventoryExtended in project MorePlanets by SteveKunG.
the class ItemCreativeSpaceKit method onItemRightClick.
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
if (player instanceof EntityPlayerMP) {
GCPlayerStats stats = GCPlayerStats.get(player);
InventoryExtended inv = stats.getExtendedInventory();
// Oxygen Mask
inv.setInventorySlotContents(0, new ItemStack(GCItems.oxMask));
// Oxygen Gear
inv.setInventorySlotContents(1, new ItemStack(GCItems.oxygenGear));
// Creative Oxygen Tank
inv.setInventorySlotContents(2, new ItemStack(GCItems.oxygenCanisterInfinite));
// Creative Oxygen Tank
inv.setInventorySlotContents(3, new ItemStack(GCItems.oxygenCanisterInfinite));
// Parachute
inv.setInventorySlotContents(4, new ItemStack(GCItems.parachute));
// Frequency Module
inv.setInventorySlotContents(5, new ItemStack(GCItems.basicItem, 1, 19));
// Thermal Armor Tier 2
inv.setInventorySlotContents(6, new ItemStack(VenusItems.thermalPaddingTier2, 1, 0));
// Thermal Armor Tier 2
inv.setInventorySlotContents(7, new ItemStack(VenusItems.thermalPaddingTier2, 1, 1));
// Thermal Armor Tier 2
inv.setInventorySlotContents(8, new ItemStack(VenusItems.thermalPaddingTier2, 1, 2));
// Thermal Armor Tier 2
inv.setInventorySlotContents(9, new ItemStack(VenusItems.thermalPaddingTier2, 1, 3));
// Shield Controller
inv.setInventorySlotContents(10, new ItemStack(VenusItems.basicItem, 1, 0));
}
return new ActionResult<>(EnumActionResult.PASS, player.getHeldItem(hand));
}
use of micdoodle8.mods.galacticraft.core.inventory.InventoryExtended in project MorePlanets by SteveKunG.
the class TeleportUtils method teleportPlayerToPlanet.
public static EntityPlayer teleportPlayerToPlanet(EntityPlayerMP player, MinecraftServer server, int sourceDim, int targetDim) {
WorldServer sourceWorld = server.getWorld(sourceDim);
WorldServer targetWorld = server.getWorld(targetDim);
BlockPos spawnPos = targetWorld.getTopSolidOrLiquidBlock(targetWorld.getSpawnPoint());
PlayerList playerList = server.getPlayerList();
GCPlayerStats stats = GCPlayerStats.get(player);
InventoryExtended inv = stats.getExtendedInventory();
player.dimension = targetDim;
player.connection.sendPacket(new SPacketRespawn(player.dimension, targetWorld.getDifficulty(), targetWorld.getWorldInfo().getTerrainType(), player.interactionManager.getGameType()));
playerList.updatePermissionLevel(player);
sourceWorld.removeEntityDangerously(player);
player.isDead = false;
// world transfer
player.setLocationAndAngles(spawnPos.getX(), spawnPos.getY(), spawnPos.getZ(), player.rotationYaw, player.rotationPitch);
player.connection.setPlayerLocation(spawnPos.getX(), spawnPos.getY(), spawnPos.getZ(), player.rotationYaw, player.rotationPitch);
targetWorld.spawnEntity(player);
targetWorld.updateEntityWithOptionalForce(player, false);
player.setWorld(targetWorld);
// prevent kicked from LAN or server world
MorePlanetsMod.PROXY.resetFloatingTick(player);
playerList.preparePlayer(player, sourceWorld);
player.connection.setPlayerLocation(spawnPos.getX(), spawnPos.getY(), spawnPos.getZ(), player.rotationYaw, player.rotationPitch);
player.interactionManager.setWorld(targetWorld);
player.connection.sendPacket(new SPacketPlayerAbilities(player.capabilities));
playerList.updateTimeAndWeatherForPlayer(player, targetWorld);
playerList.syncPlayerInventory(player);
if (targetWorld.provider instanceof IStartedDimension) {
IStartedDimension dimension = (IStartedDimension) targetWorld.provider;
LoggerMP.info("Setting up survival player gear");
dimension.setup(player);
} else if (targetWorld.provider instanceof WorldProviderMoon) {
LoggerMP.info("Setting up default survival player gear for Moon");
inv.setInventorySlotContents(0, new ItemStack(GCItems.oxMask));
inv.setInventorySlotContents(1, new ItemStack(GCItems.oxygenGear));
inv.setInventorySlotContents(2, new ItemStack(GCItems.oxTankMedium));
inv.setInventorySlotContents(3, new ItemStack(GCItems.oxTankMedium));
inv.setInventorySlotContents(4, new ItemStack(GCItems.parachute));
inv.setInventorySlotContents(5, new ItemStack(GCItems.basicItem, 1, 19));
player.inventory.addItemStackToInventory(new ItemStack(Blocks.LOG, 32 + player.world.rand.nextInt(32)));
player.inventory.addItemStackToInventory(new ItemStack(Blocks.COBBLESTONE, 32 + player.world.rand.nextInt(32)));
player.inventory.addItemStackToInventory(new ItemStack(Blocks.DIRT, 16));
player.inventory.addItemStackToInventory(new ItemStack(Blocks.SAPLING, 8 + player.world.rand.nextInt(8)));
player.inventory.addItemStackToInventory(new ItemStack(Items.IRON_INGOT, 32 + player.world.rand.nextInt(16)));
player.inventory.addItemStackToInventory(new ItemStack(Items.WHEAT_SEEDS, 16 + player.world.rand.nextInt(16)));
player.inventory.addItemStackToInventory(new ItemStack(Items.POTATO, 16 + player.world.rand.nextInt(16)));
player.inventory.addItemStackToInventory(new ItemStack(Items.CARROT, 16 + player.world.rand.nextInt(16)));
player.inventory.addItemStackToInventory(new ItemStack(Items.WATER_BUCKET));
player.inventory.addItemStackToInventory(new ItemStack(Items.WATER_BUCKET));
player.inventory.addItemStackToInventory(new ItemStack(GCBlocks.landingPad, 9));
ItemStack rocket = new ItemStack(GCItems.rocketTier1);
rocket.setTagCompound(new NBTTagCompound());
rocket.getTagCompound().setInteger("RocketFuel", 1000);
player.inventory.addItemStackToInventory(rocket);
player.inventory.addItemStackToInventory(new ItemStack(AsteroidsItems.canisterLOX));
player.inventory.addItemStackToInventory(new ItemStack(AsteroidsItems.canisterLOX));
player.inventory.addItemStackToInventory(new ItemStack(AsteroidsItems.canisterLOX));
} else if (targetWorld.provider instanceof WorldProviderMars) {
LoggerMP.info("Setting up default survival player gear for Mars");
// Knows how to build T2 rocket
SchematicRegistry.unlockNewPage(player, new ItemStack(GCItems.schematic, 1, 1));
inv.setInventorySlotContents(0, new ItemStack(GCItems.oxMask));
inv.setInventorySlotContents(1, new ItemStack(GCItems.oxygenGear));
inv.setInventorySlotContents(2, new ItemStack(GCItems.oxTankMedium));
inv.setInventorySlotContents(3, new ItemStack(GCItems.oxTankMedium));
inv.setInventorySlotContents(4, new ItemStack(GCItems.parachute));
inv.setInventorySlotContents(5, new ItemStack(GCItems.basicItem, 1, 19));
inv.setInventorySlotContents(6, new ItemStack(AsteroidsItems.thermalPadding));
inv.setInventorySlotContents(7, new ItemStack(AsteroidsItems.thermalPadding, 1, 1));
inv.setInventorySlotContents(8, new ItemStack(AsteroidsItems.thermalPadding, 1, 2));
inv.setInventorySlotContents(9, new ItemStack(AsteroidsItems.thermalPadding, 1, 3));
player.inventory.addItemStackToInventory(new ItemStack(Blocks.LOG, 32 + player.world.rand.nextInt(32)));
player.inventory.addItemStackToInventory(new ItemStack(Blocks.COBBLESTONE, 32 + player.world.rand.nextInt(32)));
player.inventory.addItemStackToInventory(new ItemStack(Blocks.DIRT, 16));
player.inventory.addItemStackToInventory(new ItemStack(Blocks.SAPLING, 8 + player.world.rand.nextInt(8)));
player.inventory.addItemStackToInventory(new ItemStack(Items.IRON_INGOT, 32 + player.world.rand.nextInt(16)));
player.inventory.addItemStackToInventory(new ItemStack(Items.WHEAT_SEEDS, 16 + player.world.rand.nextInt(16)));
player.inventory.addItemStackToInventory(new ItemStack(Items.POTATO, 16 + player.world.rand.nextInt(16)));
player.inventory.addItemStackToInventory(new ItemStack(Items.CARROT, 16 + player.world.rand.nextInt(16)));
player.inventory.addItemStackToInventory(new ItemStack(Items.WATER_BUCKET));
player.inventory.addItemStackToInventory(new ItemStack(Items.WATER_BUCKET));
player.inventory.addItemStackToInventory(new ItemStack(GCBlocks.landingPad, 9));
ItemStack rocket = new ItemStack(MarsItems.rocketMars);
rocket.setTagCompound(new NBTTagCompound());
rocket.getTagCompound().setInteger("RocketFuel", 1000);
player.inventory.addItemStackToInventory(rocket);
player.inventory.addItemStackToInventory(new ItemStack(AsteroidsItems.canisterLOX));
player.inventory.addItemStackToInventory(new ItemStack(AsteroidsItems.canisterLOX));
player.inventory.addItemStackToInventory(new ItemStack(AsteroidsItems.canisterLOX));
player.inventory.addItemStackToInventory(new ItemStack(AsteroidsItems.canisterLOX));
} else if (targetWorld.provider instanceof WorldProviderVenus) {
LoggerMP.info("Setting up default survival player gear for Venus");
// Knows how to build T2 rocket
SchematicRegistry.unlockNewPage(player, new ItemStack(GCItems.schematic, 1, 1));
// Knows how to build T3 rocket
SchematicRegistry.unlockNewPage(player, new ItemStack(MarsItems.schematic, 1, 0));
inv.setInventorySlotContents(0, new ItemStack(GCItems.oxMask));
inv.setInventorySlotContents(1, new ItemStack(GCItems.oxygenGear));
inv.setInventorySlotContents(2, new ItemStack(GCItems.oxTankHeavy));
inv.setInventorySlotContents(3, new ItemStack(GCItems.oxTankHeavy));
inv.setInventorySlotContents(4, new ItemStack(GCItems.parachute));
inv.setInventorySlotContents(5, new ItemStack(GCItems.basicItem, 1, 19));
inv.setInventorySlotContents(6, new ItemStack(VenusItems.thermalPaddingTier2));
inv.setInventorySlotContents(7, new ItemStack(VenusItems.thermalPaddingTier2, 1, 1));
inv.setInventorySlotContents(8, new ItemStack(VenusItems.thermalPaddingTier2, 1, 2));
inv.setInventorySlotContents(9, new ItemStack(VenusItems.thermalPaddingTier2, 1, 3));
inv.setInventorySlotContents(10, new ItemStack(VenusItems.basicItem));
player.inventory.addItemStackToInventory(new ItemStack(Blocks.LOG, 32 + player.world.rand.nextInt(32)));
player.inventory.addItemStackToInventory(new ItemStack(Blocks.COBBLESTONE, 32 + player.world.rand.nextInt(32)));
player.inventory.addItemStackToInventory(new ItemStack(Blocks.DIRT, 16));
player.inventory.addItemStackToInventory(new ItemStack(Blocks.SAPLING, 8 + player.world.rand.nextInt(8)));
player.inventory.addItemStackToInventory(new ItemStack(Items.IRON_INGOT, 32 + player.world.rand.nextInt(16)));
player.inventory.addItemStackToInventory(new ItemStack(Items.WHEAT_SEEDS, 16 + player.world.rand.nextInt(16)));
player.inventory.addItemStackToInventory(new ItemStack(Items.POTATO, 16 + player.world.rand.nextInt(16)));
player.inventory.addItemStackToInventory(new ItemStack(Items.CARROT, 16 + player.world.rand.nextInt(16)));
player.inventory.addItemStackToInventory(new ItemStack(Items.WATER_BUCKET));
player.inventory.addItemStackToInventory(new ItemStack(Items.WATER_BUCKET));
player.inventory.addItemStackToInventory(new ItemStack(GCBlocks.landingPad, 9));
ItemStack rocket = new ItemStack(AsteroidsItems.tier3Rocket);
rocket.setTagCompound(new NBTTagCompound());
rocket.getTagCompound().setInteger("RocketFuel", 1000);
player.inventory.addItemStackToInventory(rocket);
player.inventory.addItemStackToInventory(new ItemStack(AsteroidsItems.canisterLOX));
player.inventory.addItemStackToInventory(new ItemStack(AsteroidsItems.canisterLOX));
player.inventory.addItemStackToInventory(new ItemStack(AsteroidsItems.canisterLOX));
player.inventory.addItemStackToInventory(new ItemStack(AsteroidsItems.canisterLOX));
} else if (targetWorld.provider instanceof WorldProviderAsteroids) {
LoggerMP.info("Setting up default survival player gear for Asteroids");
ITeleportType type = GalacticraftRegistry.getTeleportTypeForDimension(targetWorld.provider.getClass());
Vector3 spawnPosVec = type.getPlayerSpawnLocation(targetWorld, player);
ChunkPos pair = targetWorld.getChunk(spawnPosVec.intX() >> 4, spawnPosVec.intZ() >> 4).getPos();
player.setLocationAndAngles(spawnPosVec.x, spawnPosVec.y, spawnPosVec.z, player.rotationYaw, player.rotationPitch);
player.setSpawnChunk(new BlockPos(spawnPosVec.intX(), spawnPosVec.intY(), spawnPosVec.intZ()), true, GCCoreUtil.getDimensionID(targetWorld));
targetWorld.getChunkProvider().loadChunk(pair.x, pair.z);
type.setupAdventureSpawn(player);
type.onSpaceDimensionChanged(targetWorld, player, false);
} else {
LoggerMP.info("Setting up default survival player gear for Non-IStartedDimension world");
// Knows how to build T2 rocket
SchematicRegistry.unlockNewPage(player, new ItemStack(GCItems.schematic, 1, 1));
// Knows how to build T3 rocket
SchematicRegistry.unlockNewPage(player, new ItemStack(MarsItems.schematic, 1, 0));
inv.setInventorySlotContents(0, new ItemStack(GCItems.oxMask));
inv.setInventorySlotContents(1, new ItemStack(GCItems.oxygenGear));
inv.setInventorySlotContents(2, new ItemStack(GCItems.oxTankHeavy));
inv.setInventorySlotContents(3, new ItemStack(GCItems.oxTankHeavy));
inv.setInventorySlotContents(5, new ItemStack(GCItems.basicItem, 1, 19));
inv.setInventorySlotContents(6, new ItemStack(AsteroidsItems.thermalPadding));
inv.setInventorySlotContents(7, new ItemStack(AsteroidsItems.thermalPadding, 1, 1));
inv.setInventorySlotContents(8, new ItemStack(AsteroidsItems.thermalPadding, 1, 2));
inv.setInventorySlotContents(9, new ItemStack(AsteroidsItems.thermalPadding, 1, 3));
player.inventory.addItemStackToInventory(new ItemStack(AsteroidsItems.canisterLOX));
player.inventory.addItemStackToInventory(new ItemStack(AsteroidsItems.canisterLOX));
player.inventory.addItemStackToInventory(new ItemStack(AsteroidsItems.canisterLOX));
}
player.addPotionEffect(new PotionEffect(MobEffects.RESISTANCE, 15 * 20, 5));
player.getActivePotionEffects().forEach(potion -> player.connection.sendPacket(new SPacketEntityEffect(player.getEntityId(), potion)));
player.connection.sendPacket(new SPacketSetExperience(player.experience, player.experienceTotal, player.experienceLevel));
player.connection.sendPacket(new SPacketSpawnPosition(spawnPos));
AttributeMap attributemap = (AttributeMap) player.getAttributeMap();
Collection<IAttributeInstance> watchedAttribs = attributemap.getWatchedAttributes();
if (!watchedAttribs.isEmpty()) {
player.connection.sendPacket(new SPacketEntityProperties(player.getEntityId(), watchedAttribs));
}
FMLCommonHandler.instance().firePlayerChangedDimensionEvent(player, sourceDim, targetDim);
if (!(targetWorld.provider instanceof WorldProviderAsteroids)) {
player.setLocationAndAngles(spawnPos.getX(), spawnPos.getY(), spawnPos.getZ(), player.rotationYaw, player.rotationPitch);
player.setSpawnChunk(spawnPos, true, GCCoreUtil.getDimensionID(player.world));
}
if (!(targetWorld.provider instanceof WorldProviderAsteroids) && player.onGround && player.getBedLocation(GCCoreUtil.getDimensionID(player.world)) == null) {
int i = 30000000;
int x = Math.min(i, Math.max(-i, MathHelper.floor(player.posX + 0.5D)));
int y = Math.min(256, Math.max(0, MathHelper.floor(player.posY + 1.5D)));
int z = Math.min(i, Math.max(-i, MathHelper.floor(player.posZ + 0.5D)));
BlockPos spawnChunkPos = targetWorld.getTopSolidOrLiquidBlock(new BlockPos(x, y, z));
player.setSpawnChunk(spawnChunkPos, true, GCCoreUtil.getDimensionID(player.world));
}
GalacticraftCore.packetPipeline.sendTo(new PacketSimpleMP(EnumSimplePacketMP.C_RELOAD_RENDERER, player.dimension), player);
GalacticraftCore.packetPipeline.sendTo(new PacketSimpleMP(EnumSimplePacketMP.C_MESSAGE_SURVIVAL_PLANET, player.dimension, new Object[] { WorldUtil.getProviderForDimensionServer(targetDim).getDimensionType().getName() }), player);
return player;
}
Aggregations