-Added Goggle enchantment

This commit is contained in:
makeo committed 2015-12-28 21:32:07 +01:00
1 parent 16984d4c16
commit cf96529de9
10 files changed
+398 -25

No files matched your search

@@ -1,5 +1,6 @@
package makeo.gadomancy.client.renderers.tile;
import makeo.gadomancy.common.events.EventHandlerRedirect;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
@@ -186,7 +187,12 @@ public class RenderTileNodeBasic {
//Gadomancy: Added dynamic size
public static void renderTileEntityAt(TileEntity tile, double x, double y, double z, float partialTicks, float size) {
//Gadomancy Added event hook
EventHandlerRedirect.preNodeRender(tile);
if (!(tile instanceof INode)) {
//Gadomancy Added event hook
EventHandlerRedirect.postNodeRender(tile);
return;
}
INode node = (INode) tile;
@@ -217,6 +223,9 @@ public class RenderTileNodeBasic {
if (((drainEntity instanceof EntityPlayer)) && (!((EntityPlayer) drainEntity).isUsingItem())) {
((TileNode) tile).drainEntity = null;
((TileNode) tile).drainCollision = null;
//Gadomancy Added event hook
EventHandlerRedirect.postNodeRender(tile);
return;
}
MovingObjectPosition drainCollision = ((TileNode) tile).drainCollision;
@@ -241,6 +250,9 @@ public class RenderTileNodeBasic {
GL11.glPopMatrix();
}
//Gadomancy Added event hook
EventHandlerRedirect.postNodeRender(tile);
}
}
@@ -15,19 +15,12 @@ import makeo.gadomancy.common.events.EventHandlerGolem;
import makeo.gadomancy.common.events.EventHandlerNetwork;
import makeo.gadomancy.common.events.EventHandlerWorld;
import makeo.gadomancy.common.network.PacketHandler;
import makeo.gadomancy.common.registration.ModSubstitutions;
import makeo.gadomancy.common.registration.RegisteredBlocks;
import makeo.gadomancy.common.registration.RegisteredEntities;
import makeo.gadomancy.common.registration.RegisteredGolemStuff;
import makeo.gadomancy.common.registration.RegisteredIntegrations;
import makeo.gadomancy.common.registration.RegisteredItems;
import makeo.gadomancy.common.registration.RegisteredPotions;
import makeo.gadomancy.common.registration.RegisteredRecipes;
import makeo.gadomancy.common.registration.RegisteredResearches;
import makeo.gadomancy.common.registration.*;
import makeo.gadomancy.common.utils.Injector;
import makeo.gadomancy.common.utils.world.WorldProviderTCEldrich;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.inventory.IInventory;
import net.minecraft.world.World;
import net.minecraftforge.common.DimensionManager;
@@ -77,6 +70,7 @@ public class CommonProxy implements IGuiHandler {
AuraEffects.AER.getTickInterval(); //initalize AuraEffects
RegisteredEnchantments.init();
RegisteredRecipes.init();
SyncDataHolder.initialize();
@@ -0,0 +1,204 @@
package makeo.gadomancy.common.blocks.tiles;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.ModContainer;
import cpw.mods.fml.common.network.NetworkRegistry;
import makeo.gadomancy.common.entities.fake.AdvancedFakePlayer;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.server.management.ItemInWorldManager;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraftforge.common.util.ForgeDirection;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
/**
* This class is part of the Gadomancy Mod
* Gadomancy is Open Source and distributed under the
* GNU LESSER GENERAL PUBLIC LICENSE
* for more read the LICENSE file
* <p/>
* Created by makeo @ 16.12.2015 11:50
*/
public class TileArcaneHand extends SynchronizedTileEntity implements IInventory, ISidedInventory {
private GuiFakePlayer fakePlayer;
private ItemInWorldManager im = null;
private Container container = null;
private List<Slot> slots = null;
@Override
public void updateEntity() {
if(im == null) {
updateConnection();
}
}
public void updateConnection() {
container = null;
slots = null;
if (im == null) {
im = new ItemInWorldManager(worldObj);
} else {
im.setWorld((WorldServer) worldObj);
}
TileEntity tile = getWorldObj().getTileEntity(xCoord, yCoord - 1, zCoord);
if (tile != null && worldObj instanceof WorldServer) {
if(fakePlayer == null) {
fakePlayer = new GuiFakePlayer(this);
}
fakePlayer.posX = xCoord;
fakePlayer.posY = yCoord;
fakePlayer.posZ = zCoord;
this.im.activateBlockOrUseItem(fakePlayer, worldObj, null, xCoord, yCoord - 1, zCoord, ForgeDirection.UP.ordinal(), 0.5F, 0.5F, 0.5F);
}
}
@Override
public int[] getAccessibleSlotsFromSide(int side) {
if(container == null) {
return new int[0];
}
int[] slots = new int[this.slots.size()];
for(int i = 0; i < slots.length; i++) {
slots[i] = i;
}
return slots;
}
@Override
public boolean canInsertItem(int slot, ItemStack stack, int side) {
return slots.get(slot).isItemValid(stack);
}
@Override
public boolean canExtractItem(int slot, ItemStack stack, int side) {
return slots.get(slot).canTakeStack(fakePlayer);
}
private static class GuiFakePlayer extends AdvancedFakePlayer {
private TileArcaneHand tile;
public GuiFakePlayer(TileArcaneHand tile) {
super((WorldServer) tile.worldObj, UUID.randomUUID(), "ArcaneHand");
this.tile = tile;
}
public void openGui(Object mod, int modGuiId, World world, int x, int y, int z) {
ModContainer mc = FMLCommonHandler.instance().findContainerFor(mod);
tile.container = NetworkRegistry.INSTANCE.getRemoteGuiContainer(mc, this, modGuiId, world, x, y, z);
if (tile.container != null) {
tile.slots = new ArrayList<Slot>();
for (Slot slot : (List<Slot>) tile.container.inventorySlots) {
if(!inventory.equals(slot.inventory)) {
tile.slots.add(slot);
}
}
}
}
}
@Override
public void readCustomNBT(NBTTagCompound compound) {
super.readCustomNBT(compound);
}
@Override
public void writeCustomNBT(NBTTagCompound compound) {
super.writeCustomNBT(compound);
}
@Override
public int getSizeInventory() {
return slots.size();
}
@Override
public ItemStack getStackInSlot(int slot) {
return slots.get(slot).getStack();
}
@Override
public ItemStack decrStackSize(int slot, int amount) {
Slot s = slots.get(slot);
if (s.getStack() != null) {
ItemStack itemstack;
if (s.getStack().stackSize <= amount) {
itemstack = s.getStack();
s.putStack(null);
this.markDirty();
return itemstack;
} else {
itemstack = s.getStack().splitStack(amount);
if (s.getStack().stackSize == 0) {
s.putStack(null);
}
this.markDirty();
return itemstack;
}
}
return null;
}
@Override
public ItemStack getStackInSlotOnClosing(int slot) {
return null;
}
@Override
public void setInventorySlotContents(int slot, ItemStack stack) {
slots.get(slot).putStack(stack);
}
@Override
public String getInventoryName() {
return "";
}
@Override
public boolean hasCustomInventoryName() {
return false;
}
@Override
public int getInventoryStackLimit() {
return 64;
}
@Override
public boolean isUseableByPlayer(EntityPlayer player) {
return false;
}
@Override
public void openInventory() {
}
@Override
public void closeInventory() {
}
@Override
public boolean isItemValidForSlot(int p_94041_1_, ItemStack p_94041_2_) {
return true;
}
}
@@ -67,11 +67,20 @@ public class ModConfig {
renderParticleDistance = config.getInt("particleRenderDistance", "general", 100, 5, 1000, "Defines, how close a player has to be towards the particle origin to see the particles created by it.");
enableAdditionalNodeTypes = config.getBoolean("enableAdditionalNodeTypes", "general", true, "Enables our custom node types. This might solve some compatibility issues (e.g. WitchingGadgets). You have to change this client- and server-side! Only change when you experience issues with special mods' features ONLY not working when using the mod together with Gadomancy.");
config.addCustomCategoryComment("potions", "Use the following if you have problems with conflicting potion ids. If the entry is set to '-1' it will try to automatically find a free potion id.");
config.addCustomCategoryComment("potions", "Use the following if you have problems with conflicting potion ids. If the entry is set to '-1' it will try to automatically find the lowest free potion id.");
config.addCustomCategoryComment("enchantments", "Use the following if you have problems with conflicting enchantment ids. If the entry is set to '-1' it will try to automatically find the lowest free enchantments id.");
}
public static int loadPotionId(String name) {
Property prop = config.get("potions", name, -1);
return loadId("potions", name);
}
public static int loadEnchantmentId(String name) {
return loadId("enchantments", name);
}
public static int loadId(String category, String name) {
Property prop = config.get(category, name, -1);
prop.setLanguageKey(name);
int result = prop.getInt(-1);
return result < -1 ? -1 : result;
@@ -0,0 +1,39 @@
package makeo.gadomancy.common.enchantments;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnumEnchantmentType;
import net.minecraft.item.ItemStack;
/**
* This class is part of the Gadomancy Mod
* Gadomancy is Open Source and distributed under the
* GNU LESSER GENERAL PUBLIC LICENSE
* for more read the LICENSE file
* <p/>
* Created by makeo @ 28.12.2015 16:15
*/
public class EnchantmentRevealer extends Enchantment {
public EnchantmentRevealer(int id) {
super(id, 1, EnumEnchantmentType.armor_head);
}
@Override
public String getName() {
return "gadomancy.enchantment.revealer";
}
@Override
public boolean canApplyAtEnchantingTable(ItemStack stack) {
return false;
}
@Override
public int getMinEnchantability(int p_77321_1_) {
return 15;
}
@Override
public int getMaxEnchantability(int p_77317_1_) {
return super.getMinEnchantability(p_77317_1_) + 50;
}
}
@@ -1,14 +1,22 @@
package makeo.gadomancy.common.events;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import makeo.gadomancy.common.registration.RegisteredEnchantments;
import makeo.gadomancy.common.registration.RegisteredPotions;
import net.minecraft.client.Minecraft;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.server.MinecraftServer;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.client.event.DrawBlockHighlightEvent;
import thaumcraft.api.aspects.Aspect;
import thaumcraft.common.config.ConfigItems;
import java.util.List;
@@ -21,13 +29,48 @@ import java.util.List;
* Created by HellFirePvP @ 15.12.2015 14:57
*/
public class EventHandlerRedirect {
public static void preNodeRender(TileEntity tile) {
//postNodeRender(tile);
System.out.print("");
private static final ItemStack ITEM_GOGGLES = new ItemStack(ConfigItems.itemGoggles);
private static boolean hasChanged = false;
private static ItemStack oldItem;
public static void addGoggles(Entity entity) {
if(entity instanceof EntityPlayer && hasGoggles((EntityPlayer) entity)) {
ItemStack[] armorInv = ((EntityPlayer)entity).inventory.armorInventory;
oldItem = armorInv[3];
hasChanged = true;
armorInv[3] = ITEM_GOGGLES;
}
}
public static void removeGoggles(Entity entity) {
if(hasChanged && entity instanceof EntityPlayer) {
((EntityPlayer)entity).inventory.armorInventory[3] = oldItem;
oldItem = null;
hasChanged = false;
}
}
private static boolean hasGoggles(EntityPlayer player) {
ItemStack stack = player.inventory.armorItemInSlot(3);
return stack != null && EnchantmentHelper.getEnchantmentLevel(RegisteredEnchantments.revealer.effectId, stack) > 0;
}
@SideOnly(Side.CLIENT)
public static void preNodeRender(TileEntity tile) {
addGoggles(Minecraft.getMinecraft().renderViewEntity);
}
@SideOnly(Side.CLIENT)
public static void postNodeRender(TileEntity tile) {
System.out.print("");
removeGoggles(Minecraft.getMinecraft().renderViewEntity);
}
public static void preBlockHighlight(DrawBlockHighlightEvent event) {
addGoggles(event.player);
}
public static void postBlockHighlight(DrawBlockHighlightEvent event) {
removeGoggles(event.player);
}
public static int getAdditionalVisDiscount(EntityPlayer player, Aspect aspect, int currentTotalDiscount) {
@@ -0,0 +1,40 @@
package makeo.gadomancy.common.registration;
import makeo.gadomancy.common.Gadomancy;
import makeo.gadomancy.common.data.config.ModConfig;
import makeo.gadomancy.common.enchantments.EnchantmentRevealer;
import makeo.gadomancy.common.utils.Injector;
import net.minecraft.enchantment.Enchantment;
/**
* This class is part of the Gadomancy Mod
* Gadomancy is Open Source and distributed under the
* GNU LESSER GENERAL PUBLIC LICENSE
* for more read the LICENSE file
* <p/>
* Created by makeo @ 28.12.2015 15:52
*/
public class RegisteredEnchantments {
public static EnchantmentRevealer revealer;
public static void init() {
revealer = registerEnchantment(EnchantmentRevealer.class);
}
public static <T extends Enchantment> T registerEnchantment(Class<T> enchClass) {
int id = ModConfig.loadEnchantmentId(enchClass.getSimpleName());
if(id == -1) {
id = getUnassignedId(enchClass);
}
return new Injector(enchClass).invokeConstructor(int.class, id);
}
private static int getUnassignedId(Class<? extends Enchantment> enchClass) {
for(int i = 0; i < Enchantment.enchantmentsList.length; i++) {
if(Enchantment.enchantmentsList[i] == null) {
return i;
}
}
throw new RuntimeException("Failed to find free id for " + Gadomancy.NAME + " enchantment (" + enchClass.getName() + ")! Please consider using the config option to change the enchantment id.");
}
}
@@ -20,10 +20,7 @@ import net.minecraft.item.crafting.IRecipe;
import thaumcraft.api.ThaumcraftApi;
import thaumcraft.api.aspects.Aspect;
import thaumcraft.api.aspects.AspectList;
import thaumcraft.api.crafting.CrucibleRecipe;
import thaumcraft.api.crafting.IArcaneRecipe;
import thaumcraft.api.crafting.InfusionRecipe;
import thaumcraft.api.crafting.ShapedArcaneRecipe;
import thaumcraft.api.crafting.*;
import thaumcraft.common.config.Config;
import thaumcraft.common.config.ConfigBlocks;
import thaumcraft.common.config.ConfigItems;
@@ -84,6 +81,8 @@ public class RegisteredRecipes {
public static IArcaneRecipe recipeAuraPylonPeak;
public static IArcaneRecipe recipeArcanePackager;
public static InfusionEnchantmentRecipe recipeRevealer;
public static void init() {
AdditionalGolemType typeSilverwood = RegisteredGolemStuff.typeSilverwood;
recipeGolemSilverwood = ThaumcraftApi.addInfusionCraftingRecipe(SimpleResearchItem.getFullName("GOLEMSILVERWOOD"),
@@ -232,6 +231,8 @@ public class RegisteredRecipes {
auraCoreRecipes = createAuraCoreRecipes();
ThaumcraftApi.getCraftingRecipes().add(new InfusionDisguiseArmor());
recipeRevealer = ThaumcraftApi.addInfusionEnchantmentRecipe("", RegisteredEnchantments.revealer, 4, new AspectList().add(Aspect.SENSES, 16).add(Aspect.MAGIC, 8), new ItemStack[]{new ItemStack(ConfigItems.itemGoggles), new ItemStack(ConfigItems.itemResource, 1, 14), new ItemStack(ConfigItems.itemResource, 1, 14)});
}
private static List[] createAuraCoreRecipes() {
@@ -22,13 +22,15 @@ public class GadomancyTransformer extends AccessTransformer {
public static final String NAME_ENCHANTMENT_HELPER = "net.minecraft.enchantment.EnchantmentHelper";
public static final String NAME_WANDMANAGER = "thaumcraft.common.items.wands.WandManager";
public static final String NAME_NODE_RENDERER = "thaumcraft.client.renderers.tile.TileNodeRenderer";
public static final String NAME_RENDER_EVENT_HANDLER = "thaumcraft.client.lib.RenderEventHandler";
public GadomancyTransformer() throws IOException {}
@Override
public byte[] transform(String name, String transformedName, byte[] bytes) {
boolean needsTransform = name.equalsIgnoreCase(NAME_ENCHANTMENT_HELPER) ||
name.equalsIgnoreCase(NAME_WANDMANAGER) || name.equalsIgnoreCase(NAME_NODE_RENDERER);
name.equalsIgnoreCase(NAME_WANDMANAGER) || name.equalsIgnoreCase(NAME_NODE_RENDERER)
|| name.equalsIgnoreCase(NAME_RENDER_EVENT_HANDLER);
if(!needsTransform) return super.transform(name, transformedName, bytes);
ClassNode node = new ClassNode();
@@ -79,14 +81,41 @@ public class GadomancyTransformer extends AccessTransformer {
mn.instructions.insertBefore(mn.instructions.get(0), setBefore);
InsnList setAfter = new InsnList();
AbstractInsnNode next = mn.instructions.get(0);
while(next != null) {
AbstractInsnNode insnNode = next;
next = insnNode.getNext();
if(insnNode.getOpcode() == Opcodes.RETURN) {
InsnList setAfter = new InsnList();
setAfter.add(new VarInsnNode(Opcodes.ALOAD, 1));
setAfter.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "makeo/gadomancy/common/events/EventHandlerRedirect",
"postNodeRender", "(Lnet/minecraft/tileentity/TileEntity;)V", false));
mn.instructions.insertBefore(insnNode, setAfter);
}
}
}
}
} else if(name.equalsIgnoreCase(NAME_RENDER_EVENT_HANDLER)) {
for(MethodNode mn : node.methods) {
if (mn.name.equals("blockHighlight")) {
InsnList setBefore = new InsnList();
setBefore.add(new VarInsnNode(Opcodes.ALOAD, 1));
setBefore.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "makeo/gadomancy/common/events/EventHandlerRedirect",
"postNodeRender", "(Lnet/minecraft/tileentity/TileEntity;)V", false));
"preBlockHighlight", "(Lnet/minecraftforge/client/event/DrawBlockHighlightEvent;)V", false));
mn.instructions.insertBefore(mn.instructions.get(0), setBefore);
AbstractInsnNode next = mn.instructions.get(0);
while(next != null) {
AbstractInsnNode insnNode = next;
next = insnNode.getNext();
for(int i = 0; i < mn.instructions.size(); i++) {
AbstractInsnNode insnNode = mn.instructions.get(i);
if(insnNode.getOpcode() == Opcodes.RETURN) {
InsnList setAfter = new InsnList();
setAfter.add(new VarInsnNode(Opcodes.ALOAD, 1));
setAfter.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "makeo/gadomancy/common/events/EventHandlerRedirect",
"postBlockHighlight", "(Lnet/minecraftforge/client/event/DrawBlockHighlightEvent;)V", false));
mn.instructions.insertBefore(insnNode, setAfter);
}
}