Search in sources :

Example 86 with TextComponentTranslation

use of net.minecraft.util.text.TextComponentTranslation in project Random-Things by lumien231.

the class RTCommand method execute.

@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
    if (args.length == 0) {
        return;
    }
    if (args[0].equals("setBiomeCrystal")) {
        if (args.length == 2 && sender instanceof EntityPlayer) {
            String biomeName = args[1];
            EntityPlayer player = (EntityPlayer) sender;
            ItemStack equipped = player.getHeldItemMainhand();
            if (equipped != null && equipped.getItem() instanceof ItemBiomeCrystal) {
                if (equipped.getTagCompound() == null) {
                    equipped.setTagCompound(new NBTTagCompound());
                }
                equipped.getTagCompound().setString("biomeName", args[1]);
            }
        }
    } else if (args[0].equals("generateBiomeCrystalChests")) {
        if (sender instanceof EntityPlayer) {
            List<ResourceLocation> biomeIds = new ArrayList<>(Biome.REGISTRY.getKeys());
            int modX = 0;
            while (!biomeIds.isEmpty()) {
                sender.getEntityWorld().setBlockState(sender.getPosition().add(modX, 0, 0), Blocks.CHEST.getDefaultState());
                IInventory inventory = (IInventory) sender.getEntityWorld().getTileEntity(sender.getPosition().add(modX, 0, 0));
                for (int i = 0; i < 27; i++) {
                    if (!biomeIds.isEmpty()) {
                        ResourceLocation next = biomeIds.remove(biomeIds.size() - 1);
                        ItemStack crystal = new ItemStack(ModItems.biomeCrystal);
                        crystal.setTagCompound(new NBTTagCompound());
                        crystal.getTagCompound().setString("biomeName", next.toString());
                        inventory.setInventorySlotContents(i, crystal);
                    }
                }
                modX += 2;
            }
        }
    } else if (args[0].equals("tpFilter")) {
        if (sender instanceof EntityPlayerMP) {
            EntityPlayerMP player = (EntityPlayerMP) sender;
            ItemStack held;
            if ((held = player.getHeldItemMainhand()) != null && held.getItem() == ModItems.positionFilter) {
                BlockPos pos = ItemPositionFilter.getPosition(held);
                player.connection.setPlayerLocation(pos.getX(), pos.getY() + 150, pos.getZ(), player.rotationYaw, player.rotationPitch);
            }
        }
    } else if (args[0].equals("testSlimeSpawn")) {
        BlockPos pos = sender.getPosition();
        World world = sender.getEntityWorld();
        if (pos != null && world != null) {
            EntitySlime slime = new EntitySlime(world);
            slime.setLocationAndAngles(pos.getX(), pos.getY(), pos.getZ(), 0F, 0F);
            sender.sendMessage(new TextComponentString(slime.getCanSpawnHere() + ""));
        }
    } else if (args[0].equals("notify") && args.length == 5) {
        String title = args[1];
        String body = args[2];
        String itemName = args[3];
        String player = args[4];
        EntityPlayerMP playerEntity = server.getPlayerList().getPlayerByUsername(player);
        ItemStack itemStack = new ItemStack(ForgeRegistries.ITEMS.getValue(new ResourceLocation(itemName)));
        MessageNotification message = new MessageNotification(title, body, itemStack);
        PacketHandler.INSTANCE.sendTo(message, playerEntity);
    } else if (args[0].equals("fireplaces")) {
        FlooNetworkHandler handler = FlooNetworkHandler.get(sender.getEntityWorld());
        List<FlooFireplace> firePlaces = handler.getFirePlaces();
        sender.sendMessage(new TextComponentString("Floo Fireplaces in Dimension " + sender.getEntityWorld().provider.getDimension()).setStyle(new Style().setUnderlined(true)));
        sender.sendMessage(new TextComponentString(""));
        for (FlooFireplace firePlace : firePlaces) {
            String name = firePlace.getName();
            UUID creator = firePlace.getCreatorUUID();
            String ownerName = null;
            if (creator != null) {
                GameProfile profile = server.getPlayerProfileCache().getProfileByUUID(creator);
                if (profile != null) {
                    ownerName = profile.getName();
                }
            }
            BlockPos pos = firePlace.getLastKnownPosition();
            sender.sendMessage(new TextComponentString((name == null ? "<Unnamed>" : name) + " | " + String.format("%d %d %d", pos.getX(), pos.getY(), pos.getZ()) + (ownerName != null ? " | " + ownerName : "")));
        }
    } else if (args[0].equals("festival")) {
        FestivalHandler handler = FestivalHandler.get(sender.getEntityWorld());
        List<EntityVillager> villagerList = sender.getEntityWorld().getEntitiesWithinAABB(EntityVillager.class, new AxisAlignedBB(sender.getPosition()).grow(50));
        if (!villagerList.isEmpty()) {
            EntityVillager villager = villagerList.get(0);
            int success = handler.addFestival(villager);
            if (success == 2) {
                sender.sendMessage(new TextComponentTranslation("command.festival.scheduled"));
            } else {
                sender.sendMessage(new TextComponentTranslation("command.festival.failed"));
            }
        } else {
            sender.sendMessage(new TextComponentTranslation("command.festival.novillager"));
        }
    } else if (args[0].equals("ancientFurnace")) {
        WorldGenAncientFurnace.pattern.place(sender.getEntityWorld(), sender.getPosition(), 3);
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) TextComponentString(net.minecraft.util.text.TextComponentString) MessageNotification(lumien.randomthings.network.messages.MessageNotification) World(net.minecraft.world.World) ResourceLocation(net.minecraft.util.ResourceLocation) FlooNetworkHandler(lumien.randomthings.handler.floo.FlooNetworkHandler) EntityVillager(net.minecraft.entity.passive.EntityVillager) Style(net.minecraft.util.text.Style) ArrayList(java.util.ArrayList) List(java.util.List) BlockPos(net.minecraft.util.math.BlockPos) UUID(java.util.UUID) IInventory(net.minecraft.inventory.IInventory) FestivalHandler(lumien.randomthings.handler.festival.FestivalHandler) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) EntitySlime(net.minecraft.entity.monster.EntitySlime) ItemBiomeCrystal(lumien.randomthings.item.ItemBiomeCrystal) TextComponentString(net.minecraft.util.text.TextComponentString) GameProfile(com.mojang.authlib.GameProfile) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) ItemStack(net.minecraft.item.ItemStack) FlooFireplace(lumien.randomthings.handler.floo.FlooFireplace)

