Search in sources :

Example 1 with ItemTelepositionFocus

use of WayofTime.bloodmagic.item.ItemTelepositionFocus in project BloodMagic by WayofTime.

the class DataProviderTeleposer method getNBTData.

@Override
public NBTTagCompound getNBTData(EntityPlayerMP player, TileEntity te, NBTTagCompound tag, World world, BlockPos pos) {
    TileTeleposer teleposer = (TileTeleposer) te;
    ItemStack contained = teleposer.getStackInSlot(0);
    if (!contained.isEmpty() && contained.hasTagCompound()) {
        ItemTelepositionFocus focus = (ItemTelepositionFocus) contained.getItem();
        NBTTagCompound focusData = new NBTTagCompound();
        focusData.setTag("pos", NBTUtil.createPosTag(focus.getBlockPos(contained)));
        focusData.setInteger("dim", contained.getTagCompound().getInteger(Constants.NBT.DIMENSION_ID));
        tag.setTag("focus", focusData);
    }
    return tag;
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack) TileTeleposer(WayofTime.bloodmagic.tile.TileTeleposer) ItemTelepositionFocus(WayofTime.bloodmagic.item.ItemTelepositionFocus)

Example 2 with ItemTelepositionFocus

use of WayofTime.bloodmagic.item.ItemTelepositionFocus in project BloodMagic by WayofTime.

the class TileTeleposer method initiateTeleport.

public void initiateTeleport() {
    if (!getWorld().isRemote && canInitiateTeleport() && getBlockType() instanceof BlockTeleposer) {
        ItemStack focusStack = getStackInSlot(0);
        ItemTelepositionFocus focus = (ItemTelepositionFocus) focusStack.getItem();
        Binding binding = focus.getBinding(focusStack);
        if (binding == null)
            return;
        BlockPos focusPos = focus.getBlockPos(getStackInSlot(0));
        World focusWorld = focus.getWorld(getStackInSlot(0));
        if (focusWorld == null)
            return;
        TileEntity boundTile = focusWorld.getTileEntity(focusPos);
        if (boundTile instanceof TileTeleposer && boundTile != this) {
            final int focusLevel = (getStackInSlot(0).getItemDamage() + 1);
            final int lpToBeDrained = (int) (0.5F * Math.sqrt((pos.getX() - focusPos.getX()) * (pos.getX() - focusPos.getX()) + (pos.getY() - focusPos.getY() + 1) * (pos.getY() - focusPos.getY() + 1) + (pos.getZ() - focusPos.getZ()) * (pos.getZ() - focusPos.getZ())));
            if (NetworkHelper.getSoulNetwork(binding).syphonAndDamage(PlayerHelper.getPlayerFromUUID(binding.getOwnerId()), lpToBeDrained * (focusLevel * 2 - 1) * (focusLevel * 2 - 1) * (focusLevel * 2 - 1))) {
                int blocksTransported = 0;
                for (int i = -(focusLevel - 1); i <= (focusLevel - 1); i++) {
                    for (int j = 0; j <= (focusLevel * 2 - 2); j++) {
                        for (int k = -(focusLevel - 1); k <= (focusLevel - 1); k++) {
                            TeleposeEvent event = new TeleposeEvent(getWorld(), pos.add(i, 1 + j, k), focusWorld, focusPos.add(i, 1 + j, k));
                            if (Utils.swapLocations(event.initalWorld, event.initialBlockPos, event.finalWorld, event.finalBlockPos) && !MinecraftForge.EVENT_BUS.post(event)) {
                                blocksTransported++;
                            }
                        }
                    }
                }
                NetworkHelper.syphonFromContainer(focusStack, lpToBeDrained * blocksTransported);
                List<Entity> originalWorldEntities;
                List<Entity> focusWorldEntities;
                AxisAlignedBB originalArea = new AxisAlignedBB(pos.getX(), pos.getY() + 1, pos.getZ(), pos.getX() + 1, Math.min(focusWorld.getHeight(), pos.getY() + 2 * focusLevel), pos.getZ() + 1).expand(focusLevel - 1, 0, focusLevel - 1);
                originalWorldEntities = getWorld().getEntitiesWithinAABB(Entity.class, originalArea);
                AxisAlignedBB focusArea = new AxisAlignedBB(focusPos.getX(), focusPos.getY() + 1, focusPos.getZ(), focusPos.getX() + 1, Math.min(focusWorld.getHeight(), focusPos.getY() + 2 * focusLevel), focusPos.getZ() + 1).expand(focusLevel - 1, 0, focusLevel - 1);
                focusWorldEntities = focusWorld.getEntitiesWithinAABB(Entity.class, focusArea);
                if (focusWorld.equals(getWorld())) {
                    if (!originalWorldEntities.isEmpty()) {
                        for (Entity entity : originalWorldEntities) {
                            TeleportQueue.getInstance().addITeleport(new Teleports.TeleportSameDim(new BlockPos(entity.posX - pos.getX() + focusPos.getX(), entity.posY - pos.getY() + focusPos.getY(), entity.posZ - pos.getZ() + focusPos.getZ()), entity, binding.getOwnerId(), true));
                        }
                    }
                    if (!focusWorldEntities.isEmpty()) {
                        for (Entity entity : focusWorldEntities) {
                            TeleportQueue.getInstance().addITeleport(new Teleports.TeleportSameDim(new BlockPos(entity.posX - pos.getX() + focusPos.getX(), entity.posY - pos.getY() + focusPos.getY(), entity.posZ - pos.getZ() + focusPos.getZ()), entity, binding.getOwnerId(), true));
                        }
                    }
                }
            // FIXME - Fix cross-dimension teleports causing major desync
            // } else {
            // if (!originalWorldEntities.isEmpty()) {
            // for (Entity entity : originalWorldEntities) {
            // TeleportQueue.getInstance().addITeleport(new Teleports.TeleportToDim(new BlockPos(entity.posX - pos.getX() + focusPos.getX(), entity.posY - pos.getY() + focusPos.getY(), entity.posZ - pos.getZ() + focusPos.getZ()), entity, focusStack.getTagCompound().getString(Constants.NBT.OWNER_UUID), getWorld(), focusWorld.provider.getDimension(), true));
            // }
            // }
            // 
            // if (!focusWorldEntities.isEmpty()) {
            // for (Entity entity : focusWorldEntities) {
            // TeleportQueue.getInstance().addITeleport(new Teleports.TeleportToDim(new BlockPos(entity.posX - pos.getX() + focusPos.getX(), entity.posY - pos.getY() + focusPos.getY(), entity.posZ - pos.getZ() + focusPos.getZ()), entity, focusStack.getTagCompound().getString(Constants.NBT.OWNER_UUID), focusWorld, getWorld().provider.getDimension(), true));
            // }
            // }
            // }
            }
        }
    }
}
Also used : Binding(WayofTime.bloodmagic.core.data.Binding) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) BlockTeleposer(WayofTime.bloodmagic.block.BlockTeleposer) World(net.minecraft.world.World) Teleports(WayofTime.bloodmagic.ritual.portal.Teleports) TileEntity(net.minecraft.tileentity.TileEntity) TeleposeEvent(WayofTime.bloodmagic.event.TeleposeEvent) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) ItemTelepositionFocus(WayofTime.bloodmagic.item.ItemTelepositionFocus)

