-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'Cleptomania/metadatav2' into dev
- Loading branch information
Showing
14 changed files
with
334 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
// Add your dependencies here | ||
|
||
dependencies { | ||
|
||
api("com.github.GTNewHorizons:GTNHLib:0.2.3:dev") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,25 @@ | ||
package com.gtnewhorizons.neid; | ||
|
||
import com.gtnewhorizon.gtnhlib.config.ConfigException; | ||
import com.gtnewhorizon.gtnhlib.config.ConfigurationManager; | ||
|
||
import cpw.mods.fml.common.Mod; | ||
import cpw.mods.fml.common.event.FMLPreInitializationEvent; | ||
|
||
@Mod(modid = "neid", name = "NotEnoughIDs", version = Tags.VERSION, dependencies = "after:battlegear2@[1.3.0,);") | ||
@Mod( | ||
modid = "neid", | ||
name = "NotEnoughIDs", | ||
version = Tags.VERSION, | ||
dependencies = "after:battlegear2@[1.3.0,);" + " required-after:gtnhlib@[0.2.1,);") | ||
public class NEID { | ||
|
||
@Mod.EventHandler | ||
public void preInit(FMLPreInitializationEvent event) { | ||
try { | ||
ConfigurationManager.registerConfig(NEIDConfig.class); | ||
} catch (ConfigException e) { | ||
throw new RuntimeException("Failed to register NotEnoughIDs config!"); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,24 @@ | ||
package com.gtnewhorizons.neid; | ||
|
||
import java.io.File; | ||
|
||
import net.minecraft.launchwrapper.Launch; | ||
import net.minecraftforge.common.config.Configuration; | ||
import com.gtnewhorizon.gtnhlib.config.Config; | ||
|
||
/** | ||
* The modid registered here is uppercased, this differs from the actual mod id in that the real one is lowercase. This | ||
* is done because the old pre GTNHLib config file was named uppercase, so we're just keeping that. | ||
*/ | ||
@Config(modid = "NEID", category = "neid") | ||
public class NEIDConfig { | ||
|
||
static Configuration config; | ||
public static boolean catchUnregisteredBlocks; | ||
public static boolean removeInvalidBlocks; | ||
public static boolean postNeidWorldsSupport; | ||
public static boolean extendDataWatcher; | ||
@Config.Comment("Causes a crash when a block has not been registered(e.g. has an id of -1)") | ||
public static boolean CatchUnregisteredBlocks = false; | ||
|
||
@Config.Comment("Remove invalid (corrupted) blocks from the game.") | ||
public static boolean RemoveInvalidBlocks = false; | ||
|
||
@Config.Comment("If true, only blocks with IDs > 4095 will disappear after removing NEID. Metadatas outside of the range 0-15 will be set to 0.") | ||
public static boolean PostNeidWorldsSupport = true; | ||
|
||
@Config.Comment("Extend DataWatch IDs. Vanilla limit is 31, new limit is 127.") | ||
public static boolean ExtendDataWatcher = false; | ||
|
||
static { | ||
NEIDConfig.config = new Configuration(new File(Launch.minecraftHome, "config/NEID.cfg")); | ||
NEIDConfig.catchUnregisteredBlocks = NEIDConfig.config.getBoolean("CatchUnregisteredBlocks", "NEID", false, ""); | ||
NEIDConfig.removeInvalidBlocks = NEIDConfig.config | ||
.getBoolean("RemoveInvalidBlocks", "NEID", false, "Remove invalid (corrupted) blocks from the game."); | ||
NEIDConfig.postNeidWorldsSupport = NEIDConfig.config.getBoolean( | ||
"PostNeidWorldsSupport", | ||
"NEID", | ||
true, | ||
"If true, only blocks with IDs > 4095 will disappear after removing NEID."); | ||
NEIDConfig.extendDataWatcher = NEIDConfig.config.getBoolean( | ||
"ExtendDataWatcher", | ||
"NEID", | ||
false, | ||
"Extend DataWatcher IDs. Vanilla limit is 31, new limit is 127."); | ||
NEIDConfig.config.save(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
src/main/java/com/gtnewhorizons/neid/mixins/early/minecraft/MixinBlock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package com.gtnewhorizons.neid.mixins.early.minecraft; | ||
|
||
import net.minecraft.block.Block; | ||
import net.minecraft.init.Blocks; | ||
|
||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Overwrite; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.Unique; | ||
|
||
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; | ||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; | ||
|
||
/** | ||
* This mixin exists to completely re-work the way that block harvestability is calculated. Forge adds this system | ||
* on-top of vanilla, which creates a pre-populated array on each block with the size of the maximum metadata value. For | ||
* instance, in vanilla we get a String array, and an int array both of size 16, pre-populated with null and -1, | ||
* respectively. This is awful for scalability with adding more possible Blocks, and increasing the metadata to 16-bits | ||
* from 4. This uproots the under-workings of that system to use a default and dynamic HashMaps for metadata specific | ||
* values, so we only use the memory we need, because most things don't even take advantage of this system, especially | ||
* based on block metadatas. The public methods of this system maintain API compatibility, so anything using those | ||
* should still function perfectly the same. The only potential breakage is if something were to reflect/ASM/mixin with | ||
* the private values/methods we're overwriting. | ||
*/ | ||
@Mixin(Block.class) | ||
public class MixinBlock { | ||
|
||
@Unique | ||
private String neid$defaultHarvestTool = null; | ||
|
||
@Unique | ||
private int neid$defaultHarvestLevel = -1; | ||
|
||
@Unique | ||
private Int2ObjectOpenHashMap<String> harvestToolMap = new Int2ObjectOpenHashMap<>(); | ||
|
||
@Unique | ||
private Int2IntOpenHashMap harvestLevelMap = new Int2IntOpenHashMap(); | ||
|
||
@Shadow(remap = false) | ||
private String[] harvestTool = null; | ||
|
||
@Shadow(remap = false) | ||
private int[] harvestLevel = null; | ||
|
||
/** | ||
* @author Cleptomania | ||
* @reason Support 16-bit metadata without using GBs of memory. Classdump of full GTNH shows nothing else | ||
* ASMing/mixin to this. | ||
*/ | ||
@Overwrite(remap = false) | ||
public void setHarvestLevel(String toolClass, int level) { | ||
this.neid$defaultHarvestTool = toolClass; | ||
this.neid$defaultHarvestLevel = level; | ||
} | ||
|
||
/** | ||
* @author Cleptomania | ||
* @reason Support 16-bit metadata without using GBs of memory. Classdump of full GTNH shows nothing else | ||
* ASMing/mixin to this. | ||
*/ | ||
@Overwrite(remap = false) | ||
public void setHarvestLevel(String toolClass, int level, int metadata) { | ||
this.harvestToolMap.put(metadata, toolClass); | ||
this.harvestLevelMap.put(metadata, level); | ||
} | ||
|
||
/** | ||
* @author Cleptomania | ||
* @reason Support 16-bit metadata without using GBs of memory. Classdump of full GTNH shows nothing else | ||
* ASMing/mixin to this. | ||
*/ | ||
@Overwrite(remap = false) | ||
public String getHarvestTool(int metadata) { | ||
return this.harvestToolMap.getOrDefault(metadata, this.neid$defaultHarvestTool); | ||
} | ||
|
||
/** | ||
* @author Cleptmania | ||
* @reason Support 16-bit metadata without using GBs of memory. Classdump of full GTNH shows nothing else | ||
* ASMing/mixin to this. | ||
*/ | ||
@Overwrite(remap = false) | ||
public int getHarvestLevel(int metadata) { | ||
return this.harvestLevelMap.getOrDefault(metadata, this.neid$defaultHarvestLevel); | ||
} | ||
|
||
/** | ||
* @author Cleptomania | ||
* @reason Support 16-bit metadata without using GBs of memory. Classdump of full GTNH shows nothing else | ||
* ASMing/mixin to this. | ||
*/ | ||
@Overwrite(remap = false) | ||
public boolean isToolEffective(String type, int metadata) { | ||
Block self = ((Block) (Object) this); | ||
if ("pickaxe".equals(type) | ||
&& (self == Blocks.redstone_ore || self == Blocks.lit_redstone_ore || self == Blocks.obsidian)) | ||
return false; | ||
String harvestTool = this.getHarvestTool(metadata); | ||
if (harvestTool == null) return false; | ||
return harvestTool.equals(type); | ||
} | ||
|
||
} |
Oops, something went wrong.