Example 87 with TextComponentTranslation

use of net.minecraft.util.text.TextComponentTranslation in project Random-Things by lumien231.

the class FestivalHandler method tick.

public void tick(World worldObj) {
    long time = worldObj.getWorldTime();
    boolean celebrationTime = time > 14000 & time < 20000;
    Iterator<Festival> iterator = currentFestivals.iterator();
    while (iterator.hasNext()) {
        boolean firework = false;
        Festival festival = iterator.next();
        if (festival.getState() == STATE.SCHEDULED && celebrationTime) {
            festival.setActive();
            firework = true;
            this.markDirty();
        } else if (festival.getState() == STATE.ACTIVE && !celebrationTime) {
            iterator.remove();
            this.markDirty();
        } else if (festival.getState() == STATE.ACTIVE && celebrationTime) {
            firework = true;
        }
        if (firework) {
            List<BlockPos> doorPositions = festival.getDoorPositions();
            if (time == 14001) {
                MessageUtil.sendToAllWatchingPos(worldObj, doorPositions.get(0), new SPacketChat(new TextComponentTranslation("festival.celebrating"), ChatType.SYSTEM));
            }
            boolean midnight = Math.abs(time - 18000) < 20 * 15;
            if (time == 18000) {
                for (BlockPos pos : doorPositions) {
                    if (worldObj.isBlockLoaded(pos) && worldObj.isAnyPlayerWithinRangeAt(pos.getX(), pos.getY(), pos.getZ(), 256)) {
                        ItemStack rocket = getRandomFirework();
                        if (!rocket.isEmpty()) {
                            BlockPos topPos = worldObj.getTopSolidOrLiquidBlock(pos);
                            EntityFireworkRocket entity = new EntityFireworkRocket(worldObj, topPos.getX() + rng.nextFloat(), topPos.getY() + 1, topPos.getZ() + rng.nextFloat(), rocket);
                            worldObj.spawnEntity(entity);
                        }
                    }
                }
            } else {
                if (!doorPositions.isEmpty() && rng.nextFloat() < (midnight ? 0.1 : 0.05)) {
                    BlockPos randomPosition = doorPositions.get(rng.nextInt(doorPositions.size()));
                    if (worldObj.isBlockLoaded(randomPosition) && worldObj.isAnyPlayerWithinRangeAt(randomPosition.getX(), randomPosition.getY(), randomPosition.getZ(), 256)) {
                        ItemStack rocket = getRandomFirework();
                        if (!rocket.isEmpty()) {
                            BlockPos pos = worldObj.getTopSolidOrLiquidBlock(randomPosition);
                            EntityFireworkRocket entity = new EntityFireworkRocket(worldObj, pos.getX() + rng.nextFloat(), pos.getY() + 1, pos.getZ() + rng.nextFloat(), rocket);
                            worldObj.spawnEntity(entity);
                        }
                    }
                }
            }
        }
    }
}
Also used : SPacketChat(net.minecraft.network.play.server.SPacketChat) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) EntityFireworkRocket(net.minecraft.entity.item.EntityFireworkRocket) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack)

