use of net.minecraft.world.dimension.DimensionType in project NetherEx by LogicTechCorp.
the class PlayerHandler method onPlayerClone.
@SubscribeEvent
public static void onPlayerClone(PlayerEvent.Clone event) {
PlayerEntity oldPlayer = event.getOriginal();
PlayerEntity newPlayer = event.getPlayer();
IInventory oldInventory = oldPlayer.inventory;
IInventory newInventory = newPlayer.inventory;
if (event.isWasDeath()) {
ItemStack mirrorStack = ItemStack.EMPTY;
for (int i = 0; i < oldInventory.getSizeInventory(); i++) {
ItemStack stack = oldInventory.getStackInSlot(i);
if (stack.getItem() == NetherExItems.DULL_MIRROR.get()) {
NBTHelper.ensureTagExists(stack);
if (stack.getTag().contains("SpawnPoint") && (stack.getDamage() < (stack.getMaxDamage() - 1))) {
stack.damageItem(1, newPlayer, entity -> {
});
}
newInventory.setInventorySlotContents(i, stack);
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")));
BlockPos spawnPoint = NBTUtil.readBlockPos(compound.getCompound("SpawnPoint"));
if (spawnDimension != null) {
newPlayer.setSpawnDimenion(spawnDimension);
newPlayer.setSpawnPoint(spawnPoint, true, false, spawnDimension);
}
}
}
}
}
}
use of net.minecraft.world.dimension.DimensionType in project NetherEx by LogicTechCorp.
the class DullMirrorItem method onItemRightClick.
@Override
public ActionResult<ItemStack> onItemRightClick(World world, PlayerEntity player, Hand hand) {
ItemStack stack = player.getHeldItem(hand);
if (!world.isRemote) {
if (stack.getDamage() < stack.getMaxDamage() && player.isShiftKeyDown()) {
DimensionType spawnDimension = world.getDimension().getType();
BlockPos spawnPoint = player.getPosition();
CompoundNBT compound = NBTHelper.ensureTagExists(stack);
if (!compound.contains("SpawnDimension") || !compound.contains("SpawnPoint")) {
DimensionType bedDimension = player.getSpawnDimension();
BlockPos bedPos = player.getBedLocation(bedDimension);
if (bedPos == null) {
bedPos = world.getServer().getWorld(bedDimension).getSpawnPoint();
}
compound.putString("BedDimension", bedDimension.getRegistryName().toString());
compound.put("BedPoint", NBTUtil.writeBlockPos(bedPos));
compound.putString("SpawnDimension", spawnDimension.getRegistryName().toString());
compound.put("SpawnPoint", NBTUtil.writeBlockPos(spawnPoint));
player.setSpawnDimenion(spawnDimension);
player.setSpawnPoint(spawnPoint, true, false, spawnDimension);
player.sendMessage(new TranslationTextComponent("tooltip.netherex.dull_mirror.spawn_point_set", spawnPoint.getX() + " " + spawnPoint.getY() + " " + spawnPoint.getZ()));
world.playSound((double) spawnPoint.getX() + 0.5D, (double) spawnPoint.getY() + 0.5D, (double) spawnPoint.getZ() + 0.5D, SoundEvents.BLOCK_PORTAL_AMBIENT, SoundCategory.BLOCKS, 0.5F, world.rand.nextFloat() * 0.4F + 0.8F, false);
} else {
DimensionType bedDimension = DimensionType.byName(new ResourceLocation(compound.getString("BedDimension")));
if (bedDimension != null) {
compound.remove("SpawnDimension");
compound.remove("SpawnPoint");
player.setSpawnDimenion(bedDimension);
player.setSpawnPoint(NBTUtil.readBlockPos(compound.getCompound("BedPoint")), true, false, bedDimension);
player.sendMessage(new TranslationTextComponent("tooltip.netherex.dull_mirror.spawn_point_removed", spawnPoint.getX() + " " + spawnPoint.getY() + " " + spawnPoint.getZ()));
world.playSound((double) spawnPoint.getX() + 0.5D, (double) spawnPoint.getY() + 0.5D, (double) spawnPoint.getZ() + 0.5D, SoundEvents.BLOCK_FIRE_AMBIENT, SoundCategory.BLOCKS, 0.5F, world.rand.nextFloat() * 0.4F + 0.8F, false);
}
}
return new ActionResult<>(ActionResultType.SUCCESS, stack);
}
}
return new ActionResult<>(ActionResultType.FAIL, stack);
}
use of net.minecraft.world.dimension.DimensionType in project NetherEx by LogicTechCorp.
the class DullMirrorItem method addInformation.
@Override
@OnlyIn(Dist.CLIENT)
public void addInformation(ItemStack stack, World world, List<ITextComponent> tooltip, ITooltipFlag flag) {
CompoundNBT compound = stack.getTag();
if (compound != null) {
if (compound.contains("SpawnDimension")) {
DimensionType type = DimensionType.byName(new ResourceLocation(compound.getString("SpawnDimension")));
tooltip.add(new TranslationTextComponent("tooltip.netherex.dull_mirror.spawn_dimension", StringUtils.capitalize(type.getRegistryName().getPath().replace("_", " "))));
}
if (compound.contains("SpawnPoint")) {
BlockPos spawnPos = NBTUtil.readBlockPos(compound.getCompound("SpawnPoint"));
tooltip.add(new TranslationTextComponent("tooltip.netherex.dull_mirror.spawn_point", spawnPos.getX() + " " + spawnPos.getY() + " " + spawnPos.getZ()));
}
if (compound.contains("DeathPoint")) {
BlockPos deathPos = NBTUtil.readBlockPos(compound.getCompound("DeathPoint"));
tooltip.add(new TranslationTextComponent("tooltip.netherex.dull_mirror.death_point", deathPos.getX() + " " + deathPos.getY() + " " + deathPos.getZ()));
}
}
}
use of net.minecraft.world.dimension.DimensionType in project NetherEx by LogicTechCorp.
the class DullMirrorItem method inventoryTick.
@Override
public void inventoryTick(ItemStack stack, World world, Entity entity, int itemSlot, boolean isSelected) {
if (stack.getDamage() == (this.getMaxDamage(stack) - 1)) {
CompoundNBT compound = NBTHelper.ensureTagExists(stack);
if (!compound.getBoolean("RemovedSpawn") && entity instanceof PlayerEntity) {
PlayerEntity player = (PlayerEntity) entity;
if (compound.contains("SpawnDimension") && compound.contains("SpawnPoint")) {
DimensionType bedDimension = DimensionType.byName(new ResourceLocation(compound.getString("BedDimension")));
if (bedDimension != null) {
player.setSpawnDimenion(bedDimension);
player.setSpawnPoint(NBTUtil.readBlockPos(compound.getCompound("BedPoint")), true, false, bedDimension);
compound.putBoolean("RemovedSpawn", true);
}
}
}
}
}
use of net.minecraft.world.dimension.DimensionType 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);
}
}
}
}
}
}
}
Aggregations