TileEntitySign .java

net.minecraft.tileentity.TileEntitySign (class): members: lineBeingEdited, getIsEditable, setEditable, isEditable, getStats, signText, stats, setPlayer.

net.minecraft.tileentityclass232 linescommonextends TileEntity7.2 KB

API Surface (30)

void writeToNBT(NBTTagCompound compound)
void readFromNBT(NBTTagCompound compound)
String getName()
IChatComponent getDisplayName()
void addChatMessage(IChatComponent component)
boolean canCommandSenderUseCommand(int permLevel, String commandName)
BlockPos getPosition()
Vec3 getPositionVector()
World getEntityWorld()
Entity getCommandSenderEntity()
boolean sendCommandFeedback()
void setCommandStat(CommandResultStats.Type type, int amount)
Packet getDescriptionPacket()
boolean func_183000_F()
boolean getIsEditable()
void setEditable(boolean isEditableIn)
void setPlayer(EntityPlayer playerIn)
EntityPlayer getPlayer()
boolean executeCommand(final EntityPlayer playerIn)
String getName()
IChatComponent getDisplayName()
void addChatMessage(IChatComponent component)
boolean canCommandSenderUseCommand(int permLevel, String commandName)
BlockPos getPosition()
Vec3 getPositionVector()
World getEntityWorld()
Entity getCommandSenderEntity()
boolean sendCommandFeedback()
void setCommandStat(CommandResultStats.Type type, int amount)
CommandResultStats getStats()

Fields & Constants (5)

signText
lineBeingEdited
isEditable
player
stats

String literals (1)

"Sign"

Full Source

