Search in sources :

Example 1 with TileEntityShortRangeTelepad

use of micdoodle8.mods.galacticraft.planets.asteroids.tile.TileEntityShortRangeTelepad in project Galacticraft by micdoodle8.

the class PacketSimpleAsteroids method handleServerSide.

@Override
public void handleServerSide(EntityPlayer player) {
    EntityPlayerMP playerBase = PlayerUtil.getPlayerBaseServerFromPlayer(player, false);
    switch(this.type) {
        case S_UPDATE_ADVANCED_GUI:
            TileEntity tile = player.worldObj.getTileEntity((BlockPos) this.data.get(1));
            switch((Integer) this.data.get(0)) {
                case 0:
                    if (tile instanceof TileEntityShortRangeTelepad) {
                        TileEntityShortRangeTelepad launchController = (TileEntityShortRangeTelepad) tile;
                        launchController.setAddress((Integer) this.data.get(2));
                    }
                    break;
                case 1:
                    if (tile instanceof TileEntityShortRangeTelepad) {
                        TileEntityShortRangeTelepad launchController = (TileEntityShortRangeTelepad) tile;
                        launchController.setTargetAddress((Integer) this.data.get(2));
                    }
                    break;
                default:
                    break;
            }
            break;
        default:
            break;
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityShortRangeTelepad(micdoodle8.mods.galacticraft.planets.asteroids.tile.TileEntityShortRangeTelepad) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP)

Example 2 with TileEntityShortRangeTelepad

use of micdoodle8.mods.galacticraft.planets.asteroids.tile.TileEntityShortRangeTelepad in project Galacticraft by micdoodle8.

the class TileEntityShortRangeTelepad method update.

@Override
public void update() {
    if (this.ticks % 40 == 0 && !worldObj.isRemote) {
        this.setAddress(this.address);
        this.setTargetAddress(this.targetAddress);
    }
    if (!this.worldObj.isRemote) {
        if (this.targetAddressResult == EnumTelepadSearchResult.VALID && (this.ticks % 5 == 0 || teleporting)) {
            List containedEntities = worldObj.getEntitiesWithinAABB(EntityLivingBase.class, AxisAlignedBB.fromBounds(this.getPos().getX(), this.getPos().getY(), this.getPos().getZ(), this.getPos().getX() + 1, this.getPos().getY() + 2, this.getPos().getZ() + 1));
            if (containedEntities.size() > 0 && this.getEnergyStoredGC() >= ENERGY_USE_ON_TELEPORT) {
                ShortRangeTelepadHandler.TelepadEntry entry = ShortRangeTelepadHandler.getLocationFromAddress(this.targetAddress);
                if (entry != null) {
                    teleporting = true;
                }
            } else {
                teleporting = false;
            }
        }
        if (this.teleporting) {
            this.teleportTime++;
            if (teleportTime >= MAX_TELEPORT_TIME) {
                ShortRangeTelepadHandler.TelepadEntry entry = ShortRangeTelepadHandler.getLocationFromAddress(this.targetAddress);
                BlockVec3 finalPos = (entry == null) ? null : entry.position;
                if (finalPos != null) {
                    TileEntity tileAt = finalPos.getTileEntity(this.worldObj);
                    List<EntityLivingBase> containedEntities = worldObj.getEntitiesWithinAABB(EntityLivingBase.class, AxisAlignedBB.fromBounds(this.getPos().getX(), this.getPos().getY(), this.getPos().getZ(), this.getPos().getX() + 1, this.getPos().getY() + 2, this.getPos().getZ() + 1));
                    if (tileAt != null && tileAt instanceof TileEntityShortRangeTelepad) {
                        TileEntityShortRangeTelepad destTelepad = (TileEntityShortRangeTelepad) tileAt;
                        int teleportResult = destTelepad.canTeleportHere();
                        if (teleportResult == 0) {
                            for (EntityLivingBase e : containedEntities) {
                                e.setPosition(finalPos.x + 0.5F, finalPos.y + 1.0F, finalPos.z + 0.5F);
                                this.worldObj.updateEntityWithOptionalForce(e, true);
                                if (e instanceof EntityPlayerMP) {
                                    ((EntityPlayerMP) e).playerNetServerHandler.setPlayerLocation(finalPos.x, finalPos.y, finalPos.z, e.rotationYaw, e.rotationPitch);
                                }
                                GalacticraftCore.packetPipeline.sendToDimension(new PacketSimpleAsteroids(PacketSimpleAsteroids.EnumSimplePacketAsteroids.C_TELEPAD_SEND, GCCoreUtil.getDimensionID(this.worldObj), new Object[] { finalPos, e.getEntityId() }), GCCoreUtil.getDimensionID(this.worldObj));
                            }
                            if (containedEntities.size() > 0) {
                                this.storage.setEnergyStored(this.storage.getEnergyStoredGC() - ENERGY_USE_ON_TELEPORT);
                                destTelepad.storage.setEnergyStored(this.storage.getEnergyStoredGC() - ENERGY_USE_ON_TELEPORT);
                            }
                        } else {
                            switch(teleportResult) {
                                case -1:
                                    for (EntityLivingBase e : containedEntities) {
                                        if (e instanceof EntityPlayer) {
                                            // No need for translation, since this should never happen
                                            ((EntityPlayer) e).addChatComponentMessage(new ChatComponentText("Cannot Send client-side"));
                                        }
                                    }
                                    break;
                                case 1:
                                    for (EntityLivingBase e : containedEntities) {
                                        if (e instanceof EntityPlayer) {
                                            // No need for translation, since this should never happen
                                            ((EntityPlayer) e).addChatComponentMessage(new ChatComponentText("Target address invalid"));
                                        }
                                    }
                                    break;
                                case 2:
                                    for (EntityLivingBase e : containedEntities) {
                                        if (e instanceof EntityPlayer) {
                                            ((EntityPlayer) e).addChatComponentMessage(new ChatComponentText(GCCoreUtil.translate("gui.message.target_no_energy.name")));
                                        }
                                    }
                                    break;
                            }
                        }
                    }
                }
                this.teleportTime = 0;
                this.teleporting = false;
            }
        } else {
            this.teleportTime = Math.max(--this.teleportTime, 0);
        }
    }
    super.update();
}
Also used : PacketSimpleAsteroids(micdoodle8.mods.galacticraft.planets.asteroids.network.PacketSimpleAsteroids) TileEntity(net.minecraft.tileentity.TileEntity) EntityLivingBase(net.minecraft.entity.EntityLivingBase) ShortRangeTelepadHandler(micdoodle8.mods.galacticraft.planets.asteroids.dimension.ShortRangeTelepadHandler) EntityPlayer(net.minecraft.entity.player.EntityPlayer) NBTTagList(net.minecraft.nbt.NBTTagList) LinkedList(java.util.LinkedList) List(java.util.List) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) BlockVec3(micdoodle8.mods.galacticraft.api.vector.BlockVec3)

