|
1 | 1 | package twilightforest; |
2 | 2 |
|
3 | | -import com.google.common.collect.ImmutableCollection; |
4 | | -import com.google.common.collect.ImmutableList; |
5 | | -import com.google.common.collect.ImmutableMultimap; |
6 | | -import com.google.common.collect.ImmutableSet; |
| 3 | +import com.google.common.collect.*; |
7 | 4 | import net.minecraft.block.state.IBlockState; |
8 | 5 | import net.minecraft.init.Blocks; |
9 | 6 | import net.minecraft.item.ItemStack; |
|
14 | 11 | import net.minecraftforge.fml.common.event.FMLInterModComms; |
15 | 12 |
|
16 | 13 | public class IMCHandler { |
17 | | - |
18 | 14 | private static final ImmutableSet.Builder<IBlockState> BLACKLIST_BUILDER = ImmutableSet.builder(); |
19 | | - private static final ImmutableList.Builder<IBlockState> HILL_BLOCKS_BUILDER = ImmutableList.builder(); |
| 15 | + private static final ImmutableList.Builder<IBlockState> ORE_BLOCKS_BUILDER = ImmutableList.builder(); |
20 | 16 | private static final ImmutableList.Builder<ItemStack> LOADING_ICONS_BUILDER = ImmutableList.builder(); |
21 | 17 | private static final ImmutableMultimap.Builder<IBlockState, IBlockState> CRUMBLE_BLOCKS_BUILDER = ImmutableMultimap.builder(); |
22 | 18 |
|
23 | | - /* |
| 19 | + /** |
24 | 20 | IMC NBT Format: You can send all of your requests as one big NBT list rather than needing to shotgun a ton of tiny NBT messages. |
25 | 21 |
|
26 | 22 | root: |
27 | 23 | • "Blacklist" - NBTTagList : List of blockstates to blacklist from blockbreaking (antibuilders, naga, hydra, etc) |
28 | 24 | • List Entry - NBTTagCompound : An IBlockState |
29 | 25 | • "Name" - String : Resource location of block. Is not allowed to be Air. |
30 | | - • "Properties" - NBTTagCompound : Additional blockstate modifications to apply to block |
| 26 | + • "Properties" - NBTTagCompound : Blockstate Properties |
31 | 27 | • [String Property Key] - String : Key is nameable to a property key, and the string value attached to it is value to property. |
32 | 28 |
|
33 | | - • "Hollow_Hill" - NBTTagList : List of blockstates to add to hollow hills - May chance this to a function in the future |
| 29 | + • "Ore_Blocks" [NYI] - NBTTagList : List of blockstates to add to Hollow Hills and Ore Magnets - May change this to a function in the future |
34 | 30 | • List Entry - NBTTagCompound : An IBlockState |
35 | 31 | • "Name" - String : Resource location of block. Is not allowed to be Air. |
36 | | - • "Properties" - NBTTagCompound : Additional blockstate modifications to apply to block |
| 32 | + • "Properties" - NBTTagCompound : Blockstate Properties |
37 | 33 | • [String Property Key] - String : Key is nameable to a property key, and the string value attached to it is value to property. |
38 | 34 |
|
39 | 35 | • "Crumbling" - NBTTagList : List of blockstates to add to hollow hills - May chance this to a function in the future |
40 | 36 | • List Entry - NBTTagCompound : An IBlockState |
41 | 37 | • "Name" - String : Resource location of block. Is not allowed to be Air. |
42 | | - • "Properties" - NBTTagCompound : Additional blockstate modifications to apply to block |
| 38 | + • "Properties" - NBTTagCompound : Blockstate Properties |
43 | 39 | • "Crumbles" - NBTTagList : List of different blockstates that the blockstate can crumble into |
44 | 40 | • List Entry - NBTTagCompound : An IBlockState. |
45 | 41 | • "Name" - String : Resource location of block. Can be Air. |
46 | | - • "Properties" - NBTTagCompound : Additional blockstate modifications to apply to block |
| 42 | + • "Properties" - NBTTagCompound : Blockstate Properties |
47 | 43 | • [String Property Key] - String : Key is nameable to a property key, and the string value attached to it is value to property. |
48 | 44 | */ |
49 | 45 |
|
50 | | - public static void handleMessage(FMLInterModComms.IMCMessage message) { |
51 | | - if (message.isNBTMessage()) { |
52 | | - NBTTagCompound imcCompound = message.getNBTValue(); |
53 | | - |
54 | | - deserializeBlockstatesFromTagList(imcCompound.getTagList("Blacklist" , Constants.NBT.TAG_COMPOUND), BLACKLIST_BUILDER ); |
55 | | - deserializeBlockstatesFromTagList(imcCompound.getTagList("Hollow_Hill", Constants.NBT.TAG_COMPOUND), HILL_BLOCKS_BUILDER ); |
| 46 | + public static void onIMC(FMLInterModComms.IMCEvent event) { |
| 47 | + for (FMLInterModComms.IMCMessage message : event.getMessages()) { |
| 48 | + if (message.isNBTMessage()) { |
| 49 | + NBTTagCompound imcCompound = message.getNBTValue(); |
56 | 50 |
|
57 | | - deserializeBlockstatesFromTagList(imcCompound.getTagList("Crumbling" , Constants.NBT.TAG_COMPOUND), CRUMBLE_BLOCKS_BUILDER); |
58 | | - } |
| 51 | + deserializeBlockstatesFromTagList(imcCompound.getTagList("Blacklist" , Constants.NBT.TAG_COMPOUND), BLACKLIST_BUILDER ); |
| 52 | + deserializeBlockstatesFromTagList(imcCompound.getTagList("Ore_Blocks", Constants.NBT.TAG_COMPOUND), ORE_BLOCKS_BUILDER ); |
| 53 | + deserializeBlockstatesFromTagList(imcCompound.getTagList("Crumbling" , Constants.NBT.TAG_COMPOUND), CRUMBLE_BLOCKS_BUILDER ); |
| 54 | + } |
59 | 55 |
|
60 | | - if (message.isItemStackMessage()) { |
61 | | - if (message.key.equals("Loading_Icon")) { |
| 56 | + if (message.isItemStackMessage() && message.key.equals("Loading_Icon")) { |
62 | 57 | LOADING_ICONS_BUILDER.add(message.getItemStackValue()); |
63 | 58 | } |
64 | 59 | } |
@@ -87,42 +82,15 @@ private static void deserializeBlockstatesFromTagList(NBTTagList list, Immutable |
87 | 82 |
|
88 | 83 | if (state.getBlock() != Blocks.AIR) |
89 | 84 | builder.add(state); |
90 | | - |
91 | | - //Block block = Block.REGISTRY.getObject(new ResourceLocation(compound.getString("name"))); |
92 | | - |
93 | | - //if (block != Blocks.AIR) { |
94 | | - // IBlockState blockState = block.getStateFromMeta(compound.getInteger("meta")); |
95 | | - |
96 | | - // BlockStateContainer stateContainer = block.getBlockState(); |
97 | | - |
98 | | - // NBTTagList properties = compound.getTagList("state", Constants.NBT.TAG_COMPOUND); |
99 | | - // for (int stateAt = 0; stateAt < properties.tagCount(); stateAt++) { |
100 | | - // NBTTagCompound property = properties.getCompoundTagAt(stateAt); |
101 | | - |
102 | | - // IProperty prop = stateContainer.getProperty(property.getString("property")); |
103 | | - |
104 | | - // if (prop != null) |
105 | | - // blockState = applyBlockStateProperty(blockState, prop, prop.getValueClass(), prop.parseValue(property.getString("value"))); |
106 | | - // } |
107 | | - |
108 | | - // builder.add(blockState); |
109 | | - //} |
110 | 85 | } |
111 | 86 | } |
112 | 87 |
|
113 | | - /*private <V extends Comparable<V>> IBlockState applyBlockStateProperty(IBlockState state, IProperty<V> property, Class<V> target, Optional optional) { |
114 | | - if (optional.isPresent() && target.isInstance(optional.get())) |
115 | | - return state.withProperty(property, (V) optional.get()); |
116 | | - else |
117 | | - return state; |
118 | | - }*/ |
119 | | - |
120 | 88 | public static ImmutableSet<IBlockState> getBlacklistedBlocks() { |
121 | 89 | return BLACKLIST_BUILDER.build(); |
122 | 90 | } |
123 | 91 |
|
124 | | - public static ImmutableList<IBlockState> getHollowHillBlocks() { |
125 | | - return HILL_BLOCKS_BUILDER.build(); |
| 92 | + public static ImmutableList<IBlockState> getOreBlocks() { |
| 93 | + return ORE_BLOCKS_BUILDER.build(); |
126 | 94 | } |
127 | 95 |
|
128 | 96 | public static ImmutableList<ItemStack> getLoadingIconStacks() { |
|
0 commit comments