TileEntitySign.java232 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.tileentity;
2
3
import com.google.gson.JsonParseException;
4
import net.minecraft.command.CommandException;
5
import net.minecraft.command.CommandResultStats;
6
import net.minecraft.command.ICommandSender;
7
import net.minecraft.entity.Entity;
8
import net.minecraft.entity.player.EntityPlayer;
9
import net.minecraft.event.ClickEvent;
10
import net.minecraft.nbt.NBTTagCompound;
11
import net.minecraft.network.Packet;
12
import net.minecraft.network.play.server.S33PacketUpdateSign;
13
import net.minecraft.server.MinecraftServer;
14
import net.minecraft.util.BlockPos;
15
import net.minecraft.util.ChatComponentProcessor;
16
import net.minecraft.util.ChatComponentText;
17
import net.minecraft.util.ChatStyle;
18
import net.minecraft.util.IChatComponent;
19
import net.minecraft.util.Vec3;
20
import net.minecraft.world.World;
21
22
public class TileEntitySign extends TileEntity
23
{
24
    public final IChatComponent[] signText = new IChatComponent[] {new ChatComponentText(""), new ChatComponentText(""), new ChatComponentText(""), new ChatComponentText("")};
25
26
    /**
27
     * The index of the line currently being edited. Only used on client side, but defined on both. Note this is only
28
     * really used when the > < are going to be visible.
29
     */
30
    public int lineBeingEdited = -1;
31
    private boolean isEditable = true;
32
    private EntityPlayer player;
33
    private final CommandResultStats stats = new CommandResultStats();
34
35
    public void writeToNBT(NBTTagCompound compound)
36
    {
37
        super.writeToNBT(compound);
38
39
        for (int i = 0; i < 4; ++i)
40
        {
41
            String s = IChatComponent.Serializer.componentToJson(this.signText[i]);
42
            compound.setString("Text" + (i + 1), s);
43
        }
44
45
        this.stats.writeStatsToNBT(compound);
46
    }
47
48
    public void readFromNBT(NBTTagCompound compound)
49
    {
50
        this.isEditable = false;
51
        super.readFromNBT(compound);
52
        ICommandSender icommandsender = new ICommandSender()
53
        {
54
            public String getName()
55
            {
56
                return "Sign";
57
            }
58
            public IChatComponent getDisplayName()
59
            {
60
                return new ChatComponentText(this.getName());
61
            }
62
            public void addChatMessage(IChatComponent component)
63
            {
64
            }
65
            public boolean canCommandSenderUseCommand(int permLevel, String commandName)
66
            {
67
                return true;
68
            }
69
            public BlockPos getPosition()
70
            {
71
                return TileEntitySign.this.pos;
72
            }
73
            public Vec3 getPositionVector()
74
            {
75
                return new Vec3((double)TileEntitySign.this.pos.getX() + 0.5D, (double)TileEntitySign.this.pos.getY() + 0.5D, (double)TileEntitySign.this.pos.getZ() + 0.5D);
76
            }
77
            public World getEntityWorld()
78
            {
79
                return TileEntitySign.this.worldObj;
80
            }
81
            public Entity getCommandSenderEntity()
82
            {
83
                return null;
84
            }
85
            public boolean sendCommandFeedback()
86
            {
87
                return false;
88
            }
89
            public void setCommandStat(CommandResultStats.Type type, int amount)
90
            {
91
            }
92
        };
93
94
        for (int i = 0; i < 4; ++i)
95
        {
96
            String s = compound.getString("Text" + (i + 1));
97
98
            try
99
            {
100
                IChatComponent ichatcomponent = IChatComponent.Serializer.jsonToComponent(s);
101
102
                try
103
                {
104
                    this.signText[i] = ChatComponentProcessor.processComponent(icommandsender, ichatcomponent, (Entity)null);
105
                }
106
                catch (CommandException var7)
107
                {
108
                    this.signText[i] = ichatcomponent;
109
                }
110
            }
111
            catch (JsonParseException var8)
112
            {
113
                this.signText[i] = new ChatComponentText(s);
114
            }
115
        }
116
117
        this.stats.readStatsFromNBT(compound);
118
    }
119
120
    /**
121
     * Allows for a specialized description packet to be created. This is often used to sync tile entity data from the
122
     * server to the client easily. For example this is used by signs to synchronise the text to be displayed.
123
     */
124
    public Packet getDescriptionPacket()
125
    {
126
        IChatComponent[] aichatcomponent = new IChatComponent[4];
127
        System.arraycopy(this.signText, 0, aichatcomponent, 0, 4);
128
        return new S33PacketUpdateSign(this.worldObj, this.pos, aichatcomponent);
129
    }
130
131
    public boolean func_183000_F()
132
    {
133
        return true;
134
    }
135
136
    public boolean getIsEditable()
137
    {
138
        return this.isEditable;
139
    }
140
141
    /**
142
     * Sets the sign's isEditable flag to the specified parameter.
143
     */
144
    public void setEditable(boolean isEditableIn)
145
    {
146
        this.isEditable = isEditableIn;
147
148
        if (!isEditableIn)
149
        {
150
            this.player = null;
151
        }
152
    }
153
154
    public void setPlayer(EntityPlayer playerIn)
155
    {
156
        this.player = playerIn;
157
    }
158
159
    public EntityPlayer getPlayer()
160
    {
161
        return this.player;
162
    }
163
164
    public boolean executeCommand(final EntityPlayer playerIn)
165
    {
166
        ICommandSender icommandsender = new ICommandSender()
167
        {
168
            public String getName()
169
            {
170
                return playerIn.getName();
171
            }
172
            public IChatComponent getDisplayName()
173
            {
174
                return playerIn.getDisplayName();
175
            }
176
            public void addChatMessage(IChatComponent component)
177
            {
178
            }
179
            public boolean canCommandSenderUseCommand(int permLevel, String commandName)
180
            {
181
                return permLevel <= 2;
182
            }
183
            public BlockPos getPosition()
184
            {
185
                return TileEntitySign.this.pos;
186
            }
187
            public Vec3 getPositionVector()
188
            {
189
                return new Vec3((double)TileEntitySign.this.pos.getX() + 0.5D, (double)TileEntitySign.this.pos.getY() + 0.5D, (double)TileEntitySign.this.pos.getZ() + 0.5D);
190
            }
191
            public World getEntityWorld()
192
            {
193
                return playerIn.getEntityWorld();
194
            }
195
            public Entity getCommandSenderEntity()
196
            {
197
                return playerIn;
198
            }
199
            public boolean sendCommandFeedback()
200
            {
201
                return false;
202
            }
203
            public void setCommandStat(CommandResultStats.Type type, int amount)
204
            {
205
                TileEntitySign.this.stats.setCommandStatScore(this, type, amount);
206
            }
207
        };
208
209
        for (int i = 0; i < this.signText.length; ++i)
210
        {
211
            ChatStyle chatstyle = this.signText[i] == null ? null : this.signText[i].getChatStyle();
212
213
            if (chatstyle != null && chatstyle.getChatClickEvent() != null)
214
            {
215
                ClickEvent clickevent = chatstyle.getChatClickEvent();
216
217
                if (clickevent.getAction() == ClickEvent.Action.RUN_COMMAND)
218
                {
219
                    MinecraftServer.getServer().getCommandManager().executeCommand(icommandsender, clickevent.getValue());
220
                }
221
            }
222
        }
223
224
        return true;
225
    }
226
227
    public CommandResultStats getStats()
228
    {
229
        return this.stats;
230
    }
231
}
232

Deobfuscated MCP 1.8.9 source of TileEntitySign from Marcelektro/MavenMCP-1.8.9 (net/minecraft/tileentity/TileEntitySign.java), stored verbatim.