Example 3 with TileEntityShortRangeTelepad

use of micdoodle8.mods.galacticraft.planets.asteroids.tile.TileEntityShortRangeTelepad in project Galacticraft by micdoodle8.

the class ShortRangeTelepadHandler method addShortRangeTelepad.

public static void addShortRangeTelepad(TileEntityShortRangeTelepad telepad) {
    if (!telepad.getWorld().isRemote) {
        if (telepad.addressValid) {
            TelepadEntry newEntry = new TelepadEntry(GCCoreUtil.getDimensionID(telepad.getWorld()), new BlockVec3(telepad));
            TelepadEntry previous = tileMap.put(telepad.address, newEntry);
            if (previous == null || !previous.equals(newEntry)) {
                AsteroidsTickHandlerServer.spaceRaceData.setDirty(true);
            }
        }
    }
}
Also used : BlockVec3(micdoodle8.mods.galacticraft.api.vector.BlockVec3)

Example 4 with TileEntityShortRangeTelepad

use of micdoodle8.mods.galacticraft.planets.asteroids.tile.TileEntityShortRangeTelepad in project Galacticraft by micdoodle8.

the class EntityFXTeleport method onUpdate.

@Override
public void onUpdate() {
    TileEntityShortRangeTelepad telepad1 = this.telepad.get();
    if (telepad1 != null) {
        Vector3 color = telepad1.getParticleColor(this.rand, this.direction);
        this.particleRed = color.floatX();
        this.particleGreen = color.floatY();
        this.particleBlue = color.floatZ();
    }
    this.prevPosX = this.posX;
    this.prevPosY = this.posY;
    this.prevPosZ = this.posZ;
    float f = (float) this.particleAge / (float) this.particleMaxAge;
    float f1 = f;
    f = -f + f * f * 2.0F;
    f = 1.0F - f;
    this.posX = this.portalPosX + this.motionX * f;
    this.posY = this.portalPosY + this.motionY * f + (1.0F - f1);
    this.posZ = this.portalPosZ + this.motionZ * f;
    if (this.particleAge++ >= this.particleMaxAge) {
        this.setDead();
    }
}
Also used : TileEntityShortRangeTelepad(micdoodle8.mods.galacticraft.planets.asteroids.tile.TileEntityShortRangeTelepad) Vector3(micdoodle8.mods.galacticraft.api.vector.Vector3)

