Search in sources :

Example 1 with CompoundNBT

use of net.minecraft.nbt.CompoundNBT in project Bookshelf by Darkhax-Minecraft.

the class SkullUtils method createSkull.

/**
 * Creates a skull using a players UUID.
 *
 * @param name The name of the player.
 * @param uuid The UUID of the player to base the skull on.
 * @return ItemStack An ItemStack containing a skull which represents the owner of the
 *         passed UUID.
 */
public static ItemStack createSkull(String name, UUID uuid) {
    final ItemStack stack = new ItemStack(Items.PLAYER_HEAD, 1);
    final CompoundNBT ownerTag = new CompoundNBT();
    ownerTag.putString("Name", name);
    ownerTag.putString("Id", uuid.toString());
    stack.getOrCreateTag().put("SkullOwner", ownerTag);
    return stack;
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) ItemStack(net.minecraft.item.ItemStack)

Example 2 with CompoundNBT

use of net.minecraft.nbt.CompoundNBT in project Bookshelf by Darkhax-Minecraft.

the class SerializerVec3d method read.

@Override
public Vector3d read(INBT nbt) {
    if (nbt instanceof CompoundNBT) {
        final CompoundNBT tag = (CompoundNBT) nbt;
        final double x = tag.getDouble("x");
        final double y = tag.getDouble("y");
        final double z = tag.getDouble("z");
        return new Vector3d(x, y, z);
    }
    throw new IllegalArgumentException("Expected NBT to be a compound tag. Class was " + nbt.getClass() + " with ID " + nbt.getId() + " instead.");
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) Vector3d(net.minecraft.util.math.vector.Vector3d)

Example 3 with CompoundNBT

use of net.minecraft.nbt.CompoundNBT in project Bookshelf by Darkhax-Minecraft.

the class SerializerEnchantmentData method read.

@Override
public EnchantmentData read(INBT nbt) {
    if (nbt instanceof CompoundNBT) {
        final CompoundNBT tag = (CompoundNBT) nbt;
        final Enchantment ench = Serializers.ENCHANTMENT.read(tag.get("enchantment"));
        final int level = Serializers.INT.read(tag.get("level"));
        return new EnchantmentData(ench, level);
    }
    throw new IllegalArgumentException("Expected NBT to be a compound tag. Class was " + nbt.getClass() + " with ID " + nbt.getId() + " instead.");
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) Enchantment(net.minecraft.enchantment.Enchantment) EnchantmentData(net.minecraft.enchantment.EnchantmentData)

Example 4 with CompoundNBT

use of net.minecraft.nbt.CompoundNBT in project Bookshelf by Darkhax-Minecraft.

the class SerializerVec3f method read.

@Override
public Vector3f read(INBT nbt) {
    if (nbt instanceof CompoundNBT) {
        final CompoundNBT tag = (CompoundNBT) nbt;
        final float x = tag.getFloat("x");
        final float y = tag.getFloat("y");
        final float z = tag.getFloat("z");
        return new Vector3f(x, y, z);
    }
    throw new IllegalArgumentException("Expected NBT to be a compound tag. Class was " + nbt.getClass() + " with ID " + nbt.getId() + " instead.");
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) Vector3f(net.minecraft.util.math.vector.Vector3f)

Example 5 with CompoundNBT

use of net.minecraft.nbt.CompoundNBT in project NetherEx by LogicTechCorp.

the class SoulGlassBlock method onEntityCollision.

