Search in sources :

Example 1 with PlayerInventory

use of net.minecraft.entity.player.PlayerInventory in project BluePower by Qmunity.

the class ContainerGhosts method clickedPhantom.

/**
 * This method is copied from the BuildCraft code, which can be found here: https://github.com/BuildCraft/BuildCraft
 * @author CovertJaguar <http://www.railcraft.info>
 */
private ItemStack clickedPhantom(Slot slot, int dragType, ClickType clickTypeIn, PlayerEntity player) {
    ItemStack stack = ItemStack.EMPTY;
    if (clickTypeIn.ordinal() == 2) {
        if (((IPhantomSlot) slot).canAdjust()) {
            slot.set(ItemStack.EMPTY);
        }
    } else if (clickTypeIn.ordinal() == 0 || clickTypeIn.ordinal() == 1) {
        PlayerInventory playerInv = player.inventory;
        slot.setChanged();
        ItemStack stackSlot = slot.getItem();
        ItemStack stackHeld = playerInv.getCarried();
        if (stackSlot != ItemStack.EMPTY) {
            stack = stackSlot.copy();
        }
        if (stackSlot == ItemStack.EMPTY) {
            if (stackHeld != ItemStack.EMPTY && slot.mayPlace(stackHeld)) {
                fillPhantomSlot(slot, stackHeld, clickTypeIn.ordinal(), dragType);
            }
        } else if (stackHeld == ItemStack.EMPTY) {
            adjustPhantomSlot(slot, clickTypeIn.ordinal(), dragType);
            slot.onQuickCraft(stack, playerInv.getCarried());
        } else if (slot.mayPlace(stackHeld)) {
            if (canStacksMerge(stackSlot, stackHeld)) {
                adjustPhantomSlot(slot, clickTypeIn.ordinal(), dragType);
            } else {
                fillPhantomSlot(slot, stackHeld, clickTypeIn.ordinal(), dragType);
            }
        }
    }
    return stack;
}
Also used : IPhantomSlot(com.bluepowermod.container.slot.IPhantomSlot) PlayerInventory(net.minecraft.entity.player.PlayerInventory) ItemStack(net.minecraft.item.ItemStack)

Example 2 with PlayerInventory

use of net.minecraft.entity.player.PlayerInventory in project NetherEx by LogicTechCorp.

the class PlayerHandler method onPlayerRespawn.

@SubscribeEvent
public static void onPlayerRespawn(PlayerEvent.PlayerRespawnEvent event) {
    World world = event.getPlayer().getEntityWorld();
    PlayerEntity player = event.getPlayer();
    PlayerInventory playerInventory = player.inventory;
    if (!world.isRemote) {
        ItemStack mirrorStack = ItemStack.EMPTY;
        for (int i = 0; i < playerInventory.getSizeInventory(); i++) {
            ItemStack stack = playerInventory.getStackInSlot(i);
            if (stack.getItem() == NetherExItems.DULL_MIRROR.get()) {
                mirrorStack = stack;
                break;
            }
        }
        if (!mirrorStack.isEmpty()) {
            if (mirrorStack.getDamage() < mirrorStack.getMaxDamage() - 1) {
                CompoundNBT compound = NBTHelper.ensureTagExists(mirrorStack);
                if (compound.contains("SpawnDimension") && compound.contains("SpawnPoint")) {
                    DimensionType spawnDimension = DimensionType.byName(new ResourceLocation(compound.getString("SpawnDimension")));
                    if (spawnDimension != null && player.dimension != spawnDimension) {
                        MinecraftServer server = world.getServer();
                        if (server != null) {
                            BlockPos spawnPoint = NBTUtil.readBlockPos(compound.getCompound("SpawnPoint"));
                            ((ServerPlayerEntity) player).teleport(server.getWorld(spawnDimension), spawnPoint.getX() + 0.5D, spawnPoint.getY(), spawnPoint.getZ() + 0.5D, player.rotationYaw, player.rotationPitch);
                        }
                    }
                }
            }
        }
    }
}
Also used : DimensionType(net.minecraft.world.dimension.DimensionType) CompoundNBT(net.minecraft.nbt.CompoundNBT) ResourceLocation(net.minecraft.util.ResourceLocation) BlockPos(net.minecraft.util.math.BlockPos) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) PlayerInventory(net.minecraft.entity.player.PlayerInventory) World(net.minecraft.world.World) ItemStack(net.minecraft.item.ItemStack) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) MinecraftServer(net.minecraft.server.MinecraftServer) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Aggregations

PlayerInventory (net.minecraft.entity.player.PlayerInventory)2 ItemStack (net.minecraft.item.ItemStack)2 IPhantomSlot (com.bluepowermod.container.slot.IPhantomSlot)1 PlayerEntity (net.minecraft.entity.player.PlayerEntity)1 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)1 CompoundNBT (net.minecraft.nbt.CompoundNBT)1 MinecraftServer (net.minecraft.server.MinecraftServer)1 ResourceLocation (net.minecraft.util.ResourceLocation)1 BlockPos (net.minecraft.util.math.BlockPos)1 World (net.minecraft.world.World)1 DimensionType (net.minecraft.world.dimension.DimensionType)1 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)1