Search in sources :

Example 6 with DimensionType

use of net.minecraft.world.dimension.DimensionType in project NetherEx by LogicTechCorp.

the class PlayerHandler method onItemCrafted.

@SubscribeEvent
public static void onItemCrafted(PlayerEvent.ItemCraftedEvent event) {
    PlayerEntity player = event.getPlayer();
    ItemStack stack = event.getCrafting();
    if (stack.getItem() == NetherExItems.DULL_MIRROR.get()) {
        if (stack.getDamage() < stack.getMaxDamage()) {
            CompoundNBT compound = NBTHelper.ensureTagExists(stack);
            compound.putBoolean("RemovedSpawn", false);
            if (compound.contains("SpawnDimension") && compound.contains("SpawnPoint")) {
                DimensionType spawnDimension = DimensionType.byName(new ResourceLocation(compound.getString("SpawnDimension")));
                BlockPos spawnPoint = NBTUtil.readBlockPos(compound.getCompound("SpawnPoint"));
                if (spawnDimension != null) {
                    player.setSpawnDimenion(spawnDimension);
                    player.setSpawnPoint(spawnPoint, true, false, spawnDimension);
                }
            }
        }
    }
}
Also used : DimensionType(net.minecraft.world.dimension.DimensionType) CompoundNBT(net.minecraft.nbt.CompoundNBT) ResourceLocation(net.minecraft.util.ResourceLocation) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Aggregations

CompoundNBT (net.minecraft.nbt.CompoundNBT)6 DimensionType (net.minecraft.world.dimension.DimensionType)6 BlockPos (net.minecraft.util.math.BlockPos)5 PlayerEntity (net.minecraft.entity.player.PlayerEntity)4 ItemStack (net.minecraft.item.ItemStack)4 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)3 ResourceLocation (net.minecraft.util.ResourceLocation)3 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)3 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)2 PlayerInventory (net.minecraft.entity.player.PlayerInventory)1 IInventory (net.minecraft.inventory.IInventory)1 MinecraftServer (net.minecraft.server.MinecraftServer)1 World (net.minecraft.world.World)1 OnlyIn (net.minecraftforge.api.distmarker.OnlyIn)1