Search in sources :

Example 1 with EntityHangingSchematic

use of micdoodle8.mods.galacticraft.core.entities.EntityHangingSchematic in project MorePlanets by SteveKunG.

the class ItemSchematicVariantsMP method onItemUse.

@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    ItemStack itemStack = player.getHeldItem(hand);
    BlockPos blockpos = pos.offset(facing);
    if (facing != EnumFacing.DOWN && facing != EnumFacing.UP && player.canPlayerEdit(blockpos, facing, itemStack)) {
        EntityHangingSchematic entityhanging = this.createEntity(world, blockpos, facing, this.getIndex(itemStack.getItemDamage()));
        if (entityhanging != null && entityhanging.onValidSurface()) {
            if (!world.isRemote) {
                world.spawnEntity(entityhanging);
                entityhanging.sendToClient(world, blockpos);
            }
            itemStack.shrink(1);
        }
        return EnumActionResult.SUCCESS;
    } else {
        return EnumActionResult.FAIL;
    }
}
Also used : EntityHangingSchematic(micdoodle8.mods.galacticraft.core.entities.EntityHangingSchematic) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack)

Example 2 with EntityHangingSchematic

use of micdoodle8.mods.galacticraft.core.entities.EntityHangingSchematic in project MorePlanets by SteveKunG.

the class ItemSchematicMP method onItemUse.

@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    ItemStack itemStack = player.getHeldItem(hand);
    BlockPos blockpos = pos.offset(facing);
    if (facing != EnumFacing.DOWN && facing != EnumFacing.UP && player.canPlayerEdit(blockpos, facing, itemStack)) {
        EntityHangingSchematic entityhanging = this.createEntity(world, blockpos, facing, this.getIndex(itemStack.getItemDamage()));
        if (entityhanging != null && entityhanging.onValidSurface()) {
            if (!world.isRemote) {
                world.spawnEntity(entityhanging);
                entityhanging.sendToClient(world, blockpos);
            }
            itemStack.shrink(1);
        }
        return EnumActionResult.SUCCESS;
    } else {
        return EnumActionResult.FAIL;
    }
}
Also used : EntityHangingSchematic(micdoodle8.mods.galacticraft.core.entities.EntityHangingSchematic) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack)

Example 3 with EntityHangingSchematic

use of micdoodle8.mods.galacticraft.core.entities.EntityHangingSchematic in project Galacticraft by micdoodle8.

the class PacketSimple method handleClientSide.

