11package twilightforest ;
22
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 .*;
74import net .minecraft .block .state .IBlockState ;
85import net .minecraft .init .Blocks ;
96import net .minecraft .item .ItemStack ;
1411import net .minecraftforge .fml .common .event .FMLInterModComms ;
1512
1613public class IMCHandler {
17-
1814 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 ();
2016 private static final ImmutableList .Builder <ItemStack > LOADING_ICONS_BUILDER = ImmutableList .builder ();
2117 private static final ImmutableMultimap .Builder <IBlockState , IBlockState > CRUMBLE_BLOCKS_BUILDER = ImmutableMultimap .builder ();
2218
23- /*
19+ /**
2420 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.
2521
2622 root:
2723 • "Blacklist" - NBTTagList : List of blockstates to blacklist from blockbreaking (antibuilders, naga, hydra, etc)
2824 • List Entry - NBTTagCompound : An IBlockState
2925 • "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
3127 • [String Property Key] - String : Key is nameable to a property key, and the string value attached to it is value to property.
3228
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
3430 • List Entry - NBTTagCompound : An IBlockState
3531 • "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
3733 • [String Property Key] - String : Key is nameable to a property key, and the string value attached to it is value to property.
3834
3935 • "Crumbling" - NBTTagList : List of blockstates to add to hollow hills - May chance this to a function in the future
4036 • List Entry - NBTTagCompound : An IBlockState
4137 • "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
4339 • "Crumbles" - NBTTagList : List of different blockstates that the blockstate can crumble into
4440 • List Entry - NBTTagCompound : An IBlockState.
4541 • "Name" - String : Resource location of block. Can be Air.
46- • "Properties" - NBTTagCompound : Additional blockstate modifications to apply to block
42+ • "Properties" - NBTTagCompound : Blockstate Properties
4743 • [String Property Key] - String : Key is nameable to a property key, and the string value attached to it is value to property.
4844 */
4945
50- public static void handleMessage (FMLInterModComms .IMCMessage message ) {
51- if (message .isNBTMessage ()) {
52- NBTTagCompound imcCompound = message .getNBTValue ();
46+ public void handleMessage (FMLInterModComms .IMCEvent event ) {
47+ for (FMLInterModComms .IMCMessage message : event .getMessages ()) {
48+ if (message .isNBTMessage ()) {
49+ NBTTagCompound imcCompound = message .getNBTValue ();
5350
54- deserializeBlockstatesFromTagList (imcCompound .getTagList ("Blacklist" , Constants .NBT .TAG_COMPOUND ), BLACKLIST_BUILDER );
55- deserializeBlockstatesFromTagList (imcCompound .getTagList ("Hollow_Hill" , Constants .NBT .TAG_COMPOUND ), HILL_BLOCKS_BUILDER );
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+ }
5655
57- deserializeBlockstatesFromTagList (imcCompound .getTagList ("Crumbling" , Constants .NBT .TAG_COMPOUND ), CRUMBLE_BLOCKS_BUILDER );
56+ if (message .isItemStackMessage () && message .key .equals ("Loading_Icon" )) {
57+ LOADING_ICONS_BUILDER .add (message .getItemStackValue ());
58+ }
5859 }
60+ }
5961
60- if (message .isItemStackMessage ()) {
61- if (message .key .equals ("Loading_Icon" )) {
62- LOADING_ICONS_BUILDER .add (message .getItemStackValue ());
62+ private void deserializeBlockstatesFromTagList (NBTTagList list , ImmutableBiMap .Builder <IBlockState , Integer > builder ) {
63+ for (int blockAt = 0 ; blockAt < list .tagCount (); blockAt ++) {
64+ NBTTagCompound main = list .getCompoundTagAt (blockAt );
65+ IBlockState key = NBTUtil .readBlockState (main );
66+
67+ if (key .getBlock () != Blocks .AIR ) {
68+ builder .put (key , main .getInteger ("" ));
6369 }
6470 }
6571 }
6672
67- private static void deserializeBlockstatesFromTagList (NBTTagList list , ImmutableMultimap .Builder <IBlockState , IBlockState > builder ) {
73+ private void deserializeBlockstatesFromTagList (NBTTagList list , ImmutableMultimap .Builder <IBlockState , IBlockState > builder ) {
6874 for (int blockAt = 0 ; blockAt < list .tagCount (); blockAt ++) {
6975 NBTTagCompound main = list .getCompoundTagAt (blockAt );
7076 IBlockState key = NBTUtil .readBlockState (main );
@@ -81,48 +87,21 @@ private static void deserializeBlockstatesFromTagList(NBTTagList list, Immutable
8187 }
8288 }
8389
84- private static void deserializeBlockstatesFromTagList (NBTTagList list , ImmutableCollection .Builder <IBlockState > builder ) {
90+ private void deserializeBlockstatesFromTagList (NBTTagList list , ImmutableCollection .Builder <IBlockState > builder ) {
8591 for (int blockAt = 0 ; blockAt < list .tagCount (); blockAt ++) {
8692 IBlockState state = NBTUtil .readBlockState (list .getCompoundTagAt (blockAt ));
8793
8894 if (state .getBlock () != Blocks .AIR )
8995 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- //}
11096 }
11197 }
11298
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-
12099 public static ImmutableSet <IBlockState > getBlacklistedBlocks () {
121100 return BLACKLIST_BUILDER .build ();
122101 }
123102
124- public static ImmutableList <IBlockState > getHollowHillBlocks () {
125- return HILL_BLOCKS_BUILDER .build ();
103+ public static ImmutableList <IBlockState > getOreBlocks () {
104+ return ORE_BLOCKS_BUILDER .build ();
126105 }
127106
128107 public static ImmutableList <ItemStack > getLoadingIconStacks () {
0 commit comments