@Override
public void onEntityCollision(BlockState state, World world, BlockPos pos, Entity entity) {
    if (entity instanceof PlayerEntity) {
        PlayerEntity player = (PlayerEntity) entity;
        boolean sinking = player.getLookVec().y < -0.75D;
        CompoundNBT playerData = player.getPersistentData();
        Direction shootDirection = null;
        if (!player.isPotionActive(NetherExEffects.SOUL_SUCKED.get())) {
            playerData.remove(SHOOT_DIRECTION_KEY);
        }
        if (playerData.contains(SHOOT_DIRECTION_KEY)) {
            shootDirection = Direction.byIndex(playerData.getInt(SHOOT_DIRECTION_KEY));
        }
        if (player.isShiftKeyDown()) {
            if (!sinking) {
                if (shootDirection == null) {
                    shootDirection = player.getHorizontalFacing().getOpposite();
                }
                Block blockOneBack = world.getBlockState(pos.offset(shootDirection)).getBlock();
                Block blockTwoBack = world.getBlockState(pos.offset(shootDirection, 2)).getBlock();
                Block blockThreeBack = world.getBlockState(pos.offset(shootDirection, 3)).getBlock();
                if (blockOneBack != this) {
                    player.addPotionEffect(new EffectInstance(NetherExEffects.SOUL_SUCKED.get(), 5, 0, false, false));
                }
                if (blockOneBack == this && blockTwoBack != this) {
                    player.addPotionEffect(new EffectInstance(NetherExEffects.SOUL_SUCKED.get(), 5, 1, false, false));
                } else if (blockOneBack == this && blockThreeBack != this) {
                    player.addPotionEffect(new EffectInstance(NetherExEffects.SOUL_SUCKED.get(), 5, 2, false, false));
                } else if (blockOneBack == this) {
                    player.addPotionEffect(new EffectInstance(NetherExEffects.SOUL_SUCKED.get(), 5, 3, false, false));
                }
            } else {
                if (shootDirection == null) {
                    shootDirection = Direction.UP;
                }
                Block blockUpOne = world.getBlockState(pos.up()).getBlock();
                Block blockUpTwo = world.getBlockState(pos.up(2)).getBlock();
                Block blockUpThree = world.getBlockState(pos.up(3)).getBlock();
                if (blockUpOne != this) {
                    player.addPotionEffect(new EffectInstance(NetherExEffects.SOUL_SUCKED.get(), 5, 0, false, false));
                }
                if (blockUpOne == this && blockUpTwo != this) {
                    player.addPotionEffect(new EffectInstance(NetherExEffects.SOUL_SUCKED.get(), 5, 1, false, false));
                } else if (blockUpOne == this && blockUpThree != this) {
                    player.addPotionEffect(new EffectInstance(NetherExEffects.SOUL_SUCKED.get(), 5, 2, false, false));
                } else if (blockUpOne == this) {
                    player.addPotionEffect(new EffectInstance(NetherExEffects.SOUL_SUCKED.get(), 5, 3, false, false));
                    player.setPosition(player.getPosX(), player.prevPosY, player.getPosZ());
                }
                player.setMotion(player.getMotion().mul(1.0D, 0.25D, 1.0D));
            }
        } else {
            EffectInstance effect = player.getActivePotionEffect(NetherExEffects.SOUL_SUCKED.get());
            int amplifier = 1;
            if (effect != null) {
                amplifier = (effect.getAmplifier() + 1);
            }
            Vec3d motion = player.getMotion();
            if (!sinking && shootDirection != null && shootDirection != Direction.UP) {
                Direction playerDirection = shootDirection.getOpposite();
                if (playerDirection == Direction.NORTH) {
                    if (motion.getZ() < 0) {
                        player.setMotion(motion.mul(1.0D, 1.0D, -1.0D));
                    } else if (motion.getZ() == 0) {
                        player.setMotion(new Vec3d(motion.getX(), motion.getY(), 0.5D));
                    }
                } else if (playerDirection == Direction.EAST) {
                    if (motion.getX() > 0) {
                        player.setMotion(motion.mul(-1.0D, 1.0D, 1.0D));
                    } else if (motion.getX() == 0) {
                        player.setMotion(new Vec3d(-0.5D, motion.getY(), motion.getZ()));
                    }
                } else if (playerDirection == Direction.SOUTH) {
                    if (motion.getZ() > 0) {
                        player.setMotion(motion.mul(1.0D, 1.0D, -1.0D));
                    } else if (motion.getZ() == 0) {
                        player.setMotion(new Vec3d(motion.getX(), motion.getY(), -0.5D));
                    }
                } else if (playerDirection == Direction.WEST) {
                    if (motion.getX() < 0) {
                        player.setMotion(motion.mul(-1.0D, 1.0D, 1.0D));
                    } else if (motion.getX() == 0) {
                        player.setMotion(new Vec3d(0.5D, motion.getY(), motion.getZ()));
                    }
                }
                if (motion.getX() > -6.0D && motion.getX() < 6.0D) {
                    player.setMotion(new Vec3d((motion.getX() * 1.15D * amplifier), motion.getY(), motion.getZ()));
                }
                if (motion.getZ() > -6.0D && motion.getZ() < 6.0D) {
                    player.setMotion(new Vec3d(motion.getX(), motion.getY(), (motion.getZ() * 1.15D * amplifier)));
                }
            } else {
                if (motion.getY() <= 0) {
                    player.setMotion(new Vec3d(motion.getX(), 0.105D, motion.getZ()));
                }
                if (motion.getY() < 1.315D) {
                    player.setMotion(new Vec3d(motion.getX(), (motion.getY() + (amplifier * 0.1D)), motion.getZ()));
                }
            }
        }
        if (shootDirection != null) {
            playerData.putInt(SHOOT_DIRECTION_KEY, shootDirection.getIndex());
        }
    }
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) GlassBlock(net.minecraft.block.GlassBlock) Block(net.minecraft.block.Block) Direction(net.minecraft.util.Direction) EffectInstance(net.minecraft.potion.EffectInstance) Vec3d(net.minecraft.util.math.Vec3d) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Aggregations

CompoundNBT (net.minecraft.nbt.CompoundNBT)127 ItemStack (net.minecraft.item.ItemStack)33 ListNBT (net.minecraft.nbt.ListNBT)19 Nonnull (javax.annotation.Nonnull)12 PlayerEntity (net.minecraft.entity.player.PlayerEntity)10 BlockPos (net.minecraft.util.math.BlockPos)10 ResourceLocation (net.minecraft.util.ResourceLocation)9 BlockState (net.minecraft.block.BlockState)8 TileEntity (net.minecraft.tileentity.TileEntity)7 StringTextComponent (net.minecraft.util.text.StringTextComponent)7 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)6 DimensionType (net.minecraft.world.dimension.DimensionType)6 TileBPMultipart (com.bluepowermod.tile.TileBPMultipart)5 Block (net.minecraft.block.Block)5 ArrayList (java.util.ArrayList)4 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)4 SUpdateTileEntityPacket (net.minecraft.network.play.server.SUpdateTileEntityPacket)4 LongItemStack (com.cjm721.overloaded.storage.stacks.intint.LongItemStack)3 Nullable (javax.annotation.Nullable)3 IItemProvider (net.minecraft.util.IItemProvider)3