@SideOnly(Side.CLIENT)
@Override
public void handleClientSide(EntityPlayer player) {
    EntityPlayerSP playerBaseClient = null;
    GCPlayerStatsClient stats = null;
    if (player instanceof EntityPlayerSP) {
        playerBaseClient = (EntityPlayerSP) player;
        stats = GCPlayerStatsClient.get(playerBaseClient);
    } else {
        if (type != EnumSimplePacket.C_UPDATE_SPACESTATION_LIST && type != EnumSimplePacket.C_UPDATE_PLANETS_LIST && type != EnumSimplePacket.C_UPDATE_CONFIGS) {
            return;
        }
    }
    switch(this.type) {
        case C_AIR_REMAINING:
            if (String.valueOf(this.data.get(2)).equals(String.valueOf(PlayerUtil.getName(player)))) {
                TickHandlerClient.airRemaining = (Integer) this.data.get(0);
                TickHandlerClient.airRemaining2 = (Integer) this.data.get(1);
            }
            break;
        case C_UPDATE_DIMENSION_LIST:
            if (String.valueOf(this.data.get(0)).equals(PlayerUtil.getName(player))) {
                String dimensionList = (String) this.data.get(1);
                if (ConfigManagerCore.enableDebug) {
                    if (!dimensionList.equals(PacketSimple.spamCheckString)) {
                        GCLog.info("DEBUG info: " + dimensionList);
                        PacketSimple.spamCheckString = dimensionList;
                    }
                }
                final String[] destinations = dimensionList.split("\\?");
                List<CelestialBody> possibleCelestialBodies = Lists.newArrayList();
                Map<Integer, Map<String, GuiCelestialSelection.StationDataGUI>> spaceStationData = Maps.newHashMap();
                for (String str : destinations) {
                    CelestialBody celestialBody = WorldUtil.getReachableCelestialBodiesForName(str);
                    if (celestialBody == null && str.contains("$")) {
                        String[] values = str.split("\\$");
                        int homePlanetID = Integer.parseInt(values[4]);
                        for (Satellite satellite : GalaxyRegistry.getRegisteredSatellites().values()) {
                            if (satellite.getParentPlanet().getDimensionID() == homePlanetID) {
                                celestialBody = satellite;
                                break;
                            }
                        }
                        if (!spaceStationData.containsKey(homePlanetID)) {
                            spaceStationData.put(homePlanetID, new HashMap<String, GuiCelestialSelection.StationDataGUI>());
                        }
                        spaceStationData.get(homePlanetID).put(values[1], new GuiCelestialSelection.StationDataGUI(values[2], Integer.parseInt(values[3])));
                    // spaceStationNames.put(values[1], values[2]);
                    // spaceStationIDs.put(values[1], Integer.parseInt(values[3]));
                    // spaceStationHomes.put(values[1], Integer.parseInt(values[4]));
                    }
                    if (celestialBody != null) {
                        possibleCelestialBodies.add(celestialBody);
                    }
                }
                if (FMLClientHandler.instance().getClient().theWorld != null) {
                    if (!(FMLClientHandler.instance().getClient().currentScreen instanceof GuiCelestialSelection)) {
                        GuiCelestialSelection gui = new GuiCelestialSelection(false, possibleCelestialBodies);
                        gui.spaceStationMap = spaceStationData;
                        // gui.spaceStationNames = spaceStationNames;
                        // gui.spaceStationIDs = spaceStationIDs;
                        FMLClientHandler.instance().getClient().displayGuiScreen(gui);
                    } else {
                        ((GuiCelestialSelection) FMLClientHandler.instance().getClient().currentScreen).possibleBodies = possibleCelestialBodies;
                        ((GuiCelestialSelection) FMLClientHandler.instance().getClient().currentScreen).spaceStationMap = spaceStationData;
                    // ((GuiCelestialSelection) FMLClientHandler.instance().getClient().currentScreen).spaceStationNames = spaceStationNames;
                    // ((GuiCelestialSelection) FMLClientHandler.instance().getClient().currentScreen).spaceStationIDs = spaceStationIDs;
                    }
                }
            }
            break;
        case C_SPAWN_SPARK_PARTICLES:
            BlockPos pos = (BlockPos) this.data.get(0);
            Minecraft mc = Minecraft.getMinecraft();
            for (int i = 0; i < 4; i++) {
                if (mc != null && mc.getRenderViewEntity() != null && mc.effectRenderer != null && mc.theWorld != null) {
                    final EntityFX fx = new EntityFXSparks(mc.theWorld, pos.getX() - 0.15 + 0.5, pos.getY() + 1.2, pos.getZ() + 0.15 + 0.5, mc.theWorld.rand.nextDouble() / 20 - mc.theWorld.rand.nextDouble() / 20, mc.theWorld.rand.nextDouble() / 20 - mc.theWorld.rand.nextDouble() / 20);
                    if (fx != null) {
                        mc.effectRenderer.addEffect(fx);
                    }
                }
            }
            break;
        case C_UPDATE_GEAR_SLOT:
            int subtype = (Integer) this.data.get(3);
            String gearName = (String) this.data.get(0);
            EntityPlayer gearDataPlayer = player.worldObj.getPlayerEntityByName(gearName);
            if (gearDataPlayer != null) {
                PlayerGearData gearData = ClientProxyCore.playerItemData.get(PlayerUtil.getName(gearDataPlayer));
                if (gearData == null) {
                    gearData = new PlayerGearData(player);
                    if (!ClientProxyCore.gearDataRequests.contains(gearName)) {
                        GalacticraftCore.packetPipeline.sendToServer(new PacketSimple(PacketSimple.EnumSimplePacket.S_REQUEST_GEAR_DATA, getDimensionID(), new Object[] { gearName }));
                        ClientProxyCore.gearDataRequests.add(gearName);
                    }
                } else {
                    ClientProxyCore.gearDataRequests.remove(gearName);
                }
                EnumExtendedInventorySlot type = EnumExtendedInventorySlot.values()[(Integer) this.data.get(2)];
                EnumModelPacketType typeChange = EnumModelPacketType.values()[(Integer) this.data.get(1)];
                switch(type) {
                    case MASK:
                        gearData.setMask(subtype);
                        break;
                    case GEAR:
                        gearData.setGear(subtype);
                        break;
                    case LEFT_TANK:
                        gearData.setLeftTank(subtype);
                        break;
                    case RIGHT_TANK:
                        gearData.setRightTank(subtype);
                        break;
                    case PARACHUTE:
                        if (typeChange == EnumModelPacketType.ADD) {
                            String name;
                            if (subtype != -1) {
                                name = ItemParaChute.names[subtype];
                                gearData.setParachute(new ResourceLocation(Constants.ASSET_PREFIX, "textures/model/parachute/" + name + ".png"));
                            }
                        } else {
                            gearData.setParachute(null);
                        }
                        break;
                    case FREQUENCY_MODULE:
                        gearData.setFrequencyModule(subtype);
                        break;
                    case THERMAL_HELMET:
                        gearData.setThermalPadding(0, subtype);
                        break;
                    case THERMAL_CHESTPLATE:
                        gearData.setThermalPadding(1, subtype);
                        break;
                    case THERMAL_LEGGINGS:
                        gearData.setThermalPadding(2, subtype);
                        break;
                    case THERMAL_BOOTS:
                        gearData.setThermalPadding(3, subtype);
                        break;
                    case SHIELD_CONTROLLER:
                        gearData.setShieldController(subtype);
                        break;
                    default:
                        break;
                }
                ClientProxyCore.playerItemData.put(gearName, gearData);
            }
            break;
        case C_CLOSE_GUI:
            FMLClientHandler.instance().getClient().displayGuiScreen(null);
            break;
        case C_RESET_THIRD_PERSON:
            FMLClientHandler.instance().getClient().gameSettings.thirdPersonView = stats.getThirdPersonView();
            break;
        case C_UPDATE_SPACESTATION_LIST:
            WorldUtil.decodeSpaceStationListClient(data);
            break;
        case C_UPDATE_SPACESTATION_DATA:
            SpaceStationWorldData var4 = SpaceStationWorldData.getMPSpaceStationData(player.worldObj, (Integer) this.data.get(0), player);
            var4.readFromNBT((NBTTagCompound) this.data.get(1));
            break;
        case C_UPDATE_SPACESTATION_CLIENT_ID:
            ClientProxyCore.clientSpaceStationID = WorldUtil.stringToSpaceStationData((String) this.data.get(0));
            break;
        case C_UPDATE_PLANETS_LIST:
            WorldUtil.decodePlanetsListClient(data);
            break;
        case C_UPDATE_CONFIGS:
            ConfigManagerCore.saveClientConfigOverrideable();
            ConfigManagerCore.setConfigOverride(data);
            break;
        case C_ADD_NEW_SCHEMATIC:
            final ISchematicPage page = SchematicRegistry.getMatchingRecipeForID((Integer) this.data.get(0));
            if (!stats.getUnlockedSchematics().contains(page)) {
                stats.getUnlockedSchematics().add(page);
            }
            break;
        case C_UPDATE_SCHEMATIC_LIST:
            for (Object o : this.data) {
                Integer schematicID = (Integer) o;
                if (schematicID != -2) {
                    Collections.sort(stats.getUnlockedSchematics());
                    if (!stats.getUnlockedSchematics().contains(SchematicRegistry.getMatchingRecipeForID(schematicID))) {
                        stats.getUnlockedSchematics().add(SchematicRegistry.getMatchingRecipeForID(schematicID));
                    }
                }
            }
            break;
        case C_PLAY_SOUND_BOSS_DEATH:
            player.playSound(Constants.TEXTURE_PREFIX + "entity.bossdeath", 10.0F, (Float) this.data.get(0));
            break;
        case C_PLAY_SOUND_EXPLODE:
            player.playSound("random.explode", 10.0F, 0.7F);
            break;
        case C_PLAY_SOUND_BOSS_LAUGH:
            player.playSound(Constants.TEXTURE_PREFIX + "entity.bosslaugh", 10.0F, 1.1F);
            break;
        case C_PLAY_SOUND_BOW:
            player.playSound("random.bow", 10.0F, 0.2F);
            break;
        case C_UPDATE_OXYGEN_VALIDITY:
            stats.setOxygenSetupValid((Boolean) this.data.get(0));
            break;
        case C_OPEN_PARACHEST_GUI:
            switch((Integer) this.data.get(1)) {
                case 0:
                    if (player.ridingEntity instanceof EntityBuggy) {
                        FMLClientHandler.instance().getClient().displayGuiScreen(new GuiBuggy(player.inventory, (EntityBuggy) player.ridingEntity, ((EntityBuggy) player.ridingEntity).getType()));
                        player.openContainer.windowId = (Integer) this.data.get(0);
                    }
                    break;
                case 1:
                    int entityID = (Integer) this.data.get(2);
                    Entity entity = player.worldObj.getEntityByID(entityID);
                    if (entity != null && entity instanceof IInventorySettable) {
                        FMLClientHandler.instance().getClient().displayGuiScreen(new GuiParaChest(player.inventory, (IInventorySettable) entity));
                    }
                    player.openContainer.windowId = (Integer) this.data.get(0);
                    break;
            }
            break;
        case C_UPDATE_WIRE_BOUNDS:
            TileEntity tile = player.worldObj.getTileEntity((BlockPos) this.data.get(0));
            if (tile instanceof TileBaseConductor) {
                ((TileBaseConductor) tile).adjacentConnections = null;
                player.worldObj.getBlockState(tile.getPos()).getBlock().setBlockBoundsBasedOnState(player.worldObj, tile.getPos());
            }
            break;
        case C_OPEN_SPACE_RACE_GUI:
            if (Minecraft.getMinecraft().currentScreen == null) {
                TickHandlerClient.spaceRaceGuiScheduled = false;
                player.openGui(GalacticraftCore.instance, GuiIdsCore.SPACE_RACE_START, player.worldObj, (int) player.posX, (int) player.posY, (int) player.posZ);
            } else {
                TickHandlerClient.spaceRaceGuiScheduled = true;
            }
            break;
        case C_UPDATE_SPACE_RACE_DATA:
            Integer teamID = (Integer) this.data.get(0);
            String teamName = (String) this.data.get(1);
            FlagData flagData = (FlagData) this.data.get(2);
            Vector3 teamColor = (Vector3) this.data.get(3);
            List<String> playerList = new ArrayList<String>();
            for (int i = 4; i < this.data.size(); i++) {
                String playerName = (String) this.data.get(i);
                ClientProxyCore.flagRequestsSent.remove(playerName);
                playerList.add(playerName);
            }
            SpaceRace race = new SpaceRace(playerList, teamName, flagData, teamColor);
            race.setSpaceRaceID(teamID);
            SpaceRaceManager.addSpaceRace(race);
            break;
        case C_OPEN_JOIN_RACE_GUI:
            stats.setSpaceRaceInviteTeamID((Integer) this.data.get(0));
            player.openGui(GalacticraftCore.instance, GuiIdsCore.SPACE_RACE_JOIN, player.worldObj, (int) player.posX, (int) player.posY, (int) player.posZ);
            break;
        case C_UPDATE_DUNGEON_DIRECTION:
            stats.setDungeonDirection((Float) this.data.get(0));
            break;
        case C_UPDATE_FOOTPRINT_LIST:
            List<Footprint> printList = new ArrayList<Footprint>();
            long chunkKey = (Long) this.data.get(0);
            for (int i = 1; i < this.data.size(); i++) {
                Footprint print = (Footprint) this.data.get(i);
                if (!print.owner.equals(player.getName())) {
                    printList.add(print);
                }
            }
            FootprintRenderer.setFootprints(chunkKey, printList);
            break;
        case C_FOOTPRINTS_REMOVED:
            long chunkKey0 = (Long) this.data.get(0);
            BlockVec3 position = (BlockVec3) this.data.get(1);
            List<Footprint> footprintList = FootprintRenderer.footprints.get(chunkKey0);
            List<Footprint> toRemove = new ArrayList<Footprint>();
            if (footprintList != null) {
                for (Footprint footprint : footprintList) {
                    if (footprint.position.x > position.x && footprint.position.x < position.x + 1 && footprint.position.z > position.z && footprint.position.z < position.z + 1) {
                        toRemove.add(footprint);
                    }
                }
            }
            if (!toRemove.isEmpty()) {
                footprintList.removeAll(toRemove);
                FootprintRenderer.footprints.put(chunkKey0, footprintList);
            }
            break;
        case C_UPDATE_STATION_SPIN:
            if (playerBaseClient.worldObj.provider instanceof WorldProviderSpaceStation) {
                ((WorldProviderSpaceStation) playerBaseClient.worldObj.provider).getSpinManager().setSpinRate((Float) this.data.get(0), (Boolean) this.data.get(1));
            }
            break;
        case C_UPDATE_STATION_DATA:
            if (playerBaseClient.worldObj.provider instanceof WorldProviderSpaceStation) {
                ((WorldProviderSpaceStation) playerBaseClient.worldObj.provider).getSpinManager().setSpinCentre((Double) this.data.get(0), (Double) this.data.get(1));
            }
            break;
        case C_UPDATE_STATION_BOX:
            if (playerBaseClient.worldObj.provider instanceof WorldProviderSpaceStation) {
                ((WorldProviderSpaceStation) playerBaseClient.worldObj.provider).getSpinManager().setSpinBox((Integer) this.data.get(0), (Integer) this.data.get(1), (Integer) this.data.get(2), (Integer) this.data.get(3), (Integer) this.data.get(4), (Integer) this.data.get(5));
            }
            break;
        case C_UPDATE_THERMAL_LEVEL:
            stats.setThermalLevel((Integer) this.data.get(0));
            stats.setThermalLevelNormalising((Boolean) this.data.get(1));
            break;
        case C_DISPLAY_ROCKET_CONTROLS:
            player.addChatMessage(new ChatComponentText(GameSettings.getKeyDisplayString(KeyHandlerClient.spaceKey.getKeyCode()) + "  - " + GCCoreUtil.translate("gui.rocket.launch.name")));
            player.addChatMessage(new ChatComponentText(GameSettings.getKeyDisplayString(KeyHandlerClient.leftKey.getKeyCode()) + " / " + GameSettings.getKeyDisplayString(KeyHandlerClient.rightKey.getKeyCode()) + "  - " + GCCoreUtil.translate("gui.rocket.turn.name")));
            player.addChatMessage(new ChatComponentText(GameSettings.getKeyDisplayString(KeyHandlerClient.accelerateKey.getKeyCode()) + " / " + GameSettings.getKeyDisplayString(KeyHandlerClient.decelerateKey.getKeyCode()) + "  - " + GCCoreUtil.translate("gui.rocket.updown.name")));
            player.addChatMessage(new ChatComponentText(GameSettings.getKeyDisplayString(KeyHandlerClient.openFuelGui.getKeyCode()) + "       - " + GCCoreUtil.translate("gui.rocket.inv.name")));
            break;
        case C_GET_CELESTIAL_BODY_LIST:
            String str = "";
            for (CelestialBody cBody : GalaxyRegistry.getRegisteredPlanets().values()) {
                str = str.concat(cBody.getUnlocalizedName() + ";");
            }
            for (CelestialBody cBody : GalaxyRegistry.getRegisteredMoons().values()) {
                str = str.concat(cBody.getUnlocalizedName() + ";");
            }
            for (CelestialBody cBody : GalaxyRegistry.getRegisteredSatellites().values()) {
                str = str.concat(cBody.getUnlocalizedName() + ";");
            }
            for (SolarSystem solarSystem : GalaxyRegistry.getRegisteredSolarSystems().values()) {
                str = str.concat(solarSystem.getUnlocalizedName() + ";");
            }
            GalacticraftCore.packetPipeline.sendToServer(new PacketSimple(EnumSimplePacket.S_COMPLETE_CBODY_HANDSHAKE, getDimensionID(), new Object[] { str }));
            break;
        case C_UPDATE_ENERGYUNITS:
            CommandGCEnergyUnits.handleParamClientside((Integer) this.data.get(0));
            break;
        case C_RESPAWN_PLAYER:
            final WorldProvider provider = WorldUtil.getProviderForNameClient((String) this.data.get(0));
            final int dimID = GCCoreUtil.getDimensionID(provider);
            if (ConfigManagerCore.enableDebug) {
                GCLog.info("DEBUG: Client receiving respawn packet for dim " + dimID);
            }
            int par2 = (Integer) this.data.get(1);
            String par3 = (String) this.data.get(2);
            int par4 = (Integer) this.data.get(3);
            WorldUtil.forceRespawnClient(dimID, par2, par3, par4);
            break;
        case C_UPDATE_STATS:
            stats.setBuildFlags((Integer) this.data.get(0));
            BlockPanelLighting.updateClient(this.data);
            break;
        case C_UPDATE_TELEMETRY:
            tile = player.worldObj.getTileEntity((BlockPos) this.data.get(0));
            if (tile instanceof TileEntityTelemetry) {
                ((TileEntityTelemetry) tile).receiveUpdate(data, this.getDimensionID());
            }
            break;
        case C_SEND_PLAYERSKIN:
            String strName = (String) this.data.get(0);
            String s1 = (String) this.data.get(1);
            String s2 = (String) this.data.get(2);
            String strUUID = (String) this.data.get(3);
            GameProfile gp = PlayerUtil.getOtherPlayerProfile(strName);
            if (gp == null) {
                gp = PlayerUtil.makeOtherPlayerProfile(strName, strUUID);
            }
            gp.getProperties().put("textures", new Property("textures", s1, s2));
            break;
        case C_SEND_OVERWORLD_IMAGE:
            try {
                int cx = (Integer) this.data.get(0);
                int cz = (Integer) this.data.get(1);
                byte[] bytes = (byte[]) this.data.get(2);
                MapUtil.receiveOverworldImageCompressed(cx, cz, bytes);
            } catch (Exception e) {
                e.printStackTrace();
            }
            break;
        case C_RECOLOR_PIPE:
            TileEntity tileEntity = player.worldObj.getTileEntity((BlockPos) this.data.get(0));
            if (tileEntity instanceof TileEntityFluidPipe) {
                TileEntityFluidPipe pipe = (TileEntityFluidPipe) tileEntity;
                pipe.getNetwork().split(pipe);
                pipe.setNetwork(null);
            }
            break;
        case C_RECOLOR_ALL_GLASS:
            BlockSpaceGlass.updateGlassColors((Integer) this.data.get(0), (Integer) this.data.get(1), (Integer) this.data.get(2));
            break;
        case C_UPDATE_MACHINE_DATA:
            TileEntity tile3 = player.worldObj.getTileEntity((BlockPos) this.data.get(0));
            if (tile3 instanceof ITileClientUpdates) {
                ((ITileClientUpdates) tile3).updateClient(this.data);
            }
            break;
        case C_LEAK_DATA:
            TileEntity tile4 = player.worldObj.getTileEntity((BlockPos) this.data.get(0));
            if (tile4 instanceof TileEntityOxygenSealer) {
                ((ITileClientUpdates) tile4).updateClient(this.data);
            }
            break;
        case C_SPAWN_HANGING_SCHEMATIC:
            EntityHangingSchematic entity = new EntityHangingSchematic(player.worldObj, (BlockPos) this.data.get(0), EnumFacing.getFront((Integer) this.data.get(2)), (Integer) this.data.get(3));
            ((WorldClient) player.worldObj).addEntityToWorld((Integer) this.data.get(1), entity);
            break;
        default:
            break;
    }
}
Also used : IControllableEntity(micdoodle8.mods.galacticraft.core.entities.IControllableEntity) Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) TileBaseConductor(micdoodle8.mods.galacticraft.core.energy.tile.TileBaseConductor) SolarSystem(micdoodle8.mods.galacticraft.api.galaxies.SolarSystem) EntityBuggy(micdoodle8.mods.galacticraft.core.entities.EntityBuggy) WorldProvider(net.minecraft.world.WorldProvider) EntityFXSparks(micdoodle8.mods.galacticraft.core.client.fx.EntityFXSparks) EntityFX(net.minecraft.client.particle.EntityFX) Footprint(micdoodle8.mods.galacticraft.core.wrappers.Footprint) EnumExtendedInventorySlot(micdoodle8.mods.galacticraft.api.item.EnumExtendedInventorySlot) GuiParaChest(micdoodle8.mods.galacticraft.core.client.gui.container.GuiParaChest) WorldClient(net.minecraft.client.multiplayer.WorldClient) EntityHangingSchematic(micdoodle8.mods.galacticraft.core.entities.EntityHangingSchematic) GuiCelestialSelection(micdoodle8.mods.galacticraft.core.client.gui.screen.GuiCelestialSelection) GameProfile(com.mojang.authlib.GameProfile) EntityPlayer(net.minecraft.entity.player.EntityPlayer) GuiBuggy(micdoodle8.mods.galacticraft.core.client.gui.container.GuiBuggy) SpaceRace(micdoodle8.mods.galacticraft.core.dimension.SpaceRace) ITileClientUpdates(micdoodle8.mods.galacticraft.api.tile.ITileClientUpdates) Satellite(micdoodle8.mods.galacticraft.api.galaxies.Satellite) TileEntity(net.minecraft.tileentity.TileEntity) FlagData(micdoodle8.mods.galacticraft.core.wrappers.FlagData) WorldProviderSpaceStation(micdoodle8.mods.galacticraft.core.dimension.WorldProviderSpaceStation) CelestialBody(micdoodle8.mods.galacticraft.api.galaxies.CelestialBody) PlayerGearData(micdoodle8.mods.galacticraft.core.wrappers.PlayerGearData) EnumModelPacketType(micdoodle8.mods.galacticraft.core.entities.player.GCPlayerHandler.EnumModelPacketType) Property(com.mojang.authlib.properties.Property) BlockVec3(micdoodle8.mods.galacticraft.api.vector.BlockVec3) SpaceStationWorldData(micdoodle8.mods.galacticraft.core.dimension.SpaceStationWorldData) IInventorySettable(micdoodle8.mods.galacticraft.core.inventory.IInventorySettable) Vector3(micdoodle8.mods.galacticraft.api.vector.Vector3) Minecraft(net.minecraft.client.Minecraft) Footprint(micdoodle8.mods.galacticraft.core.wrappers.Footprint) IOException(java.io.IOException) ISchematicPage(micdoodle8.mods.galacticraft.api.recipe.ISchematicPage) EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 4 with EntityHangingSchematic

