net.minecraft.tileentity.TileEntitySign Java Examples

The following examples show how to use net.minecraft.tileentity.TileEntitySign. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ProtectionManager.java    From MyTown2 with The Unlicense 6 votes vote down vote up
public static void checkBlockInteraction(Resident res, BlockPos bp, PlayerInteractEvent.Action action, Event ev) {
    if(!ev.isCancelable()) {
        return;
    }

    World world = MinecraftServer.getServer().worldServerForDimension(bp.getDim());
    Block block = world.getBlock(bp.getX(), bp.getY(), bp.getZ());

    // Bypass for SellSign
    if (block instanceof BlockSign) {
        TileEntity te = world.getTileEntity(bp.getX(), bp.getY(), bp.getZ());
        if(te instanceof TileEntitySign && SellSign.SellSignType.instance.isTileValid((TileEntitySign) te)) {
            return;
        }
    }

    for(SegmentBlock segment : segmentsBlock.get(block.getClass())) {
        if(!segment.shouldInteract(res, bp, action)) {
            ev.setCanceled(true);
        }
    }
}
 
Example #2
Source File: CraftPlayer.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void sendSignChange(Location loc, String[] lines) {
    if (getHandle().connection == null) {
        return;
    }

    if (lines == null) {
        lines = new String[4];
    }

    Validate.notNull(loc, "Location can not be null");
    if (lines.length < 4) {
        throw new IllegalArgumentException("Must have at least 4 lines");
    }

    ITextComponent[] components = CraftSign.sanitizeLines(lines);
    TileEntitySign sign = new TileEntitySign();
    sign.setPos(new BlockPos(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
    System.arraycopy(components, 0, sign.signText, 0, sign.signText.length);

    getHandle().connection.sendPacket(sign.getUpdatePacket());
}
 
Example #3
Source File: SellSign.java    From MyTown2 with The Unlicense 6 votes vote down vote up
@Override
public boolean isTileValid(TileEntitySign te) {
    if (!te.signText[0].startsWith(Sign.IDENTIFIER)) {
        return false;
    }

    try {
        NBTTagCompound rootTag = SignClassTransformer.getMyEssentialsDataValue(te);
        if (rootTag == null)
            return false;

        if (!rootTag.getString("Type").equals(SellSignType.instance.getTypeID()))
            return false;

        NBTBase data = rootTag.getTag("Value");
        if (!(data instanceof NBTTagCompound))
            return false;

        NBTTagCompound signData = (NBTTagCompound) data;

        MyTownUniverse.instance.getOrMakeResident(UUID.fromString(signData.getString("Owner")));
        return true;
    } catch (Exception ex) {
        return false;
    }
}
 
Example #4
Source File: StructureBuilder.java    From mobycraft with Apache License 2.0 6 votes vote down vote up
private static void wrapSignText(String containerProperty,
		TileEntitySign sign) {
	if (containerProperty.length() < 14) {
		sign.signText[1] = new ChatComponentText(containerProperty);
	} else if (containerProperty.length() < 27) {
		sign.signText[1] = new ChatComponentText(
				containerProperty.substring(0, 13));
		sign.signText[2] = new ChatComponentText(
				containerProperty.substring(13, containerProperty.length()));
	} else {
		sign.signText[1] = new ChatComponentText(
				containerProperty.substring(0, 13));
		sign.signText[1] = new ChatComponentText(
				containerProperty.substring(13, 26));
		sign.signText[2] = new ChatComponentText(
				containerProperty.substring(26, containerProperty.length()));
	}
}
 
Example #5
Source File: CraftSign.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
public static String[] sanitizeLines(String[] lines) {
    String[] astring = new String[4];

        for(int i = 0; i < 4; i++) {
        if (i < lines.length && lines[i] != null) {
            astring[i] = lines[i];
            } else {
            astring[i] = "";
        }
    }

    return TileEntitySign.sanitizeLines(astring);
}
 
Example #6
Source File: SellSign.java    From MyTown2 with The Unlicense 5 votes vote down vote up
public SellSign(TileEntitySign te, NBTTagCompound signData) {
    super(SellSignType.instance);
    this.bp = new BlockPos(te.xCoord, te.yCoord, te.zCoord, te.getWorldObj().provider.dimensionId);
    this.owner = MyTownUniverse.instance.getOrMakeResident(UUID.fromString(signData.getString("Owner")));
    this.price = signData.getInteger("Price");
    this.restricted = signData.getBoolean("Restricted");
    this.plot = MyTownUniverse.instance.plots.get(te.getWorldObj().provider.dimensionId, te.xCoord, te.yCoord, te.zCoord);
}
 
Example #7
Source File: Plot.java    From MyTown2 with The Unlicense 5 votes vote down vote up
public void deleteSignBlocks(SignType signType, World world) {
    if(world.provider.dimensionId != dim)
        return;

    int x1 = getStartX();
    int y1 = getStartY();
    int z1 = getStartZ();
    int x2 = getEndX();
    int y2 = getEndY();
    int z2 = getEndZ();
    int cx1 = x1 >> 4;
    int cz1 = z1 >> 4;
    int cx2 = x2 >> 4;
    int cz2 = z2 >> 4;
    for(int cx = cx1; cx <= cx2; cx++)
        for(int cz = cz1; cz <= cz2; cz++) {
            Chunk chunk = world.getChunkFromChunkCoords(cx, cz);
            if(!chunk.isChunkLoaded)
                chunk = world.getChunkProvider().loadChunk(cx, cz);

            List<int[]> sellSigns = new ArrayList<int[]>(2);
            for(Object obj: chunk.chunkTileEntityMap.values()) {
                if(obj instanceof TileEntitySign) {
                    TileEntitySign sign = (TileEntitySign) obj;
                    if(    sign.xCoord >= x1 && sign.xCoord <= x2
                        && sign.yCoord >= y1 && sign.yCoord <= y2
                        && sign.zCoord >= z1 && sign.zCoord <= z2
                        && signType.isTileValid(sign) )
                            sellSigns.add(new int[]{sign.xCoord, sign.yCoord, sign.zCoord});
                }
            }

            for(int[] sellSign: sellSigns) {
                world.removeTileEntity(sellSign[0], sellSign[1], sellSign[2]);
                world.setBlock(sellSign[0], sellSign[1], sellSign[2], Blocks.air);
            }
        }
}
 
Example #8
Source File: AdapterSign.java    From OpenPeripheral-Integration with MIT License 5 votes vote down vote up
@ScriptCallable(description = "Sets the text on the sign")
public void setText(TileEntitySign sign,
		@Arg(name = "text", description = "The text to display on the sign") String text) {
	String[] lines = text.split("\n");

	final int newLength = lines.length;
	final int maxLength = sign.signText.length;

	Preconditions.checkArgument(newLength >= 0 && newLength < maxLength, "Value must be in range [1,%s]", maxLength);

	for (int i = 0; i < maxLength; ++i)
		setLine(sign, i, i < newLength? lines[i] : "");

	updateSign(sign);
}
 
Example #9
Source File: AdapterSign.java    From OpenPeripheral-Integration with MIT License 5 votes vote down vote up
@ScriptCallable(description = "Sets all text from table")
public void setLines(TileEntitySign sign, @Arg(name = "lines") String[] lines) {
	final String[] signText = sign.signText;
	for (int i = 0; i < signText.length; i++) {
		final String line = (i < lines.length? Strings.nullToEmpty(lines[i]) : "");
		signText[i] = line;
	}

	updateSign(sign);
}
 
Example #10
Source File: AdapterSign.java    From OpenPeripheral-Integration with MIT License 5 votes vote down vote up
@Asynchronous
@ScriptCallable(returnTypes = ReturnType.STRING, description = "Gets the text from the supplied line of the sign")
public String getLine(TileEntitySign sign,
		@Arg(name = "line", description = "The line number to get from the sign") Index line) {
	line.checkElementIndex("line", sign.signText.length);
	return sign.signText[line.value];
}
 
Example #11
Source File: AdapterSign.java    From OpenPeripheral-Integration with MIT License 5 votes vote down vote up
@ScriptCallable(description = "Sets the text on the sign")
public void setLine(TileEntitySign sign,
		@Arg(name = "line", description = "The line number to set the text on the sign") Index line,
		@Arg(name = "text", description = "The text to display on the sign") String text) {
	line.checkElementIndex("line", sign.signText.length);
	setLine(sign, line.value, text);
	updateSign(sign);
}
 
Example #12
Source File: NoLagModule.java    From seppuku with GNU General Public License v3.0 5 votes vote down vote up
@Listener
public void renderWorld(EventRender3D event) {
    final Minecraft mc = Minecraft.getMinecraft();
    if (this.signs.getValue()) {
        for (TileEntity te : mc.world.loadedTileEntityList) {
            if (te instanceof TileEntitySign) {
                final TileEntitySign sign = (TileEntitySign) te;
                sign.signText = new ITextComponent[]{new TextComponentString(""), new TextComponentString(""), new TextComponentString(""), new TextComponentString("")};
            }
        }
    }
}
 
Example #13
Source File: CraftSign.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
public CraftSign(final Block block) {
    super(block);

    CraftWorld world = (CraftWorld) block.getWorld();
    sign = (net.minecraft.tileentity.TileEntitySign) world.getTileEntityAt(getX(), getY(), getZ());
    // Spigot start
    if (sign == null) {
        lines = new String[]{"", "", "", ""};
        return;
    }
    // Spigot end
    lines = new String[sign.signText.length];
    System.arraycopy(sign.signText, 0, lines, 0, lines.length);
}
 
Example #14
Source File: BlockDrawingHelper.java    From malmo with MIT License 5 votes vote down vote up
protected void DrawPrimitive( DrawSign s, World w ) throws Exception
{
    String sType = s.getType().value();
    BlockType bType = BlockType.fromValue(sType); // Safe - SignType is a subset of BlockType
    XMLBlockState blockType = new XMLBlockState(bType, s.getColour(), s.getFace(), s.getVariant());
    BlockPos pos = new BlockPos( s.getX(), s.getY(), s.getZ() );
    setBlockState(w, pos, blockType );
    if (blockType.type == BlockType.STANDING_SIGN && s.getRotation() != null)
    {
        IBlockState placedBlockState = w.getBlockState(pos);
        if (placedBlockState != null)
        {
            Block placedBlock = placedBlockState.getBlock();
            if (placedBlock != null)
            {
                IBlockState rotatedBlock = placedBlock.getStateFromMeta(s.getRotation());
                w.setBlockState(pos, rotatedBlock);
            }
        }
    }
    TileEntity tileentity = w.getTileEntity(pos);
    if (tileentity instanceof TileEntitySign)
    {
        TileEntitySign sign = (TileEntitySign)tileentity;
        if (s.getLine1() != null)
            sign.signText[0] = new TextComponentString(s.getLine1());
        if (s.getLine2() != null)
            sign.signText[1] = new TextComponentString(s.getLine2());
        if (s.getLine3() != null)
            sign.signText[2] = new TextComponentString(s.getLine3());
        if (s.getLine4() != null)
            sign.signText[3] = new TextComponentString(s.getLine4());
    }
}
 
Example #15
Source File: SignTextMod.java    From ForgeHax with MIT License 5 votes vote down vote up
@SubscribeEvent
public void onInput(MouseEvent event) {
  if (event.getButton() == 2 && Mouse.getEventButtonState()) { // on middle click
    RayTraceResult result = MC.player.rayTrace(999, 0);
    if (result == null) {
      return;
    }
    if (result.typeOfHit == RayTraceResult.Type.BLOCK) {
      TileEntity tileEntity = MC.world.getTileEntity(result.getBlockPos());
      
      if (tileEntity instanceof TileEntitySign) {
        TileEntitySign sign = (TileEntitySign) tileEntity;
        
        int signTextLength = 0;
        // find the first line from the bottom that isn't empty
        for (int i = 3; i >= 0; i--) {
          if (!sign.signText[i].getUnformattedText().isEmpty()) {
            signTextLength = i + 1;
            break;
          }
        }
        if (signTextLength == 0) {
          return; // if the sign is empty don't do anything
        }
        
        String[] lines = new String[signTextLength];
        
        for (int i = 0; i < signTextLength; i++) {
          lines[i] =
              sign.signText[i].getFormattedText().replace(TextFormatting.RESET.toString(), "");
        }
        
        String fullText = String.join("\n", lines);
        
        Helper.printMessage("Copied sign");
        setClipboardString(fullText);
      }
    }
  }
}
 
Example #16
Source File: WorldUtils.java    From litematica with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void insertSignTextFromSchematic(TileEntitySign teClient)
{
    WorldSchematic worldSchematic = SchematicWorldHandler.getSchematicWorld();

    if (worldSchematic != null)
    {
        TileEntity te = worldSchematic.getTileEntity(teClient.getPos());

        if (te instanceof TileEntitySign)
        {
            ITextComponent[] textSchematic = ((TileEntitySign) te).signText;
            ITextComponent[] textClient = teClient.signText;

            if (textClient != null && textSchematic != null)
            {
                int size = Math.min(textSchematic.length, textClient.length);

                for (int i = 0; i < size; ++i)
                {
                    if (textSchematic[i] != null)
                    {
                        textClient[i] = textSchematic[i].createCopy();
                    }
                }
            }
        }
    }
}
 
Example #17
Source File: CraftSign.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void applyTo(TileEntitySign sign) {
    super.applyTo(sign);

    ITextComponent[] newLines = sanitizeLines(lines);
    System.arraycopy(newLines, 0, sign.signText, 0, 4);
}
 
Example #18
Source File: CraftSign.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void load(TileEntitySign sign) {
    super.load(sign);

    lines = new String[sign.signText.length];
    System.arraycopy(revertComponents(sign.signText), 0, lines, 0, lines.length);
}
 
Example #19
Source File: MainCommand.java    From mobycraft with Apache License 2.0 4 votes vote down vote up
@SubscribeEvent
public void containerWand(PlayerInteractEvent event) {
	EntityPlayer player = event.entityPlayer;

	if (!event.action.equals(Action.RIGHT_CLICK_BLOCK)
			&& !event.action.equals(Action.LEFT_CLICK_BLOCK)) {
		return;
	}

	if (player.getHeldItem() == null
			|| player.getHeldItem().getItem() != Mobycraft.container_wand) {
		return;
	}

	sender = player;
	World world = event.world;
	BlockPos pos = event.pos;

	if (world.getBlockState(pos).getBlock() != Blocks.wall_sign
			&& world.getBlockState(pos).getBlock() != Blocks.standing_sign) {
		return;
	}

	TileEntitySign sign = (TileEntitySign) world.getTileEntity(pos);

	if (!sign.signText[0].getUnformattedText().contains("Name:")) {
		return;
	}

	String name = sign.signText[1].getUnformattedText().concat(
			sign.signText[2].getUnformattedText().concat(
					sign.signText[3].getUnformattedText()));


	Container container = listCommands.getWithName(name);

	if (container == null) {
		return;
	}

	lifecycleCommands.removeContainer(container.getId());
	sendConfirmMessage("Removed container with name \"" + name + "\"");

	buildCommands.updateContainers(false);
}
 
Example #20
Source File: AdapterSign.java    From OpenPeripheral-Integration with MIT License 4 votes vote down vote up
@Override
public Class<?> getTargetClass() {
	return TileEntitySign.class;
}
 
Example #21
Source File: EntityChaosMonkey.java    From mobycraft with Apache License 2.0 4 votes vote down vote up
/**
 * Called to update the entity's position/logic.
 */
public void onUpdate() {
	super.onUpdate();
	this.motionY *= 0.6000000238418579D;

	if (chaosCountdown > 0) {
		chaosCountdown--;
		return;
	}

	BlockPos pos = this.getPosition();
	BlockPos minPos = buildCommands.getMinPos();
	BlockPos maxPos = buildCommands.getMaxPos();

	int x = pos.getX();
	int y = pos.getY();
	int z = pos.getZ();
	int minX = minPos.getX();
	int minY = minPos.getY();
	int minZ = minPos.getZ();
	int maxX = maxPos.getX();
	int maxY = maxPos.getY();
	int maxZ = maxPos.getZ();

	if (x < minX || y < minY || z < minZ || x > maxX || y > maxY
			|| z > maxZ) {
		this.setLocationAndAngles(Utils.negativeNextInt(minX, maxX),
				Utils.negativeNextInt(minY, maxY), minZ + 8, 0, 0);
	}

	World world = this.worldObj;
	if (world.getTileEntity(this.getPosition()) == null) {
		return;
	}

	TileEntity entity = world.getTileEntity(this.getPosition());
	if (!(entity instanceof TileEntitySign)) {
		return;
	}

	TileEntitySign sign = (TileEntitySign) entity;

	if (!sign.signText[0].getUnformattedText().contains("Name:")) {
		return;
	}

	String name = sign.signText[1].getUnformattedText().concat(
			sign.signText[2].getUnformattedText().concat(
					sign.signText[3].getUnformattedText()));

	if (listCommands.getWithName(name) == null) {
		return;
	}

	Container container = listCommands.getWithName(name);
	lifecycleCommands.removeContainer(container.getId());
	if (!world.isRemote) {
		sendErrorMessage("Oh no! The Chaos Monkey has destroyed the container \""
				+ name + "\"!");
	}

	if (sender instanceof EntityPlayer) {
		((EntityPlayer) sender).inventory
				.addItemStackToInventory(new ItemStack(
						Mobycraft.container_essence, new Random().nextInt(3)));
	}

	chaosCountdown = maxChaosCountdown;

	buildCommands.updateContainers(false);
}
 
Example #22
Source File: AdapterSign.java    From OpenPeripheral-Integration with MIT License 4 votes vote down vote up
private static void updateSign(TileEntitySign sign) {
	sign.getWorldObj().markBlockForUpdate(sign.xCoord, sign.yCoord, sign.zCoord);
}
 
Example #23
Source File: AdapterSign.java    From OpenPeripheral-Integration with MIT License 4 votes vote down vote up
private static void setLine(TileEntitySign sign, final int index, String text) {
	sign.signText[index] = text.length() < 15? text : text.substring(0, 15);
}
 
Example #24
Source File: AdapterSign.java    From OpenPeripheral-Integration with MIT License 4 votes vote down vote up
@ScriptCallable(returnTypes = ReturnType.TABLE, description = "Gets all text as table")
public String[] getLines(TileEntitySign sign) {
	return sign.signText;
}
 
Example #25
Source File: AdapterSign.java    From OpenPeripheral-Integration with MIT License 4 votes vote down vote up
@Asynchronous
@ScriptCallable(returnTypes = ReturnType.STRING, description = "Gets the text on the sign")
public String getText(TileEntitySign sign) {
	return StringUtils.join(sign.signText, '\n');
}
 
Example #26
Source File: CraftSign.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
public CraftSign(final Material material, final TileEntitySign te) {
    super(material, te);
}
 
Example #27
Source File: SellSign.java    From MyTown2 with The Unlicense 4 votes vote down vote up
@Override
public Sign loadData(TileEntitySign tileEntity, NBTBase signData) {
    return new SellSign(tileEntity, (NBTTagCompound) signData);
}
 
Example #28
Source File: CraftSign.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
public CraftSign(final Block block) {
    super(block, TileEntitySign.class);
}
 
Example #29
Source File: LaggerModule.java    From seppuku with GNU General Public License v3.0 4 votes vote down vote up
@Listener
public void onUpdate(EventPlayerUpdate event) {
    if (event.getStage() == EventStageable.EventStage.PRE) {
        switch (this.mode.getValue()) {
            case BOXER:
                for (int i = 0; i <= this.packets.getValue(); i++) {
                    mc.player.connection.sendPacket(new CPacketAnimation(EnumHand.MAIN_HAND));
                }
                break;
            case SWAP:
                for (int i = 0; i <= this.packets.getValue(); i++) {
                    mc.player.connection.sendPacket(new CPacketPlayerDigging(CPacketPlayerDigging.Action.SWAP_HELD_ITEMS, BlockPos.ORIGIN, mc.player.getHorizontalFacing()));
                }
                break;
            case MOVEMENT:
                for (int i = 0; i <= this.packets.getValue(); i++) {
                    final Entity riding = mc.player.getRidingEntity();
                    if (riding != null) {
                        riding.posX = mc.player.posX;
                        riding.posY = mc.player.posY + 1337;
                        riding.posZ = mc.player.posZ;
                        mc.player.connection.sendPacket(new CPacketVehicleMove(riding));
                    }
                }
                break;
            case SIGN:
                for (TileEntity te : mc.world.loadedTileEntityList) {
                    if (te instanceof TileEntitySign) {
                        final TileEntitySign tileEntitySign = (TileEntitySign) te;

                        for (int i = 0; i <= this.packets.getValue(); i++) {
                            mc.player.connection.sendPacket(new CPacketUpdateSign(tileEntitySign.getPos(), new TextComponentString[]{new TextComponentString("give"), new TextComponentString("riga"), new TextComponentString("the"), new TextComponentString("green book")}));
                        }
                    }
                }
                break;
            case NBT:
                final ItemStack itemStack = new ItemStack(Items.WRITABLE_BOOK);
                final NBTTagList pages = new NBTTagList();

                for (int page = 0; page < 50; page++) {
                    pages.appendTag(new NBTTagString("192i9i1jr1fj8fj893fj84ujv8924jv2j4c8j248vj2498u2-894u10fuj0jhv20j204uv902jv90j209vj204vj"));
                }

                final NBTTagCompound tag = new NBTTagCompound();
                tag.setString("author", mc.session.getUsername());
                tag.setString("title", "Crash!");
                tag.setTag("pages", pages);
                itemStack.setTagCompound(tag);

                for (int i = 0; i <= this.packets.getValue(); i++) {
                    mc.player.connection.sendPacket(new CPacketCreativeInventoryAction(0, itemStack));
                    //mc.player.connection.sendPacket(new CPacketClickWindow(0, 0, 0, ClickType.PICKUP, itemStack, (short)0));
                }
                break;
        }
    }
}