Skip to content

Commit e567e42

Browse files
committed
Let's do this properly
1 parent c0c9163 commit e567e42

File tree

2 files changed

+20
-54
lines changed

2 files changed

+20
-54
lines changed

src/main/java/twilightforest/IMCHandler.java

Lines changed: 19 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package 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.*;
74
import net.minecraft.block.state.IBlockState;
85
import net.minecraft.init.Blocks;
96
import net.minecraft.item.ItemStack;
@@ -14,51 +11,49 @@
1411
import net.minecraftforge.fml.common.event.FMLInterModComms;
1512

1613
public 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();
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();
5650

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+
}
5955

60-
if (message.isItemStackMessage()) {
61-
if (message.key.equals("Loading_Icon")) {
56+
if (message.isItemStackMessage() && message.key.equals("Loading_Icon")) {
6257
LOADING_ICONS_BUILDER.add(message.getItemStackValue());
6358
}
6459
}
@@ -87,42 +82,15 @@ private static void deserializeBlockstatesFromTagList(NBTTagList list, Immutable
8782

8883
if (state.getBlock() != Blocks.AIR)
8984
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-
//}
11085
}
11186
}
11287

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-
12088
public static ImmutableSet<IBlockState> getBlacklistedBlocks() {
12189
return BLACKLIST_BUILDER.build();
12290
}
12391

124-
public static ImmutableList<IBlockState> getHollowHillBlocks() {
125-
return HILL_BLOCKS_BUILDER.build();
92+
public static ImmutableList<IBlockState> getOreBlocks() {
93+
return ORE_BLOCKS_BUILDER.build();
12694
}
12795

12896
public static ImmutableList<ItemStack> getLoadingIconStacks() {

src/main/java/twilightforest/TwilightForestMod.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,7 @@ public void postInit(FMLPostInitializationEvent evt) {
149149

150150
@EventHandler
151151
public void onIMC(FMLInterModComms.IMCEvent event) {
152-
for (FMLInterModComms.IMCMessage message : event.getMessages()) {
153-
IMCHandler.handleMessage(message);
154-
}
152+
IMCHandler.onIMC(event);
155153
}
156154

157155
@EventHandler

0 commit comments

Comments
 (0)