use of micdoodle8.mods.galacticraft.core.entities.EntityHangingSchematic in project Galacticraft by micdoodle8.

the class BaseRoom method buildRoomContents.

/**
 * Room contents boundaries are:
 *    x from 1 to maxX
 *    y from 1 to this.sizeY - 1
 *    z from 1 to maxZ
 */
private void buildRoomContents(World worldIn, int x, int y, int z, int maxX, int maxZ, BlockPos blockpos, int randomInt) {
    IBlockState state = Blocks.air.getDefaultState();
    int semirand = ((blockpos.getY() * 379 + blockpos.getX()) * 373 + blockpos.getZ()) * 7 & 15;
    int facing = 0;
    int facing1 = 0;
    int facing2 = 0;
    int facingLamp = 2;
    int facingScreen = 2;
    switch(this.direction) {
        case WEST:
            facing1 = 3;
            facing2 = 2;
            facingLamp = 3;
            facingScreen = 5;
            break;
        case EAST:
            facing = 2;
            facing1 = 1;
            facing2 = 0;
            facingLamp = 2;
            facingScreen = 4;
            break;
        case NORTH:
            facing = 3;
            facing1 = 2;
            facing2 = 1;
            facingLamp = 5;
            facingScreen = 2;
            break;
        case SOUTH:
            facing = 1;
            facing1 = 0;
            facing2 = 3;
            facingLamp = 4;
            facingScreen = 3;
    }
    // Offset from centre - used for some rooms
    int ox = maxX / 2 - 3;
    int xx = x - ox;
    switch(this.type) {
        case EMPTY:
            // Pillars in corners
            if ((z == 1 || z == maxZ - 1) && (x == 2 || x == maxX - 1)) {
                state = GCBlocks.wallGC.getStateFromMeta(2);
            } else if (y == 1) {
                // Some random Netherwart
                if (semirand < 2) {
                    state = AsteroidBlocks.spaceWart.getStateFromMeta(semirand);
                }
            }
            break;
        case STORE:
            if (maxX >= 6 && y == 1 && maxZ >= 5) {
                // An actual landing pad (indoors!)
                if (xx >= 3 && xx <= 5 && z >= 2 && z <= 4) {
                    state = GCBlocks.landingPad.getDefaultState();
                } else if (xx == 2) {
                    // Cargo loaders and unloaders, these will contain treasure items but only accessible when powered
                    switch(z) {
                        case 2:
                            state = GCBlocks.cargoLoader.getStateFromMeta(facing);
                            break;
                        case 3:
                            state = GCBlocks.aluminumWire.getStateFromMeta(1);
                            break;
                        case 4:
                            state = GCBlocks.cargoLoader.getStateFromMeta(4 + (facing ^ 2));
                            break;
                        default:
                    }
                }
            }
            break;
        case POWER:
            facing = (facing + 1) % 4;
            switch(y) {
                case 1:
                    // Layer 1: wall blocks with sealable alu wire in the centre
                    if (z == 3 && xx >= 4 && x <= maxX - 2)
                        state = GCBlocks.sealableBlock.getStateFromMeta(14);
                    else if (xx >= 3 && z > 1 && (z < maxZ - 1 || z == 4))
                        state = this.configuration.getWallBlock();
                    break;
                case 2:
                    // Layer 2: tier 1 storage and alu wire and a switch
                    if (z == 2) {
                        if (xx == 3)
                            state = GCBlocks.machineTiered.getStateFromMeta(0 + facing);
                        else if (xx > 3 && x < maxX - 2)
                            state = GCBlocks.aluminumWire.getStateFromMeta(0);
                        else if (x == maxX - 2)
                            state = GCBlocks.aluminumWire.getStateFromMeta(2);
                        else if ((xx == 3 || x == maxX - 1))
                            state = AsteroidBlocks.blockMinerBase.getDefaultState();
                    } else if (z == 3 && x == maxX - 2)
                        state = GCBlocks.aluminumWire.getStateFromMeta(0);
                    else // An industrial looking frame for the whole structure
                    if (z == 4 && (xx == 3 || x == maxX - 1))
                        state = AsteroidBlocks.blockMinerBase.getDefaultState();
                    break;
                case 3:
                    // Layer 3: tier 2 storage and alu wire
                    if (z == 2 && xx == 4)
                        state = GCBlocks.aluminumWire.getStateFromMeta(0);
                    else if (z == 3 && x == maxX - 2)
                        state = GCBlocks.machineTiered.getStateFromMeta(8 + (facing ^ 2));
                    else if (z == 3 && x == maxX - 1)
                        state = GCBlocks.aluminumWire.getStateFromMeta(1);
                    else if (z == 3 && xx >= 4 && x < maxX - 2)
                        state = GCBlocks.aluminumWire.getStateFromMeta(0);
                    else // An industrial looking frame for the whole structure
                    if ((z == 2 || z == 4) && (xx == 3 || x == maxX - 1))
                        state = AsteroidBlocks.blockMinerBase.getDefaultState();
                    break;
                case 4:
                    // Layer 4: tier 2 storage and alu wire
                    if (z == 3) {
                        if (x == maxX - 3)
                            state = GCBlocks.machineTiered.getStateFromMeta(8 + facing);
                        else if (x == maxX - 1 || x == maxX - 2)
                            state = GCBlocks.aluminumWire.getStateFromMeta(1);
                    } else // An industrial looking frame for the whole structure
                    if ((z == 2 || z == 4) && xx >= 3 && x < maxX)
                        state = AsteroidBlocks.blockMinerBase.getDefaultState();
                    break;
            }
            break;
        case ENGINEERING:
            if (y == 1) {
                int closerz = (maxZ <= 5) ? 2 : 3;
                if ((z == maxZ - 2 && x == maxX / 2 + 1 || (z == closerz && (x == 2 || x == maxX - 1) && maxX > 5)) && maxZ > 3) {
                    state = GCBlocks.nasaWorkbench.getDefaultState();
                } else {
                    state = AsteroidBlocks.blockBasic.getStateFromMeta(6);
                }
            }
            break;
        case MEDICAL:
            int zTable = maxZ - 3;
            int zTank = maxZ - 1;
            int zLight = zTable;
            if (zTable <= 1) {
                if (zTable < 0) {
                    // Too small to build the room
                    break;
                }
                // Small medical room: bring everything closer together
                zTable++;
                zLight++;
                zTank = maxZ;
            }
            if (y == 1) {
                // Operating table at y == 1
                if (z == zTable && x <= maxX - 1 && x >= maxX - 3) {
                    state = GCBlocks.crafting.getStateFromMeta(1);
                } else
                    // Tiled floor
                    state = Blocks.iron_trapdoor.getDefaultState();
            } else if (y == 2 || y == 3) {
                // Operating table at y == 2
                if (y == 2 && z == zTable && x <= maxX - 1 && x >= maxX - 3) {
                    state = GCBlocks.landingPad.getDefaultState();
                } else if (z == zTank) {
                    // Fluid tanks, 2 tanks high - these will be filled with Bacterial Sludge below
                    if ((maxX - x) % 2 == 1) {
                        state = GCBlocks.fluidTank.getDefaultState();
                    }
                }
            } else if ((y == 4 || y == 5) && (z == zLight || z == zLight - 1)) {
                // Lighting
                if (x == maxX)
                    state = GCBlocks.concealedDetector.getStateFromMeta(8 + facing + (this.configuration.getDeckType() == EnumBaseType.HUMANOID ? 0 : 4));
                else if (x == maxX - 1)
                    state = GCBlocks.brightLamp.getStateFromMeta(facingLamp);
            }
            break;
        case CREW:
            if (y == 1) {
                if (x == 2 || x == maxX - 1) {
                    if ((z % 2) == 1) {
                        state = GCBlocks.wallGC.getStateFromMeta((z == 1) ? 3 : 2);
                    }
                } else {
                    state = Blocks.carpet.getStateFromMeta(7);
                }
            } else if (y == 2) {
                if (x == 2 || x == maxX - 1) {
                    if (z == 1) {
                        state = Blocks.brewing_stand.getDefaultState();
                    } else if (z > 2 && z < maxZ) {
                        state = GCBlocks.landingPad.getStateFromMeta(1);
                    }
                }
            }
            break;
        case CONTROL:
            if (y == 1) {
                if (x == maxX / 2 + 1 && z == maxZ - 2) {
                    state = AsteroidBlocks.blockBasic.getStateFromMeta(6);
                } else {
                    state = GCBlocks.slabGCHalf.getStateFromMeta(6);
                }
            } else if (y <= 3) {
                if ((x == 1 || x == maxX) && !(z == 0 || z == maxZ)) {
                    state = GCBlocks.telemetry.getDefaultState();
                } else if ((x == 2 || x == maxX - 1) && !(z == 0 || z == maxZ)) {
                    state = GCBlocks.screen.getStateFromMeta((x == 2 ? facingLamp : facingLamp ^ 1));
                } else if (z == maxZ && x > 2 && x < maxX - 1) {
                    state = GCBlocks.screen.getStateFromMeta(facingScreen);
                } else if (x == maxX / 2 + 1 && z == maxZ - 2 && y == 2) {
                    state = GCBlocks.landingPad.getStateFromMeta(1);
                }
            }
            break;
        case CRYO:
            boolean xEntrance = maxX > 5 ? (x > 2 && x < maxX - 1) : (x > 1 && x < maxX);
            boolean highEntrance = this.configuration.isHangarDeck() && this.configuration.getDeckType() == EnumBaseType.AVIAN;
            if (y == 1) {
                // Build a dark plinth for it all at y == 1
                if (z == 1 && x > 1 && x < maxX) {
                    state = GCBlocks.slabGCHalf.getStateFromMeta(6);
                } else if (z != 0 || !xEntrance || highEntrance) {
                    state = AsteroidBlocks.blockBasic.getStateFromMeta(6);
                }
            } else if (z == 0 && (y > (highEntrance ? 5 : 3) || !xEntrance)) {
                // Dark ceiling and entrance wall
                state = AsteroidBlocks.blockBasic.getStateFromMeta(6);
            } else if (y <= 4 && (z == maxZ || x == 1 || x == maxX)) {
                // Around the walls: Cryo Chambers alternated with dark blocks
                if (z == maxZ && x % 2 == 0 && x < maxX) {
                    if (y == 2) {
                        state = MarsBlocks.machine.getStateFromMeta(BlockMachineMars.CRYOGENIC_CHAMBER_METADATA + facing1);
                    }
                } else if (z < maxZ && z > 1 && (maxZ - z) % 2 == 0) {
                    if (y == 2) {
                        state = MarsBlocks.machine.getStateFromMeta(BlockMachineMars.CRYOGENIC_CHAMBER_METADATA + (x == 1 ? facing : facing2));
                    }
                } else {
                    state = AsteroidBlocks.blockBasic.getStateFromMeta(6);
                }
            } else if (y > 5 || y == this.configuration.getRoomHeight() || (z == maxZ || x == 1 || x == maxX)) {
                // Dark top section of walls and ceiling
                state = AsteroidBlocks.blockBasic.getStateFromMeta(6);
            }
            break;
        default:
    }
    worldIn.setBlockState(blockpos, state, 2);
    if (state.getBlock() instanceof ITileEntityProvider) {
        TileEntity tile = worldIn.getTileEntity(blockpos);
        if (tile instanceof IMultiBlock) {
            List<BlockPos> positions = new LinkedList<>();
            ((IMultiBlock) tile).getPositions(blockpos, positions);
            for (BlockPos pos : positions) {
                worldIn.setBlockState(pos, GCBlocks.fakeBlock.getDefaultState().withProperty(BlockMulti.MULTI_TYPE, ((IMultiBlock) tile).getMultiType()), 2);
            }
        }
        if (tile instanceof TileEntityFluidTank) {
            ((TileEntityFluidTank) tile).fill(null, new FluidStack(MarsModule.sludge, 16000), true);
        } else if (tile instanceof TileEntityCargoLoader) {
            TileEntityCargoLoader loader = (TileEntityCargoLoader) tile;
            loader.locked = true;
            // Looks like the food supplies have gone off!
            loader.addCargo(new ItemStack(Items.poisonous_potato, 64, 0), true);
            loader.addCargo(new ItemStack(Items.poisonous_potato, 64, 0), true);
            loader.addCargo(new ItemStack(Items.poisonous_potato, 64, 0), true);
            loader.addCargo(new ItemStack(Items.poisonous_potato, 64, 0), true);
            loader.addCargo(new ItemStack(Items.rotten_flesh, 64, 0), true);
            loader.addCargo(new ItemStack(GCItems.flagPole, semirand % 31 + 2, 0), true);
            // Slimeling Inventory Bag
            loader.addCargo(new ItemStack(MarsItems.marsItemBasic, semirand % 2 + 1, 4), true);
            // Thermal cloth
            loader.addCargo(new ItemStack(AsteroidsItems.basicItem, semirand % 23 + 41, 7), true);
            loader.addCargo(new ItemStack(GCItems.oilCanister, 1, ItemCanisterGeneric.EMPTY), true);
            loader.addCargo(new ItemStack(GCItems.oilCanister, 1, ItemCanisterGeneric.EMPTY), true);
            loader.addCargo(new ItemStack(GCItems.oilCanister, 1, ItemCanisterGeneric.EMPTY), true);
            loader.addCargo(new ItemStack(GCItems.oilCanister, 1, ItemCanisterGeneric.EMPTY), true);
            loader.addCargo(new ItemStack(GCItems.oilCanister, 1, ItemCanisterGeneric.EMPTY), true);
            loader.addCargo(this.configuration.getDeckType().treasure.copy(), true);
        } else if (tile instanceof TileEntityCrafting) {
            switch(semirand % 4) {
                case 0:
                    break;
                case 1:
                    ((TileEntityCrafting) tile).craftMatrix.setInventorySlotContents(1, new ItemStack(Items.iron_ingot));
                    ((TileEntityCrafting) tile).craftMatrix.setInventorySlotContents(3, new ItemStack(Items.iron_ingot));
                    break;
                case 2:
                    // Creeper or Zombie head
                    int slot = semirand % 9;
                    ((TileEntityCrafting) tile).craftMatrix.setInventorySlotContents(slot, new ItemStack(Items.skull, 1, (semirand % 13 < 6) ? 4 : 2));
                    break;
                case 3:
                    ((TileEntityCrafting) tile).craftMatrix.setInventorySlotContents(0, new ItemStack(Items.iron_ingot));
                    ((TileEntityCrafting) tile).craftMatrix.setInventorySlotContents(1, new ItemStack(Items.iron_ingot));
                    ((TileEntityCrafting) tile).craftMatrix.setInventorySlotContents(3, new ItemStack(Items.iron_ingot));
                    ((TileEntityCrafting) tile).craftMatrix.setInventorySlotContents(4, new ItemStack(Items.stick));
                    ((TileEntityCrafting) tile).craftMatrix.setInventorySlotContents(7, new ItemStack(Items.stick));
                    break;
            }
        } else if (tile instanceof TileEntityBrewingStand) {
            TileEntityBrewingStand stand = (TileEntityBrewingStand) tile;
            // Poison
            stand.setInventorySlotContents(0, new ItemStack(Items.potionitem, 1, 8196));
            // Weakness
            stand.setInventorySlotContents(1, new ItemStack(Items.potionitem, 1, 8200));
            // Harming
            stand.setInventorySlotContents(2, new ItemStack(Items.potionitem, 1, 8204));
        } else if (tile instanceof TileEntityEnergyStorageModule) {
            TileEntityEnergyStorageModule store = (TileEntityEnergyStorageModule) tile;
            if (semirand % 3 == 1) {
                store.setInventorySlotContents(1, new ItemStack(GCItems.battery, 1, 100));
            }
        }
    }
    if (this.type == EnumRoomType.ENGINEERING && y == (this.configuration.getRoomHeight() <= 4 ? 2 : 3) && z == maxZ && (x == 3 || x == 6)) {
        EnumFacing hangingDirection = this.direction;
        if (hangingDirection == EnumFacing.WEST || hangingDirection == EnumFacing.EAST) {
            // Apparently we have our North and our South reversed ?  So we don't want the opposite for North and South!
            hangingDirection = hangingDirection.getOpposite();
        }
        EntityHangingSchematic entityhanging = new EntityHangingSchematic(worldIn, blockpos, hangingDirection, x / 3 - 1);
        if (entityhanging != null) {
            worldIn.spawnEntityInWorld(entityhanging);
            entityhanging.setSendToClient();
        }
    }
}
Also used : TileEntityCrafting(micdoodle8.mods.galacticraft.core.tile.TileEntityCrafting) TileEntityCargoLoader(micdoodle8.mods.galacticraft.core.tile.TileEntityCargoLoader) IBlockState(net.minecraft.block.state.IBlockState) TileEntityEnergyStorageModule(micdoodle8.mods.galacticraft.core.tile.TileEntityEnergyStorageModule) FluidStack(net.minecraftforge.fluids.FluidStack) EnumFacing(net.minecraft.util.EnumFacing) LinkedList(java.util.LinkedList) TileEntity(net.minecraft.tileentity.TileEntity) EntityHangingSchematic(micdoodle8.mods.galacticraft.core.entities.EntityHangingSchematic) ITileEntityProvider(net.minecraft.block.ITileEntityProvider) IMultiBlock(micdoodle8.mods.galacticraft.core.tile.IMultiBlock) TileEntityBrewingStand(net.minecraft.tileentity.TileEntityBrewingStand) TileEntityFluidTank(micdoodle8.mods.galacticraft.core.tile.TileEntityFluidTank) BlockPos(net.minecraft.util.BlockPos) ItemStack(net.minecraft.item.ItemStack)