Example 3 with ItemTelepositionFocus

use of WayofTime.bloodmagic.item.ItemTelepositionFocus in project BloodMagic by WayofTime.

the class ContainerTeleposer method transferStackInSlot.

@Override
public ItemStack transferStackInSlot(EntityPlayer player, int slot) {
    ItemStack stack = ItemStack.EMPTY;
    Slot slotObject = inventorySlots.get(slot);
    int slots = inventorySlots.size();
    if (slotObject != null && slotObject.getHasStack()) {
        ItemStack stackInSlot = slotObject.getStack();
        stack = stackInSlot.copy();
        if (stack.getItem() instanceof ItemTelepositionFocus) {
            if (slot <= slots) {
                if (!this.mergeItemStack(stackInSlot, 0, slots, false)) {
                    return ItemStack.EMPTY;
                }
            } else if (!this.mergeItemStack(stackInSlot, slots, 36 + slots, false)) {
                return ItemStack.EMPTY;
            }
        }
        if (stackInSlot.getCount() == 0) {
            slotObject.putStack(ItemStack.EMPTY);
        } else {
            slotObject.onSlotChanged();
        }
        if (stackInSlot.getCount() == stack.getCount()) {
            return ItemStack.EMPTY;
        }
        slotObject.onTake(player, stackInSlot);
    }
    return stack;
}
Also used : Slot(net.minecraft.inventory.Slot) ItemStack(net.minecraft.item.ItemStack) ItemTelepositionFocus(WayofTime.bloodmagic.item.ItemTelepositionFocus)

Aggregations

ItemTelepositionFocus (WayofTime.bloodmagic.item.ItemTelepositionFocus)3 ItemStack (net.minecraft.item.ItemStack)3 BlockTeleposer (WayofTime.bloodmagic.block.BlockTeleposer)1 Binding (WayofTime.bloodmagic.core.data.Binding)1 TeleposeEvent (WayofTime.bloodmagic.event.TeleposeEvent)1 Teleports (WayofTime.bloodmagic.ritual.portal.Teleports)1 TileTeleposer (WayofTime.bloodmagic.tile.TileTeleposer)1 Entity (net.minecraft.entity.Entity)1 Slot (net.minecraft.inventory.Slot)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 TileEntity (net.minecraft.tileentity.TileEntity)1 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)1 BlockPos (net.minecraft.util.math.BlockPos)1 World (net.minecraft.world.World)1