Example 88 with TextComponentTranslation

use of net.minecraft.util.text.TextComponentTranslation in project Random-Things by lumien231.

the class BlockEnderMailbox method onBlockActivated.

@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
    if (!worldIn.isRemote) {
        ItemStack heldItem = playerIn.getHeldItemMainhand();
        if (playerIn.isSneaking() && heldItem.getItem() == ModItems.enderLetter) {
            NBTTagCompound compound;
            if ((compound = heldItem.getTagCompound()) != null) {
                if (compound.hasKey("receiver") && !compound.getBoolean("received")) {
                    GameProfile playerProfile = worldIn.getMinecraftServer().getPlayerProfileCache().getGameProfileForUsername(compound.getString("receiver"));
                    if (playerProfile != null && playerProfile.getId() != null) {
                        EnderMailboxInventory mailboxInventory = EnderLetterHandler.get(worldIn).getOrCreateInventoryForPlayer(playerProfile.getId());
                        for (int slot = 0; slot < mailboxInventory.getSizeInventory(); slot++) {
                            if (mailboxInventory.getStackInSlot(slot).isEmpty()) {
                                ItemStack sendingLetter = heldItem.copy();
                                heldItem.shrink(1);
                                sendingLetter.getTagCompound().setBoolean("received", true);
                                sendingLetter.getTagCompound().setString("sender", playerIn.getGameProfile().getName());
                                mailboxInventory.setInventorySlotContents(slot, sendingLetter);
                                playerIn.world.playSound(null, pos, SoundEvents.ENTITY_ENDERMEN_TELEPORT, SoundCategory.BLOCKS, 1, 1);
                                return true;
                            }
                        }
                        playerIn.sendMessage(new TextComponentTranslation("item.enderLetter.noSpace").setStyle(new Style().setColor(TextFormatting.DARK_PURPLE)));
                    } else {
                        playerIn.sendMessage(new TextComponentTranslation("item.enderLetter.noPlayer", compound.getString("receiver")).setStyle(new Style().setColor(TextFormatting.DARK_PURPLE)));
                    }
                }
            }
            return true;
        }
        TileEntityEnderMailbox te = (TileEntityEnderMailbox) worldIn.getTileEntity(pos);
        if (te.getOwner() != null) {
            if (te.getOwner().equals(playerIn.getGameProfile().getId())) {
                playerIn.openGui(RandomThings.instance, GuiIds.ENDER_MAILBOX, worldIn, pos.getX(), pos.getY(), pos.getZ());
            } else {
                playerIn.sendMessage(new TextComponentTranslation("block.enderMailbox.owner").setStyle(new Style().setColor(TextFormatting.RED)));
            }
        }
    }
    return true;
}
Also used : TileEntityEnderMailbox(lumien.randomthings.tileentity.TileEntityEnderMailbox) EnderMailboxInventory(lumien.randomthings.handler.EnderLetterHandler.EnderMailboxInventory) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) GameProfile(com.mojang.authlib.GameProfile) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Style(net.minecraft.util.text.Style) ItemStack(net.minecraft.item.ItemStack)

Example 89 with TextComponentTranslation