Example 5 with TileEntityShortRangeTelepad

use of micdoodle8.mods.galacticraft.planets.asteroids.tile.TileEntityShortRangeTelepad in project Galacticraft by micdoodle8.

the class AsteroidsModuleClient method spawnParticle.

@Override
public void spawnParticle(String particleID, Vector3 position, Vector3 motion, Object... extraData) {
    Minecraft mc = FMLClientHandler.instance().getClient();
    if (mc != null && mc.getRenderViewEntity() != null && mc.effectRenderer != null) {
        double dX = mc.getRenderViewEntity().posX - position.x;
        double dY = mc.getRenderViewEntity().posY - position.y;
        double dZ = mc.getRenderViewEntity().posZ - position.z;
        EntityFX particle = null;
        double viewDistance = 64.0D;
        if (dX * dX + dY * dY + dZ * dZ < viewDistance * viewDistance) {
            if (particleID.equals("portalBlue")) {
                particle = new EntityFXTeleport(mc.theWorld, position, motion, (TileEntityShortRangeTelepad) extraData[0], (Boolean) extraData[1]);
            } else if (particleID.equals("cryoFreeze")) {
                particle = new EntityCryoFX(mc.theWorld, position, motion);
            }
        }
        if (particle != null) {
            particle.prevPosX = particle.posX;
            particle.prevPosY = particle.posY;
            particle.prevPosZ = particle.posZ;
            mc.effectRenderer.addEffect(particle);
        }
    }
}
Also used : TileEntityShortRangeTelepad(micdoodle8.mods.galacticraft.planets.asteroids.tile.TileEntityShortRangeTelepad) EntityCryoFX(micdoodle8.mods.galacticraft.planets.mars.client.fx.EntityCryoFX) EntityFX(net.minecraft.client.particle.EntityFX) Minecraft(net.minecraft.client.Minecraft) EntityFXTeleport(micdoodle8.mods.galacticraft.planets.asteroids.client.fx.EntityFXTeleport)

Aggregations

TileEntityShortRangeTelepad (micdoodle8.mods.galacticraft.planets.asteroids.tile.TileEntityShortRangeTelepad)6 TileEntity (net.minecraft.tileentity.TileEntity)5 BlockVec3 (micdoodle8.mods.galacticraft.api.vector.BlockVec3)2 Vector3 (micdoodle8.mods.galacticraft.api.vector.Vector3)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)2 LinkedList (java.util.LinkedList)1 List (java.util.List)1 ISortableBlock (micdoodle8.mods.galacticraft.core.blocks.ISortableBlock)1 IMultiBlock (micdoodle8.mods.galacticraft.core.tile.IMultiBlock)1 EnumSortCategoryBlock (micdoodle8.mods.galacticraft.core.util.EnumSortCategoryBlock)1 EntityFXTeleport (micdoodle8.mods.galacticraft.planets.asteroids.client.fx.EntityFXTeleport)1 ShortRangeTelepadHandler (micdoodle8.mods.galacticraft.planets.asteroids.dimension.ShortRangeTelepadHandler)1 PacketSimpleAsteroids (micdoodle8.mods.galacticraft.planets.asteroids.network.PacketSimpleAsteroids)1 EntityCryoFX (micdoodle8.mods.galacticraft.planets.mars.client.fx.EntityCryoFX)1 Block (net.minecraft.block.Block)1 Minecraft (net.minecraft.client.Minecraft)1 EntityFX (net.minecraft.client.particle.EntityFX)1 EntityLivingBase (net.minecraft.entity.EntityLivingBase)1 ItemStack (net.minecraft.item.ItemStack)1