TileEntityBanner .java

net.minecraft.tileentity.TileEntityBanner (class): members: getPatternResourceLocation, patternResourceLocation, setBaseColorAndPatterns, removeBannerData.

net.minecraft.tileentityclass324 linescommonextends TileEntity11.7 KB

API Surface (20)

void setItemValues(ItemStack stack)
void writeToNBT(NBTTagCompound compound)
void setBaseColorAndPatterns(NBTTagCompound compound, int baseColorIn, NBTTagList patternsIn)
void readFromNBT(NBTTagCompound compound)
Packet getDescriptionPacket()
int getBaseColor()
int getBaseColor(ItemStack stack)
int getPatterns(ItemStack stack)
List<TileEntityBanner.EnumBannerPattern> getPatternList()
NBTTagList getPatterns()
List<EnumDyeColor> getColorList()
String getPatternResourceLocation()
void removeBannerData(ItemStack stack)
String getPatternName()
String getPatternID()
String[] getCraftingLayers()
boolean hasValidCrafting()
boolean hasCraftingStack()
ItemStack getCraftingStack()
TileEntityBanner.EnumBannerPattern getPatternByID(String id)

Fields & Constants (6)

baseColor
patterns
field_175119_g
patternList
colorList
patternResourceLocation

String literals (44)

"BlockEntityTag"
"Patterns"
"Base"
"Pattern"
"Color"
"base"
"square_bottom_left"
"square_bottom_right"
"square_top_left"
"square_top_right"
"stripe_bottom"
"stripe_top"
"stripe_left"
"stripe_right"
"stripe_center"
"stripe_middle"
"stripe_downright"
"stripe_downleft"
"small_stripes"
"cross"
"straight_cross"
"triangle_bottom"
"triangle_top"
"triangles_bottom"

Full Source