use of net.minecraft.util.text.TextComponentTranslation in project ManaCraft by Yaossg.

the class ItemManaApple method itemInteractionForEntity.

@Override
public boolean itemInteractionForEntity(ItemStack stack, EntityPlayer playerIn, EntityLivingBase target, EnumHand hand) {
    if (target instanceof EntityPig && hand == EnumHand.MAIN_HAND && Config.PES > 0) {
        if (playerIn.getServer() != null)
            playerIn.getServer().getPlayerList().sendMessage(new TextComponentTranslation("message.pig"));
        EntityPig pig = (EntityPig) target;
        playerIn.attackEntityFrom(new DamageSource("byPig").setDifficultyScaled().setExplosion().setMagicDamage().setFireDamage(), 16);
        ItemManaApple.appleExplosin(pig);
        Util.giveManaCraftAdvancement(playerIn, "pig_bomb");
        stack.shrink(1);
        return true;
    }
    return false;
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) DamageSource(net.minecraft.util.DamageSource) EntityPig(net.minecraft.entity.passive.EntityPig)

Example 90 with TextComponentTranslation

use of net.minecraft.util.text.TextComponentTranslation in project Kingdom-Keys-Re-Coded by Wehavecookies56.

the class DimensionTeleporter method teleport.

public void teleport(Entity entity) {
    EntityPlayerMP playerMP = (EntityPlayerMP) entity;
    entity.setPosition(spawn.getX(), spawn.getY() + 1, spawn.getZ());
    entity.motionX = entity.motionY = entity.motionZ = 0.0D;
    entity.setPosition(spawn.getX(), spawn.getY() + 1, spawn.getZ());
    if (playerMP.dimension != Utils.getDimensionIDAndBlockPos(dimension).id)
        playerMP.mcServer.getPlayerList().transferPlayerToDimension(playerMP, Utils.getDimensionIDAndBlockPos(dimension).id, this);
    WorldSavedDataKingdomKeys data = WorldSavedDataKingdomKeys.get(playerMP.world);
    if (!data.isGenerated()) {
        entity.sendMessage(new TextComponentTranslation("Generating world, this will take a while..."));
        entity.sendMessage(new TextComponentTranslation("This only happens the first time you visit the world"));
        WorldLoader loader = new WorldLoader();
        loader.processAndGenerateStructureFile(dimension, playerMP.world.getMinecraftServer().getServer().getWorld(Utils.getDimensionIDAndBlockPos(dimension).id), Utils.getDimensionIDAndBlockPos(dimension).offset);
        entity.sendMessage(new TextComponentTranslation("World generated completed, please wait while chunks load..."));
        entity.sendMessage(new TextComponentTranslation("Expect a large performance drop while this happens"));
        data.setGenerated(true);
    }
    entity.setPositionAndRotation(spawn.getX(), spawn.getY() + 1, spawn.getZ(), 180, 0);
    entity.setPosition(spawn.getX(), spawn.getY() + 1, spawn.getZ());
    entity.setPosition(spawn.getX(), spawn.getY() + 1, spawn.getZ());
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) WorldLoader(uk.co.wehavecookies56.kk.common.world.WorldLoader) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) WorldSavedDataKingdomKeys(uk.co.wehavecookies56.kk.common.world.WorldSavedDataKingdomKeys)

Aggregations

TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)502 ItemStack (net.minecraft.item.ItemStack)134 ITextComponent (net.minecraft.util.text.ITextComponent)82 EntityPlayer (net.minecraft.entity.player.EntityPlayer)72 BlockPos (net.minecraft.util.math.BlockPos)70 TextComponentString (net.minecraft.util.text.TextComponentString)66 Style (net.minecraft.util.text.Style)60 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)58 TileEntity (net.minecraft.tileentity.TileEntity)45 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)36 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)33 ArrayList (java.util.ArrayList)32 World (net.minecraft.world.World)30 IBlockState (net.minecraft.block.state.IBlockState)28 EnumFacing (net.minecraft.util.EnumFacing)26 CommandException (net.minecraft.command.CommandException)25 Block (net.minecraft.block.Block)20 Nonnull (javax.annotation.Nonnull)19 WrongUsageException (net.minecraft.command.WrongUsageException)19 EnumActionResult (net.minecraft.util.EnumActionResult)19