Move helper methods to separate jar

main
azurelmao 2 years ago
parent 4ec6692f18
commit 0896650df7

@ -45,6 +45,8 @@ dependencies {
modImplementation("org.apache.commons:commons-lang3:3.12.0")
include("org.apache.commons:commons-lang3:3.12.0")
modImplementation files("libs/halplibe-1.0.0.jar")
}
java {

Binary file not shown.

@ -1,32 +0,0 @@
package azurelmao.examplemod.helper;
import azurelmao.examplemod.mixin.helper.RenderPlayerInterface;
import net.minecraft.src.helper.DamageType;
import net.minecraft.src.material.ArmorMaterial;
import org.apache.commons.lang3.ArrayUtils;
public class ArmorHelper {
/**
* @param textureName name of the armor texture file.
* @param durability durability of your armor. Will be different than in-game due to how it gets allocated between armor pieces.
* @param combat combat damage reduction in percent. Can be more than 100.
* @param blast blast damage reduction in percent.
* @param fire fire damage reduction in percent.
* @param fall fall damage reduction in percent.
* @return the new ArmorMaterial.
*/
public static ArmorMaterial createArmorMaterial(String textureName, int durability, float combat, float blast, float fire, float fall) {
String[] armorFilenamePrefix = RenderPlayerInterface.getArmorFilenamePrefix();
armorFilenamePrefix = ArrayUtils.add(armorFilenamePrefix, textureName);
RenderPlayerInterface.setArmorFilenamePrefix(armorFilenamePrefix);
ArmorMaterial armorMaterial = new ArmorMaterial(textureName, armorFilenamePrefix.length - 1, durability);
ArmorMaterial.setProtectionValuePercent(armorMaterial, DamageType.COMBAT, combat);
ArmorMaterial.setProtectionValuePercent(armorMaterial, DamageType.BLAST, blast);
ArmorMaterial.setProtectionValuePercent(armorMaterial, DamageType.FIRE, fire);
ArmorMaterial.setProtectionValuePercent(armorMaterial, DamageType.FALL, fall);
return armorMaterial;
}
}

@ -1,56 +0,0 @@
package azurelmao.examplemod.helper;
import azurelmao.examplemod.mixin.helper.BlockInterface;
import net.minecraft.src.Block;
import net.minecraft.src.Item;
import net.minecraft.src.ItemBlock;
import net.minecraft.src.Material;
import net.minecraft.src.StepSound;
public class BlockHelper {
public static Block createBlock(int id, String name, int x, int y, Material material, StepSound stepSound, float hardness, float resistance, float lightValue) {
Block block = new Block(id, material);
block.setTexCoords(x, y);
block.setBlockName(name);
((BlockInterface) block).callSetHardness(hardness);
((BlockInterface) block).callSetResistance(resistance);
((BlockInterface) block).callSetStepSound(stepSound);
((BlockInterface) block).callSetLightValue(lightValue);
Item.itemsList[block.blockID] = new ItemBlock(block.blockID - Block.blocksList.length);
return block;
}
public static Block createBlock(int id, String name, int topX, int topY, int bottomX, int bottomY, int sidesX, int sidesY, Material material, StepSound stepSound, float hardness, float resistance, float lightValue) {
Block block = new Block(id, material);
block.setTexCoords(topX, topY, bottomX, bottomY, sidesX, sidesY);
block.setBlockName(name);
((BlockInterface) block).callSetHardness(hardness);
((BlockInterface) block).callSetResistance(resistance);
((BlockInterface) block).callSetStepSound(stepSound);
((BlockInterface) block).callSetLightValue(lightValue);
Item.itemsList[block.blockID] = new ItemBlock(block.blockID - Block.blocksList.length);
return block;
}
public static Block createBlock(int id, String name, int topX, int topY, int bottomX, int bottomY, int northX, int northY, int eastX, int eastY, int southX, int southY, int westX, int westY, Material material, StepSound stepSound, float hardness, float resistance, float lightValue) {
Block block = new Block(id, material);
block.setTexCoords(topX, topY, bottomX, bottomY, northX, northY, eastX, eastY, southX, southY, westX, westY);
block.setBlockName(name);
((BlockInterface) block).callSetHardness(hardness);
((BlockInterface) block).callSetResistance(resistance);
((BlockInterface) block).callSetStepSound(stepSound);
((BlockInterface) block).callSetLightValue(lightValue);
Item.itemsList[block.blockID] = new ItemBlock(block.blockID - Block.blocksList.length);
return block;
}
}

@ -1,18 +0,0 @@
package azurelmao.examplemod.helper;
import azurelmao.examplemod.mixin.helper.DimensionInterface;
import net.minecraft.src.Block;
import net.minecraft.src.Dimension;
import net.minecraft.src.WorldType;
import java.util.Arrays;
public class DimensionHelper {
public static Dimension createDimension(int id, String name, Dimension homeDimension, float worldScale, Block portalBlock, WorldType worldType, int minY, int maxY) {
Dimension[] extendedList = Arrays.copyOf(Dimension.dimensionList, Dimension.dimensionList.length + 1);
DimensionInterface.setDimensionList(extendedList);
return new Dimension(id, name, homeDimension, worldScale, portalBlock.blockID).setWorldType(worldType).setBounds(minY, maxY);
}
}

@ -1,19 +0,0 @@
package azurelmao.examplemod.helper;
import azurelmao.examplemod.mixin.helper.EntityListInterface;
import azurelmao.examplemod.mixin.helper.RenderManagerInterface;
import net.minecraft.src.Render;
import net.minecraft.src.RenderManager;
import java.util.Map;
public class EntityHelper {
public static void createEntity(Class clazz, Render render, int id, String name) {
Map entityRenderMap = ((RenderManagerInterface) RenderManager.instance).getEntityRenderMap();
entityRenderMap.put(clazz, render);
render.setRenderManager(RenderManager.instance);
EntityListInterface.callAddMapping(clazz, name, id);
}
}

@ -1,15 +0,0 @@
package azurelmao.examplemod.helper;
import net.minecraft.src.EntityFX;
import java.util.HashMap;
import java.util.Map;
public class ParticleHelper {
public static Map<String, Class<? extends EntityFX>> particles = new HashMap<>();
public static void createParticle(Class<? extends EntityFX> clazz, String name) {
particles.put(name, clazz);
}
}

@ -1,168 +0,0 @@
package azurelmao.examplemod.helper;
import azurelmao.examplemod.ExampleMod;
import azurelmao.examplemod.mixin.helper.CraftingManagerInterface;
import azurelmao.examplemod.mixin.helper.RecipesBlastFurnaceInterface;
import azurelmao.examplemod.mixin.helper.RecipesFurnaceInterface;
import net.minecraft.src.*;
import java.util.List;
import java.util.Map;
public class RecipeHelper {
public static final CraftingManager craftingManager = CraftingManager.getInstance();
public static final RecipesFurnace smeltingManager = RecipesFurnace.smelting();
public static final RecipesBlastFurnace blastingManager = RecipesBlastFurnace.smelting();
public static class Crafting {
public static void createRecipe(Item outputItem, int amount, Object[] aobj) {
((CraftingManagerInterface) craftingManager).callAddRecipe(new ItemStack(outputItem, amount), aobj);
}
public static void createRecipe(Block outputBlock, int amount, Object[] aobj) {
((CraftingManagerInterface) craftingManager).callAddRecipe(new ItemStack(outputBlock, amount), aobj);
}
public static void createShapelessRecipe(Item outputItem, int amount, Object[] aobj) {
((CraftingManagerInterface) craftingManager).callAddShapelessRecipe(new ItemStack(outputItem, amount), aobj);
}
public static void createShapelessRecipe(Block outputBlock, int amount, Object[] aobj) {
((CraftingManagerInterface) craftingManager).callAddShapelessRecipe(new ItemStack(outputBlock, amount), aobj);
}
public static void removeRecipe(Item outputItem) {
List recipes = craftingManager.getRecipeList();
IRecipe theRecipe = null;
for (Object recipe : recipes) {
if (recipe instanceof RecipeShaped && ((RecipeShaped) recipe).recipeOutput.itemID == outputItem.itemID) {
theRecipe = (IRecipe) recipe;
break;
}
else if (recipe instanceof RecipeShapeless && ((RecipeShapeless) recipe).recipeOutput.itemID == outputItem.itemID) {
theRecipe = (IRecipe) recipe;
break;
}
}
if (theRecipe == null) {
ExampleMod.LOGGER.info("Couldn't find recipe with output: " + outputItem.getItemName());
return;
}
recipes.remove(theRecipe);
((CraftingManagerInterface) craftingManager).setRecipes(recipes);
}
public static void removeRecipe(Block outputBlock) {
List recipes = craftingManager.getRecipeList();
IRecipe theRecipe = null;
for (Object recipe : recipes) {
if (recipe instanceof RecipeShaped && ((RecipeShaped) recipe).recipeOutput.itemID == outputBlock.blockID) {
theRecipe = (IRecipe) recipe;
break;
}
else if (recipe instanceof RecipeShapeless && ((RecipeShapeless) recipe).recipeOutput.itemID == outputBlock.blockID) {
theRecipe = (IRecipe) recipe;
break;
}
}
if (theRecipe == null) {
ExampleMod.LOGGER.info("Couldn't find crafting recipe with output: " + outputBlock.getBlockName(0));
return;
}
recipes.remove(theRecipe);
((CraftingManagerInterface) craftingManager).setRecipes(recipes);
}
}
public static class Smelting {
public static void createRecipe(Item outputItem, Item inputItem) {
smeltingManager.addSmelting(inputItem.itemID, new ItemStack(outputItem));
}
public static void createRecipe(Item outputItem, Block inputItem) {
smeltingManager.addSmelting(inputItem.blockID, new ItemStack(outputItem));
}
public static void createRecipe(Block outputItem, Item inputItem) {
smeltingManager.addSmelting(inputItem.itemID, new ItemStack(outputItem));
}
public static void createRecipe(Block outputItem, Block inputItem) {
smeltingManager.addSmelting(inputItem.blockID, new ItemStack(outputItem));
}
public static void removeRecipe(Item inputItem) {
Map recipes = smeltingManager.getSmeltingList();
if (recipes.containsKey(inputItem)) {
ExampleMod.LOGGER.info("Couldn't find smelting recipe with input: " + inputItem.getItemName());
return;
}
recipes.remove(inputItem);
((RecipesFurnaceInterface) smeltingManager).setSmeltingList(recipes);
}
public static void removeRecipe(Block inputItem) {
Map recipes = smeltingManager.getSmeltingList();
if (recipes.containsKey(inputItem)) {
ExampleMod.LOGGER.info("Couldn't find smelting recipe with input: " + inputItem.getBlockName(0));
return;
}
recipes.remove(inputItem);
((RecipesFurnaceInterface) smeltingManager).setSmeltingList(recipes);
}
}
public static class Blasting {
public static void createRecipe(Item outputItem, Item inputItem) {
blastingManager.addSmelting(inputItem.itemID, new ItemStack(outputItem));
}
public static void createRecipe(Item outputItem, Block inputItem) {
blastingManager.addSmelting(inputItem.blockID, new ItemStack(outputItem));
}
public static void createRecipe(Block outputItem, Item inputItem) {
blastingManager.addSmelting(inputItem.itemID, new ItemStack(outputItem));
}
public static void createRecipe(Block outputItem, Block inputItem) {
blastingManager.addSmelting(inputItem.blockID, new ItemStack(outputItem));
}
public static void removeRecipe(Item inputItem) {
Map recipes = blastingManager.getSmeltingList();
if (recipes.containsKey(inputItem)) {
ExampleMod.LOGGER.info("Couldn't find blasting recipe with input: " + inputItem.getItemName());
return;
}
recipes.remove(inputItem);
((RecipesBlastFurnaceInterface) blastingManager).setSmeltingList(recipes);
}
public static void removeRecipe(Block inputItem) {
Map recipes = blastingManager.getSmeltingList();
if (recipes.containsKey(inputItem)) {
ExampleMod.LOGGER.info("Couldn't find blasting recipe with input: " + inputItem.getBlockName(0));
return;
}
recipes.remove(inputItem);
((RecipesBlastFurnaceInterface) blastingManager).setSmeltingList(recipes);
}
}
}

@ -1,24 +0,0 @@
package azurelmao.examplemod.mixin.fix;
import net.minecraft.server.MinecraftServer;
import net.minecraft.src.Dimension;
import net.minecraft.src.EntityTracker;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(value = MinecraftServer.class, remap = false)
public class MinecraftServerMixin {
// Mixin to fix custom dimensions on multiplayer
@Shadow
public EntityTracker[] entityTracker;
@Inject(method = "startServer", at = @At(value = "HEAD"))
private void examplemod_startServer(CallbackInfoReturnable<Boolean> cir) {
entityTracker = new EntityTracker[Dimension.dimensionList.length];
}
}

@ -1,22 +0,0 @@
package azurelmao.examplemod.mixin.helper;
import net.minecraft.src.Block;
import net.minecraft.src.StepSound;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Invoker;
@Mixin(value = Block.class, remap = false)
public interface BlockInterface {
@Invoker("setHardness")
Block callSetHardness(float f);
@Invoker("setResistance")
Block callSetResistance(float f);
@Invoker("setStepSound")
Block callSetStepSound(StepSound stepSound);
@Invoker("setLightValue")
Block callSetLightValue(float f);
}

@ -1,22 +0,0 @@
package azurelmao.examplemod.mixin.helper;
import net.minecraft.src.CraftingManager;
import net.minecraft.src.ItemStack;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
import org.spongepowered.asm.mixin.gen.Invoker;
import java.util.List;
@Mixin(value = CraftingManager.class, remap = false)
public interface CraftingManagerInterface {
@Invoker("addRecipe")
void callAddRecipe(ItemStack itemstack, Object[] aobj);
@Invoker("addShapelessRecipe")
void callAddShapelessRecipe(ItemStack itemstack, Object[] aobj);
@Accessor("recipes")
void setRecipes(List list);
}

@ -1,14 +0,0 @@
package azurelmao.examplemod.mixin.helper;
import net.minecraft.src.Dimension;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
@Mixin(value = Dimension.class, remap = false)
public interface DimensionInterface {
@Accessor("dimensionList")
static void setDimensionList(Dimension[] list) {
throw new AssertionError();
}
}

@ -1,14 +0,0 @@
package azurelmao.examplemod.mixin.helper;
import net.minecraft.src.EntityList;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Invoker;
@Mixin(value = EntityList.class, remap = false)
public interface EntityListInterface {
@Invoker("addMapping")
static void callAddMapping(Class clazz, String name, int id) {
throw new AssertionError();
}
}

@ -1,14 +0,0 @@
package azurelmao.examplemod.mixin.helper;
import net.minecraft.src.RecipesBlastFurnace;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
import java.util.Map;
@Mixin(value = RecipesBlastFurnace.class, remap = false)
public interface RecipesBlastFurnaceInterface {
@Accessor("smeltingList")
void setSmeltingList(Map map);
}

@ -1,14 +0,0 @@
package azurelmao.examplemod.mixin.helper;
import net.minecraft.src.RecipesFurnace;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
import java.util.Map;
@Mixin(value = RecipesFurnace.class, remap = false)
public interface RecipesFurnaceInterface {
@Accessor("smeltingList")
void setSmeltingList(Map map);
}

@ -1,51 +0,0 @@
package azurelmao.examplemod.mixin.helper;
import azurelmao.examplemod.helper.ParticleHelper;
import net.minecraft.client.Minecraft;
import net.minecraft.src.EntityFX;
import net.minecraft.src.RenderGlobal;
import net.minecraft.src.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.util.Map;
@Mixin(value = RenderGlobal.class, remap = false)
public class RenderGlobalMixin {
@Shadow
private Minecraft mc;
@Shadow
private World worldObj;
@Inject(method = "spawnParticle", at = @At(value = "RETURN"))
private void examplemod_spawnParticle(String s, double x, double y, double z, double motionX, double motionY, double motionZ, CallbackInfo ci) {
if (mc != null && mc.renderViewEntity != null && mc.effectRenderer != null) {
double d6 = this.mc.renderViewEntity.posX - x;
double d7 = this.mc.renderViewEntity.posY - y;
double d8 = this.mc.renderViewEntity.posZ - z;
double d9 = 16.0;
if (!(d6 * d6 + d7 * d7 + d8 * d8 > d9 * d9)) {
Map<String, Class<? extends EntityFX>> particles = ParticleHelper.particles;
for (String name : particles.keySet()) {
if (s.equals(name)) {
Class<? extends EntityFX> clazz = particles.get(name);
try {
mc.effectRenderer.addEffect(clazz.getDeclaredConstructor(World.class, double.class, double.class, double.class, double.class, double.class, double.class).newInstance(worldObj, x, y, z, motionX, motionY, motionZ));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
}
}
}
}

@ -1,14 +0,0 @@
package azurelmao.examplemod.mixin.helper;
import net.minecraft.src.RenderManager;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
import java.util.Map;
@Mixin(value = RenderManager.class, remap = false)
public interface RenderManagerInterface {
@Accessor("entityRenderMap")
Map getEntityRenderMap();
}

@ -1,19 +0,0 @@
package azurelmao.examplemod.mixin.helper;
import net.minecraft.src.RenderPlayer;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
@Mixin(value = RenderPlayer.class, remap = false)
public interface RenderPlayerInterface {
@Accessor("armorFilenamePrefix")
static String[] getArmorFilenamePrefix() {
throw new AssertionError();
}
@Accessor("armorFilenamePrefix")
static void setArmorFilenamePrefix(String[] strings) {
throw new AssertionError();
}
}

@ -1,14 +0,0 @@
package azurelmao.examplemod.mixin.helper;
import net.minecraft.src.TileEntity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Invoker;
@Mixin(value = TileEntity.class, remap = false)
public interface TileEntityInterface {
@Invoker("addMapping")
static void callAddMapping(Class clazz, String s) {
throw new AssertionError();
}
}
Loading…
Cancel
Save