Aggregations

EntityHangingSchematic (micdoodle8.mods.galacticraft.core.entities.EntityHangingSchematic)4 ItemStack (net.minecraft.item.ItemStack)3 TileEntity (net.minecraft.tileentity.TileEntity)2 GameProfile (com.mojang.authlib.GameProfile)1 Property (com.mojang.authlib.properties.Property)1 IOException (java.io.IOException)1 LinkedList (java.util.LinkedList)1 CelestialBody (micdoodle8.mods.galacticraft.api.galaxies.CelestialBody)1 Satellite (micdoodle8.mods.galacticraft.api.galaxies.Satellite)1 SolarSystem (micdoodle8.mods.galacticraft.api.galaxies.SolarSystem)1 EnumExtendedInventorySlot (micdoodle8.mods.galacticraft.api.item.EnumExtendedInventorySlot)1 ISchematicPage (micdoodle8.mods.galacticraft.api.recipe.ISchematicPage)1 ITileClientUpdates (micdoodle8.mods.galacticraft.api.tile.ITileClientUpdates)1 BlockVec3 (micdoodle8.mods.galacticraft.api.vector.BlockVec3)1 Vector3 (micdoodle8.mods.galacticraft.api.vector.Vector3)1 EntityFXSparks (micdoodle8.mods.galacticraft.core.client.fx.EntityFXSparks)1 GuiBuggy (micdoodle8.mods.galacticraft.core.client.gui.container.GuiBuggy)1 GuiParaChest (micdoodle8.mods.galacticraft.core.client.gui.container.GuiParaChest)1 GuiCelestialSelection (micdoodle8.mods.galacticraft.core.client.gui.screen.GuiCelestialSelection)1 SpaceRace (micdoodle8.mods.galacticraft.core.dimension.SpaceRace)1