TileEntityBanner.java324 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.tileentity;
2
3
import com.google.common.collect.Lists;
4
import java.util.List;
5
import net.minecraft.block.BlockFlower;
6
import net.minecraft.init.Blocks;
7
import net.minecraft.init.Items;
8
import net.minecraft.item.EnumDyeColor;
9
import net.minecraft.item.ItemStack;
10
import net.minecraft.nbt.NBTTagCompound;
11
import net.minecraft.nbt.NBTTagList;
12
import net.minecraft.network.Packet;
13
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
14
15
public class TileEntityBanner extends TileEntity
16
{
17
    private int baseColor;
18
19
    /** A list of all the banner patterns. */
20
    private NBTTagList patterns;
21
    private boolean field_175119_g;
22
    private List<TileEntityBanner.EnumBannerPattern> patternList;
23
    private List<EnumDyeColor> colorList;
24
25
    /**
26
     * This is a String representation of this banners pattern and color lists, used for texture caching.
27
     */
28
    private String patternResourceLocation;
29
30
    public void setItemValues(ItemStack stack)
31
    {
32
        this.patterns = null;
33
34
        if (stack.hasTagCompound() && stack.getTagCompound().hasKey("BlockEntityTag", 10))
35
        {
36
            NBTTagCompound nbttagcompound = stack.getTagCompound().getCompoundTag("BlockEntityTag");
37
38
            if (nbttagcompound.hasKey("Patterns"))
39
            {
40
                this.patterns = (NBTTagList)nbttagcompound.getTagList("Patterns", 10).copy();
41
            }
42
43
            if (nbttagcompound.hasKey("Base", 99))
44
            {
45
                this.baseColor = nbttagcompound.getInteger("Base");
46
            }
47
            else
48
            {
49
                this.baseColor = stack.getMetadata() & 15;
50
            }
51
        }
52
        else
53
        {
54
            this.baseColor = stack.getMetadata() & 15;
55
        }
56
57
        this.patternList = null;
58
        this.colorList = null;
59
        this.patternResourceLocation = "";
60
        this.field_175119_g = true;
61
    }
62
63
    public void writeToNBT(NBTTagCompound compound)
64
    {
65
        super.writeToNBT(compound);
66
        setBaseColorAndPatterns(compound, this.baseColor, this.patterns);
67
    }
68
69
    public static void setBaseColorAndPatterns(NBTTagCompound compound, int baseColorIn, NBTTagList patternsIn)
70
    {
71
        compound.setInteger("Base", baseColorIn);
72
73
        if (patternsIn != null)
74
        {
75
            compound.setTag("Patterns", patternsIn);
76
        }
77
    }
78
79
    public void readFromNBT(NBTTagCompound compound)
80
    {
81
        super.readFromNBT(compound);
82
        this.baseColor = compound.getInteger("Base");
83
        this.patterns = compound.getTagList("Patterns", 10);
84
        this.patternList = null;
85
        this.colorList = null;
86
        this.patternResourceLocation = null;
87
        this.field_175119_g = true;
88
    }
89
90
    /**
91
     * Allows for a specialized description packet to be created. This is often used to sync tile entity data from the
92
     * server to the client easily. For example this is used by signs to synchronise the text to be displayed.
93
     */
94
    public Packet getDescriptionPacket()
95
    {
96
        NBTTagCompound nbttagcompound = new NBTTagCompound();
97
        this.writeToNBT(nbttagcompound);
98
        return new S35PacketUpdateTileEntity(this.pos, 6, nbttagcompound);
99
    }
100
101
    public int getBaseColor()
102
    {
103
        return this.baseColor;
104
    }
105
106
    public static int getBaseColor(ItemStack stack)
107
    {
108
        NBTTagCompound nbttagcompound = stack.getSubCompound("BlockEntityTag", false);
109
        return nbttagcompound != null && nbttagcompound.hasKey("Base") ? nbttagcompound.getInteger("Base") : stack.getMetadata();
110
    }
111
112
    /**
113
     * Retrieves the amount of patterns stored on an ItemStack. If the tag does not exist this value will be 0.
114
     */
115
    public static int getPatterns(ItemStack stack)
116
    {
117
        NBTTagCompound nbttagcompound = stack.getSubCompound("BlockEntityTag", false);
118
        return nbttagcompound != null && nbttagcompound.hasKey("Patterns") ? nbttagcompound.getTagList("Patterns", 10).tagCount() : 0;
119
    }
120
121
    public List<TileEntityBanner.EnumBannerPattern> getPatternList()
122
    {
123
        this.initializeBannerData();
124
        return this.patternList;
125
    }
126
127
    public NBTTagList getPatterns()
128
    {
129
        return this.patterns;
130
    }
131
132
    public List<EnumDyeColor> getColorList()
133
    {
134
        this.initializeBannerData();
135
        return this.colorList;
136
    }
137
138
    public String getPatternResourceLocation()
139
    {
140
        this.initializeBannerData();
141
        return this.patternResourceLocation;
142
    }
143
144
    /**
145
     * Establishes all of the basic properties for the banner. This will also apply the data from the tile entities nbt
146
     * tag compounds.
147
     */
148
    private void initializeBannerData()
149
    {
150
        if (this.patternList == null || this.colorList == null || this.patternResourceLocation == null)
151
        {
152
            if (!this.field_175119_g)
153
            {
154
                this.patternResourceLocation = "";
155
            }
156
            else
157
            {
158
                this.patternList = Lists.<TileEntityBanner.EnumBannerPattern>newArrayList();
159
                this.colorList = Lists.<EnumDyeColor>newArrayList();
160
                this.patternList.add(TileEntityBanner.EnumBannerPattern.BASE);
161
                this.colorList.add(EnumDyeColor.byDyeDamage(this.baseColor));
162
                this.patternResourceLocation = "b" + this.baseColor;
163
164
                if (this.patterns != null)
165
                {
166
                    for (int i = 0; i < this.patterns.tagCount(); ++i)
167
                    {
168
                        NBTTagCompound nbttagcompound = this.patterns.getCompoundTagAt(i);
169
                        TileEntityBanner.EnumBannerPattern tileentitybanner$enumbannerpattern = TileEntityBanner.EnumBannerPattern.getPatternByID(nbttagcompound.getString("Pattern"));
170
171
                        if (tileentitybanner$enumbannerpattern != null)
172
                        {
173
                            this.patternList.add(tileentitybanner$enumbannerpattern);
174
                            int j = nbttagcompound.getInteger("Color");
175
                            this.colorList.add(EnumDyeColor.byDyeDamage(j));
176
                            this.patternResourceLocation = this.patternResourceLocation + tileentitybanner$enumbannerpattern.getPatternID() + j;
177
                        }
178
                    }
179
                }
180
            }
181
        }
182
    }
183
184
    /**
185
     * Removes all the banner related data from a provided instance of ItemStack.
186
     */
187
    public static void removeBannerData(ItemStack stack)
188
    {
189
        NBTTagCompound nbttagcompound = stack.getSubCompound("BlockEntityTag", false);
190
191
        if (nbttagcompound != null && nbttagcompound.hasKey("Patterns", 9))
192
        {
193
            NBTTagList nbttaglist = nbttagcompound.getTagList("Patterns", 10);
194
195
            if (nbttaglist.tagCount() > 0)
196
            {
197
                nbttaglist.removeTag(nbttaglist.tagCount() - 1);
198
199
                if (nbttaglist.hasNoTags())
200
                {
201
                    stack.getTagCompound().removeTag("BlockEntityTag");
202
203
                    if (stack.getTagCompound().hasNoTags())
204
                    {
205
                        stack.setTagCompound((NBTTagCompound)null);
206
                    }
207
                }
208
            }
209
        }
210
    }
211
212
    public static enum EnumBannerPattern
213
    {
214
        BASE("base", "b"),
215
        SQUARE_BOTTOM_LEFT("square_bottom_left", "bl", "   ", "   ", "#  "),
216
        SQUARE_BOTTOM_RIGHT("square_bottom_right", "br", "   ", "   ", "  #"),
217
        SQUARE_TOP_LEFT("square_top_left", "tl", "#  ", "   ", "   "),
218
        SQUARE_TOP_RIGHT("square_top_right", "tr", "  #", "   ", "   "),
219
        STRIPE_BOTTOM("stripe_bottom", "bs", "   ", "   ", "###"),
220
        STRIPE_TOP("stripe_top", "ts", "###", "   ", "   "),
221
        STRIPE_LEFT("stripe_left", "ls", "#  ", "#  ", "#  "),
222
        STRIPE_RIGHT("stripe_right", "rs", "  #", "  #", "  #"),
223
        STRIPE_CENTER("stripe_center", "cs", " # ", " # ", " # "),
224
        STRIPE_MIDDLE("stripe_middle", "ms", "   ", "###", "   "),
225
        STRIPE_DOWNRIGHT("stripe_downright", "drs", "#  ", " # ", "  #"),
226
        STRIPE_DOWNLEFT("stripe_downleft", "dls", "  #", " # ", "#  "),
227
        STRIPE_SMALL("small_stripes", "ss", "# #", "# #", "   "),
228
        CROSS("cross", "cr", "# #", " # ", "# #"),
229
        STRAIGHT_CROSS("straight_cross", "sc", " # ", "###", " # "),
230
        TRIANGLE_BOTTOM("triangle_bottom", "bt", "   ", " # ", "# #"),
231
        TRIANGLE_TOP("triangle_top", "tt", "# #", " # ", "   "),
232
        TRIANGLES_BOTTOM("triangles_bottom", "bts", "   ", "# #", " # "),
233
        TRIANGLES_TOP("triangles_top", "tts", " # ", "# #", "   "),
234
        DIAGONAL_LEFT("diagonal_left", "ld", "## ", "#  ", "   "),
235
        DIAGONAL_RIGHT("diagonal_up_right", "rd", "   ", "  #", " ##"),
236
        DIAGONAL_LEFT_MIRROR("diagonal_up_left", "lud", "   ", "#  ", "## "),
237
        DIAGONAL_RIGHT_MIRROR("diagonal_right", "rud", " ##", "  #", "   "),
238
        CIRCLE_MIDDLE("circle", "mc", "   ", " # ", "   "),
239
        RHOMBUS_MIDDLE("rhombus", "mr", " # ", "# #", " # "),
240
        HALF_VERTICAL("half_vertical", "vh", "## ", "## ", "## "),
241
        HALF_HORIZONTAL("half_horizontal", "hh", "###", "###", "   "),
242
        HALF_VERTICAL_MIRROR("half_vertical_right", "vhr", " ##", " ##", " ##"),
243
        HALF_HORIZONTAL_MIRROR("half_horizontal_bottom", "hhb", "   ", "###", "###"),
244
        BORDER("border", "bo", "###", "# #", "###"),
245
        CURLY_BORDER("curly_border", "cbo", new ItemStack(Blocks.vine)),
246
        CREEPER("creeper", "cre", new ItemStack(Items.skull, 1, 4)),
247
        GRADIENT("gradient", "gra", "# #", " # ", " # "),
248
        GRADIENT_UP("gradient_up", "gru", " # ", " # ", "# #"),
249
        BRICKS("bricks", "bri", new ItemStack(Blocks.brick_block)),
250
        SKULL("skull", "sku", new ItemStack(Items.skull, 1, 1)),
251
        FLOWER("flower", "flo", new ItemStack(Blocks.red_flower, 1, BlockFlower.EnumFlowerType.OXEYE_DAISY.getMeta())),
252
        MOJANG("mojang", "moj", new ItemStack(Items.golden_apple, 1, 1));
253
254
        private String patternName;
255
        private String patternID;
256
        private String[] craftingLayers;
257
        private ItemStack patternCraftingStack;
258
259
        private EnumBannerPattern(String name, String id)
260
        {
261
            this.craftingLayers = new String[3];
262
            this.patternName = name;
263
            this.patternID = id;
264
        }
265
266
        private EnumBannerPattern(String name, String id, ItemStack craftingItem)
267
        {
268
            this(name, id);
269
            this.patternCraftingStack = craftingItem;
270
        }
271
272
        private EnumBannerPattern(String name, String id, String craftingTop, String craftingMid, String craftingBot)
273
        {
274
            this(name, id);
275
            this.craftingLayers[0] = craftingTop;
276
            this.craftingLayers[1] = craftingMid;
277
            this.craftingLayers[2] = craftingBot;
278
        }
279
280
        public String getPatternName()
281
        {
282
            return this.patternName;
283
        }
284
285
        public String getPatternID()
286
        {
287
            return this.patternID;
288
        }
289
290
        public String[] getCraftingLayers()
291
        {
292
            return this.craftingLayers;
293
        }
294
295
        public boolean hasValidCrafting()
296
        {
297
            return this.patternCraftingStack != null || this.craftingLayers[0] != null;
298
        }
299
300
        public boolean hasCraftingStack()
301
        {
302
            return this.patternCraftingStack != null;
303
        }
304
305
        public ItemStack getCraftingStack()
306
        {
307
            return this.patternCraftingStack;
308
        }
309
310
        public static TileEntityBanner.EnumBannerPattern getPatternByID(String id)
311
        {
312
            for (TileEntityBanner.EnumBannerPattern tileentitybanner$enumbannerpattern : values())
313
            {
314
                if (tileentitybanner$enumbannerpattern.patternID.equals(id))
315
                {
316
                    return tileentitybanner$enumbannerpattern;
317
                }
318
            }
319
320
            return null;
321
        }
322
    }
323
}
324

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