uploaded src

This commit is contained in:
makeo committed 2015-10-19 20:52:53 +02:00
1 parent de120fbdea
commit 425cc32981
125 files changed
+9746

No files matched your search

@@ -0,0 +1,50 @@
package makeo.gadomancy.api;
import net.minecraft.block.Block;
import net.minecraft.world.World;
/**
* 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
*
* Created by makeo @ 11.10.2015 12:09
*/
public abstract class ClickBehavior {
protected World world;
protected Block block;
protected int x, y, z, metadata;
protected boolean hasVisCost;
public ClickBehavior(boolean hasVisCost) {
this.hasVisCost = hasVisCost;
}
public ClickBehavior() {
this(false);
}
@Deprecated
public void init(World world, Block block, int x, int y, int z, int metadata) {
this.world = world;
this.block = block;
this.x = x;
this.y = y;
this.z = z;
this.metadata = metadata;
}
public abstract boolean isValidForBlock();
public boolean hasVisCost() {
return hasVisCost;
}
public int getComparatorOutput() {
return 0;
}
public void addInstability(int instability) { }
}
@@ -0,0 +1,73 @@
package makeo.gadomancy.api;
import makeo.gadomancy.api.golems.AdditionalGolemType;
import makeo.gadomancy.api.golems.cores.AdditionalGolemCore;
import makeo.gadomancy.api.internal.IApiHandler;
import net.minecraft.item.ItemStack;
import thaumcraft.common.entities.golems.EntityGolemBase;
import thaumcraft.common.entities.golems.EnumGolemType;
import java.util.List;
/**
* 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
*
* Created by makeo @ 26.07.2015 19:00
*/
public abstract class GadomancyApi {
private static IApiHandler handler;
public static void setInstance(IApiHandler handler) {
GadomancyApi.handler = handler;
}
public static boolean registerAdditionalGolemType(String name, String modId, AdditionalGolemType newType){
return handler.registerAdditionalGolemType(name, modId, newType);
}
public static AdditionalGolemType getAdditionalGolemType(String name) {
return handler.getAdditionalGolemType(name);
}
public static AdditionalGolemType getAdditionalGolemType(EnumGolemType type) {
return getAdditionalGolemType(type.name());
}
public static List<AdditionalGolemType> getAdditionalGolemTypes() {
return handler.getAdditionalGolemTypes();
}
public static boolean isAdditionalGolemType(String name) {
return getAdditionalGolemType(name) != null;
}
public static boolean isAdditionalGolemType(EnumGolemType type) {
return isAdditionalGolemType(type.name());
}
public static AdditionalGolemCore getAdditionalGolemCore(EntityGolemBase golem) {
return handler.getAdditionalGolemCore(golem);
}
public static AdditionalGolemCore getAdditionalGolemCore(ItemStack placer) {
return handler.getAdditionalGolemCore(placer);
}
public static void setAdditionalGolemCore(EntityGolemBase golem, AdditionalGolemCore core) {
handler.setAdditionalGolemCore(golem, core);
}
public static boolean registerAdditionalGolemCore(String name, AdditionalGolemCore core) {
return handler.registerAdditionalGolemCore(name, core);
}
public static List<AdditionalGolemCore> getAdditionalGolemCores() {
return handler.getAdditionalGolemCores();
}
public static void registerClawClickBehavior(ClickBehavior clickBehavior) {
handler.registerClawClickBehavior(clickBehavior);
}
}
@@ -0,0 +1,87 @@
package makeo.gadomancy.api.golems;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraft.util.ResourceLocation;
import thaumcraft.common.entities.golems.EnumGolemType;
/**
* 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
*
* Created by makeo @ 26.07.2015 20:55
*/
public abstract class AdditionalGolemType {
private EnumGolemType enumEntry;
private Item placerItem;
private String modId;
public final int maxHealth;
public final int armor;
public final float movementSpeed;
public final boolean fireResist;
public final int upgradeAmount;
public final int carryLimit;
public final int regenDelay;
public final int strength;
public AdditionalGolemType(int maxHealth, int armor, float movementSpeed, boolean fireResist, int upgradeAmount, int carryLimit, int regenDelay, int strength) {
this.maxHealth = maxHealth;
this.armor = armor;
this.movementSpeed = movementSpeed;
this.fireResist = fireResist;
this.upgradeAmount = upgradeAmount;
this.carryLimit = carryLimit;
this.regenDelay = regenDelay;
this.strength = strength;
}
public abstract String getUnlocalizedName();
public abstract void registerIcons(IIconRegister ir);
public abstract IIcon getIcon(ItemStack stack, int pass);
public void setupGolem() {
}
public int getRenderPasses() { return 1; }
public abstract ResourceLocation getEntityTexture();
public abstract ResourceLocation getInvSlotTexture();
public EnumGolemType getEnumEntry() {
return enumEntry;
}
public String getName() {
return enumEntry.name();
}
public Item getPlacerItem() {
return placerItem;
}
public String getModId() {
return modId;
}
@Deprecated
public final void setEnumEntry(EnumGolemType enumEntry) {
this.enumEntry = enumEntry;
}
@Deprecated
public void setPlacerItem(Item placerItem) {
this.placerItem = placerItem;
}
@Deprecated
public void setModId(String modId) {
this.modId = modId;
}
}
@@ -0,0 +1,52 @@
package makeo.gadomancy.api.golems.cores;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import thaumcraft.common.entities.golems.EntityGolemBase;
/**
* 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
*
* Created by makeo @ 11.08.2015 14:10
*/
public abstract class AdditionalGolemCore {
private String name;
public abstract void setupGolem(EntityGolemBase golem);
public void setupGolemInventory(EntityGolemBase golem) { }
public abstract boolean hasGui();
public byte getBaseCore() {
return 1;
}
public boolean openGui(EntityPlayer player, EntityGolemBase golem) {
return false;
}
public ItemStack getToolItem(EntityGolemBase golem) {
return null;
}
public String getUnlocalizedGuiText() {
return "gadomancy.golem.core.text.default";
}
public abstract String getUnlocalizedName();
public abstract ItemStack getItem();
public String getName() {
return name;
}
@Deprecated
public void setName(String name) {
this.name = name;
}
}
@@ -0,0 +1,26 @@
package makeo.gadomancy.api.golems.events;
import cpw.mods.fml.common.eventhandler.Event;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import thaumcraft.common.entities.golems.EntityGolemBase;
/**
* 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
*
* Created by makeo @ 14.10.2015 14:09
*/
public class GolemDropPlacerEvent extends Event {
public final EntityPlayer player;
public final EntityItem placer;
public final EntityGolemBase golem;
public GolemDropPlacerEvent(EntityPlayer player, EntityItem placer, EntityGolemBase golem) {
this.player = player;
this.placer = placer;
this.golem = golem;
}
}
@@ -0,0 +1,26 @@
package makeo.gadomancy.api.golems.events;
import cpw.mods.fml.common.eventhandler.Event;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import thaumcraft.common.entities.golems.EntityGolemBase;
/**
* 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
*
* Created by makeo @ 14.10.2015 14:09
*/
public class PlacerCreateGolemEvent extends Event {
public final EntityPlayer player;
public final ItemStack placer;
public final EntityGolemBase golem;
public PlacerCreateGolemEvent(EntityPlayer player, EntityGolemBase golem, ItemStack placer) {
this.player = player;
this.golem = golem;
this.placer = placer;
}
}
@@ -0,0 +1,37 @@
package makeo.gadomancy.api.internal;
import makeo.gadomancy.api.ClickBehavior;
import makeo.gadomancy.api.golems.AdditionalGolemType;
import makeo.gadomancy.api.golems.cores.AdditionalGolemCore;
import net.minecraft.item.ItemStack;
import thaumcraft.common.entities.golems.EntityGolemBase;
import java.util.List;
/**
* 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
*
* Created by makeo @ 14.10.2015 14:28
*/
public interface IApiHandler {
boolean registerAdditionalGolemType(String name, String modId, AdditionalGolemType newType);
AdditionalGolemType getAdditionalGolemType(String name);
List<AdditionalGolemType> getAdditionalGolemTypes();
AdditionalGolemCore getAdditionalGolemCore(EntityGolemBase golem);
AdditionalGolemCore getAdditionalGolemCore(ItemStack placer);
boolean registerAdditionalGolemCore(String name, AdditionalGolemCore core);
void setAdditionalGolemCore(EntityGolemBase golem, AdditionalGolemCore core);
List<AdditionalGolemCore> getAdditionalGolemCores();
void registerClawClickBehavior(ClickBehavior clickBehavior);
}
@@ -0,0 +1,150 @@
package makeo.gadomancy.client;
import cpw.mods.fml.client.registry.ClientRegistry;
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
import cpw.mods.fml.client.registry.RenderingRegistry;
import cpw.mods.fml.common.FMLLog;
import makeo.gadomancy.client.events.RenderEventHandler;
import makeo.gadomancy.client.events.ResourceReloadListener;
import makeo.gadomancy.client.gui.InfusionClawGui;
import makeo.gadomancy.client.renderers.block.RenderBlockTransparent;
import makeo.gadomancy.client.renderers.entity.RenderAdditionalGolemBase;
import makeo.gadomancy.client.renderers.item.ItemRenderRemoteJar;
import makeo.gadomancy.client.renderers.item.ItemRenderTileEntity;
import makeo.gadomancy.client.renderers.tile.RenderTileArcaneDropper;
import makeo.gadomancy.client.renderers.tile.RenderTileInfusionClaw;
import makeo.gadomancy.client.renderers.tile.RenderTileRemoteJar;
import makeo.gadomancy.client.renderers.tile.RenderTileStickyJar;
import makeo.gadomancy.common.CommonProxy;
import makeo.gadomancy.common.blocks.tiles.TileArcaneDropper;
import makeo.gadomancy.common.blocks.tiles.TileInfusionClaw;
import makeo.gadomancy.common.blocks.tiles.TileRemoteJar;
import makeo.gadomancy.common.blocks.tiles.TileStickyJar;
import makeo.gadomancy.common.registration.RegisteredBlocks;
import makeo.gadomancy.common.utils.Injector;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.client.resources.IResourceManager;
import net.minecraft.client.resources.SimpleReloadableResourceManager;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.world.World;
import net.minecraftforge.client.MinecraftForgeClient;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.util.ForgeDirection;
import thaumcraft.client.gui.GuiGolem;
import thaumcraft.client.renderers.entity.RenderGolemBase;
import thaumcraft.common.entities.golems.EntityGolemBase;
import java.util.List;
/**
* 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
*
* Created by makeo @ 29.11.2014 14:15
*/
public class ClientProxy extends CommonProxy {
@Override
public void preInitalize() {
super.preInitalize();
}
@Override
public void initalize() {
injectGolemTextures();
//Tiles
ClientRegistry.bindTileEntitySpecialRenderer(TileStickyJar.class, new RenderTileStickyJar());
RenderTileRemoteJar renderTileRemoteJar = new RenderTileRemoteJar();
ClientRegistry.bindTileEntitySpecialRenderer(TileRemoteJar.class, renderTileRemoteJar);
RenderTileArcaneDropper renderTileArcaneDropper = new RenderTileArcaneDropper();
ClientRegistry.bindTileEntitySpecialRenderer(TileArcaneDropper.class, renderTileArcaneDropper);
RenderTileInfusionClaw renderTileInfusionClaw = new RenderTileInfusionClaw();
ClientRegistry.bindTileEntitySpecialRenderer(TileInfusionClaw.class, renderTileInfusionClaw);
//Items
TileArcaneDropper fakeTile = new TileArcaneDropper();
fakeTile.blockMetadata = 8 | ForgeDirection.SOUTH.ordinal();
MinecraftForgeClient.registerItemRenderer(Item.getItemFromBlock(RegisteredBlocks.blockArcaneDropper), new ItemRenderTileEntity(renderTileArcaneDropper, fakeTile));
MinecraftForgeClient.registerItemRenderer(Item.getItemFromBlock(RegisteredBlocks.blockInfusionClaw), new ItemRenderTileEntity(renderTileInfusionClaw, new TileInfusionClaw()));
MinecraftForgeClient.registerItemRenderer(Item.getItemFromBlock(RegisteredBlocks.blockRemoteJar), new ItemRenderRemoteJar(renderTileRemoteJar));
//Blocks
RegisteredBlocks.rendererTransparentBlock = registerBlockRenderer(new RenderBlockTransparent());
super.initalize();
}
@Override
public void postInitalize() {
IResourceManager manager = Minecraft.getMinecraft().getResourceManager();
if(manager instanceof SimpleReloadableResourceManager) {
SimpleReloadableResourceManager rm = (SimpleReloadableResourceManager) manager;
rm.registerReloadListener(new ResourceReloadListener());
}
MinecraftForge.EVENT_BUS.register(new RenderEventHandler());
super.postInitalize();
}
public int registerBlockRenderer(ISimpleBlockRenderingHandler renderer) {
int nextId = RenderingRegistry.getNextAvailableRenderId();
RenderingRegistry.registerBlockHandler(nextId, renderer);
return nextId;
}
@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
switch (ID) {
case 0:
return new GuiGolem(player, (EntityGolemBase) world.getEntityByID(x));
//return new AdditionalGolemGui(player, (EntityGolemBase)world.getEntityByID(x));
case 1:
return new InfusionClawGui(player.inventory, (IInventory) world.getTileEntity(x, y, z));
}
return null;
}
public static void injectGolemTextures() {
RenderGolemBase render = unregisterRenderer(EntityGolemBase.class, RenderGolemBase.class);
if(render != null) {
RenderingRegistry.registerEntityRenderingHandler(EntityGolemBase.class, new RenderAdditionalGolemBase());
}
}
public static <T extends Render> T unregisterRenderer(Class<? extends Entity> entityClass, Class<T> renderClass) {
Injector registry = new Injector(RenderingRegistry.instance());
List entityRenderers = registry.getField("entityRenderers");
if(entityRenderers == null) {
FMLLog.severe("Failed to get entityRenderers field in RenderingRegistry!");
return null;
}
for(int i = 0; i < entityRenderers.size(); i++) {
Injector pair = new Injector(entityRenderers.get(i));
Class<? extends Entity> target = pair.getField("target");
if(entityClass.equals(target)) {
Render render = pair.getField("renderer");
if(renderClass.isInstance(render)) {
entityRenderers.remove(i);
return (T)render;
}
}
}
return null;
}
}
@@ -0,0 +1,36 @@
package makeo.gadomancy.client.events;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import thaumcraft.api.BlockCoordinates;
import thaumcraft.api.IArchitect;
import java.util.ArrayList;
/**
* 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
*
* Created by makeo @ 13.10.2015 20:34
*/
public class FakeArchitectItem extends Item implements IArchitect {
private ArrayList<BlockCoordinates> coords;
public void setCoords(ArrayList<BlockCoordinates> coords) {
this.coords = coords;
}
@Override
public ArrayList<BlockCoordinates> getArchitectBlocks(ItemStack stack, World world, int x, int y, int z, int side, EntityPlayer player) {
return coords;
}
@Override
public boolean showAxis(ItemStack paramItemStack, World paramWorld, EntityPlayer paramEntityPlayer, int paramInt, EnumAxis paramEnumAxis) {
return false;
}
}
@@ -0,0 +1,58 @@
package makeo.gadomancy.client.events;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import makeo.gadomancy.common.registration.RegisteredBlocks;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import net.minecraftforge.client.event.DrawBlockHighlightEvent;
import net.minecraftforge.common.util.ForgeDirection;
import org.lwjgl.opengl.GL11;
import thaumcraft.api.BlockCoordinates;
import thaumcraft.api.IArchitect;
import thaumcraft.api.wands.ItemFocusBasic;
import thaumcraft.client.lib.REHWandHandler;
import thaumcraft.common.items.wands.ItemWandCasting;
import java.util.ArrayList;
/**
* 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
*
* Created by makeo @ 13.10.2015 16:11
*/
public class RenderEventHandler {
private static final REHWandHandler WAND_HANDLER = new REHWandHandler();
private static final FakeArchitectItem ARCHITECT_ITEM = new FakeArchitectItem();
@SubscribeEvent
public void on(DrawBlockHighlightEvent e) {
if(e.currentItem != null && e.currentItem.getItem() instanceof ItemWandCasting) {
ItemFocusBasic focus = ((ItemWandCasting) e.currentItem.getItem()).getFocus(e.currentItem);
if(focus == null || !(focus instanceof IArchitect)) {
Block block = e.player.worldObj.getBlock(e.target.blockX, e.target.blockY, e.target.blockZ);
if(block != null && block == RegisteredBlocks.blockArcaneDropper) {
ForgeDirection dir = ForgeDirection.getOrientation(e.player.worldObj.getBlockMetadata(e.target.blockX, e.target.blockY, e.target.blockZ) & 7);
ArrayList<BlockCoordinates> coords = new ArrayList<BlockCoordinates>();
for(int x = -1; x < 2; x++) {
for(int y = -1; y < 2; y++) {
for(int z = -1; z < 2; z++) {
coords.add(new BlockCoordinates(e.target.blockX + 2*dir.offsetX + x, e.target.blockY + 2*dir.offsetY + y, e.target.blockZ + 2*dir.offsetZ + z));
}
}
}
coords.add(new BlockCoordinates(e.target.blockX + dir.offsetX, e.target.blockY + dir.offsetY, e.target.blockZ + dir.offsetZ));
ARCHITECT_ITEM.setCoords(coords);
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
WAND_HANDLER.handleArchitectOverlay(new ItemStack(ARCHITECT_ITEM), e, e.player.ticksExisted, e.target);
GL11.glPopAttrib();
}
}
}
}
}
@@ -0,0 +1,53 @@
package makeo.gadomancy.client.events;
import makeo.gadomancy.api.GadomancyApi;
import makeo.gadomancy.api.golems.AdditionalGolemType;
import makeo.gadomancy.client.textures.GolemGuiTexture;
import makeo.gadomancy.common.utils.Injector;
import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.IResourceManager;
import net.minecraft.client.resources.IResourceManagerReloadListener;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import net.minecraft.util.StringTranslate;
import java.util.Map;
/**
* 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
*
* Created by makeo @ 03.10.2015 12:09
*/
public class ResourceReloadListener implements IResourceManagerReloadListener {
private Map languageList;
public ResourceReloadListener() {
Injector instance = new Injector(new Injector(StringTranslate.class)
.getField(Injector.findField(StringTranslate.class, StringTranslate.class)));
languageList = instance.getField(instance.findField(Map.class));
}
@Override
public void onResourceManagerReload(IResourceManager resourceManager) {
manipulateLanguageFile();
registerTextureOverride();
}
private void manipulateLanguageFile() {
if(languageList != null) {
for(AdditionalGolemType type : GadomancyApi.getAdditionalGolemTypes()) {
languageList.put("item.ItemGolemPlacer." + type.getEnumEntry().ordinal() + ".name",
StatCollector.translateToLocal(type.getUnlocalizedName() + ".name"));
}
}
}
private static final ResourceLocation TC_GOLEM_GUI_TEXTURE = new ResourceLocation("thaumcraft", "textures/gui/guigolem.png");
private void registerTextureOverride() {
Minecraft.getMinecraft().renderEngine.loadTexture(TC_GOLEM_GUI_TEXTURE, new GolemGuiTexture(TC_GOLEM_GUI_TEXTURE));
}
}
@@ -0,0 +1,62 @@
package makeo.gadomancy.client.gui;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import makeo.gadomancy.api.GadomancyApi;
import makeo.gadomancy.api.golems.cores.AdditionalGolemCore;
import makeo.gadomancy.common.utils.Injector;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.StatCollector;
import org.lwjgl.opengl.GL11;
import thaumcraft.client.gui.GuiGolem;
import thaumcraft.common.entities.golems.ContainerGolem;
import thaumcraft.common.entities.golems.EntityGolemBase;
/**
* 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
*
* Created by makeo @ 10.09.2015 14:15
*/
@SideOnly(Side.CLIENT)
public class AdditionalGolemGui extends GuiGolem {
protected EntityPlayer player;
protected EntityGolemBase golem;
protected int threat;
public AdditionalGolemGui(EntityPlayer player, EntityGolemBase golem) {
super(player, golem);
this.player = player;
this.golem = golem;
Injector injector = new Injector(this, GuiGolem.class);
this.threat = injector.getField("threat");
}
protected void drawGuiContainerForegroundLayer(int par1, int par2) {
GL11.glPushMatrix();
GL11.glScaled(0.5D, 0.5D, 0.5D);
if (this.threat >= 0) {
drawInfoString("golemthreat." + this.threat + ".text");
} else {
AdditionalGolemCore core = GadomancyApi.getAdditionalGolemCore(this.golem);
if(core != null) {
drawInfoString(core.getUnlocalizedGuiText());
} else {
drawInfoString("golemblurb." + this.golem.getCore() + ".text");
}
}
if (((ContainerGolem) this.inventorySlots).maxScroll > 0) {
this.fontRendererObj.drawString(((ContainerGolem) this.inventorySlots).currentScroll + 1 + "/" + (((ContainerGolem) this.inventorySlots).maxScroll + 1), 323, 140, 14540253);
}
GL11.glPopMatrix();
}
private void drawInfoString(String unlocalized) {
this.fontRendererObj.drawSplitString(StatCollector.translateToLocal(unlocalized), 80, 22, 110, 14540253);
}
}
@@ -0,0 +1,105 @@
package makeo.gadomancy.client.gui;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import makeo.gadomancy.common.blocks.tiles.TileInfusionClaw;
import makeo.gadomancy.common.containers.ContainerInfusionClaw;
import makeo.gadomancy.common.utils.ColorHelper;
import makeo.gadomancy.common.utils.SimpleResourceLocation;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import org.lwjgl.opengl.GL11;
import java.awt.*;
/**
* 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
*
* Created by makeo @ 09.10.2015 20:21
*/
@SideOnly(Side.CLIENT)
public class InfusionClawGui extends GuiContainer {
private static final ResourceLocation BACKGROUND = new SimpleResourceLocation("/gui/gui_infusion_claw.png");
private ContainerInfusionClaw container;
public InfusionClawGui(InventoryPlayer playerInv, IInventory clawInv) {
super(new ContainerInfusionClaw(playerInv, clawInv));
container = (ContainerInfusionClaw) super.inventorySlots;
}
@Override
protected void drawGuiContainerForegroundLayer(int p_146979_1_, int p_146979_2_) {
ItemStack cursorStack = container.playerInv.getItemStack();
if(((TileInfusionClaw)container.clawInv).isRunning() || (cursorStack != null && cursorStack.stackSize > 0 && !container.clawInv.isItemValidForSlot(0, cursorStack))) {
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glColor4f(1, 1, 1, 0.5f);
this.mc.renderEngine.bindTexture(BACKGROUND);
float t = this.zLevel;
this.zLevel = 200.0F;
GL11.glEnable(3042);
drawTexturedModalRect(80, 32, 240, 0, 16, 16);
GL11.glDisable(3042);
this.zLevel = t;
GL11.glPopAttrib();
}
}
@Override
protected void drawGuiContainerBackgroundLayer(float p_146976_1_, int p_146976_2_, int p_146976_3_) {
GL11.glEnable(GL11.GL_BLEND);
this.mc.renderEngine.bindTexture(BACKGROUND);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
int var5 = (this.width - this.xSize) / 2;
int var6 = (this.height - this.ySize) / 2;
drawTexturedModalRect(var5, var6, 0, 0, this.xSize, this.ySize);
int baseX = this.guiLeft;
int baseY = this.guiTop;
drawTexturedModalRect(baseX + 114, baseY + 36, 244, 19, 8, 8);
boolean isLocked = ((TileInfusionClaw)container.clawInv).isLocked();
if(isLocked) {
drawTexturedModalRect(baseX + 114, baseY + 36, 244, 27, 8, 8);
}
GL11.glPushMatrix();
GL11.glTranslatef(baseX + 124, baseY + 38, 0);
GL11.glScalef(0.5F, 0.5F, 0.0F);
this.fontRendererObj.drawString(StatCollector.translateToLocal("gadomancy.info.InfusionClaw.lock"), 0, 0, ColorHelper.toHex(isLocked ? Color.WHITE : Color.GRAY));
GL11.glPopMatrix();
GL11.glDisable(GL11.GL_BLEND);
}
@Override
protected void mouseClicked(int x, int y, int par3) {
super.mouseClicked(x, y, par3);
int baseX = (this.width - this.xSize) / 2;
int baseY = (this.height - this.ySize) / 2;
int checkX = x - baseX - 114;
int checkY = y - baseY - 36;
if(checkX >= 0 && checkX <= 8 && checkY >= 0 && checkY <= 8) {
TileInfusionClaw tile = ((TileInfusionClaw)container.clawInv);
this.mc.playerController.sendEnchantPacket(this.inventorySlots.windowId, tile.isLocked() ? 0 : 1);
tile.setIsLocked(tile.isLocked());
}
}
}
@@ -0,0 +1,127 @@
package makeo.gadomancy.client.models;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.entity.Entity;
/**
* 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
*
* Created by makeo @ 30.09.2015 17:04
* using Techne: http://www.minecraftforum.net/forums/mapping-and-modding/minecraft-tools/1261123
*/
public class ModelArcaneDropper extends ModelBase {
//fields
ModelRenderer shape1;
ModelRenderer shape2;
ModelRenderer shape3;
ModelRenderer shape4;
ModelRenderer shape5;
ModelRenderer shape6;
ModelRenderer shape7;
ModelRenderer shape8;
ModelRenderer shape9;
ModelRenderer shape10;
ModelRenderer shape11;
public ModelArcaneDropper() {
textureWidth = 64;
textureHeight = 64;
shape1 = new ModelRenderer(this, 44, 0);
shape1.addBox(0F, 0F, 0F, 2, 14, 8);
shape1.setRotationPoint(-1F, 10F, -4F);
shape1.setTextureSize(64, 64);
shape1.mirror = true;
setRotation(shape1, 0F, 0F, 0F);
shape2 = new ModelRenderer(this, 0, 0);
shape2.addBox(0F, 0F, 0F, 16, 16, 4);
shape2.setRotationPoint(-8F, 8F, 4F);
shape2.setTextureSize(64, 64);
shape2.mirror = true;
setRotation(shape2, 0F, 0F, 0F);
shape3 = new ModelRenderer(this, 0, 20);
shape3.addBox(0F, 0F, 0F, 16, 16, 4);
shape3.setRotationPoint(-8F, 8F, -8F);
shape3.setTextureSize(64, 64);
shape3.mirror = true;
setRotation(shape3, 0F, 0F, 0F);
shape4 = new ModelRenderer(this, 34, 22);
shape4.addBox(0F, 0F, 0F, 7, 2, 8);
shape4.setRotationPoint(1F, 10F, -4F);
shape4.setTextureSize(64, 64);
shape4.mirror = true;
setRotation(shape4, 0F, 0F, 0F);
shape5 = new ModelRenderer(this, 34, 32);
shape5.addBox(0F, 0F, 0F, 7, 4, 8);
shape5.setRotationPoint(1F, 20F, -4F);
shape5.setTextureSize(64, 64);
shape5.mirror = true;
setRotation(shape5, 0F, 0F, 0F);
shape6 = new ModelRenderer(this, 34, 52);
shape6.addBox(0F, 0F, 0F, 7, 4, 8);
shape6.setRotationPoint(-8F, 20F, -4F);
shape6.setTextureSize(64, 64);
shape6.mirror = true;
setRotation(shape6, 0F, 0F, 0F);
shape7 = new ModelRenderer(this, 0, 40);
shape7.addBox(0F, 0F, 0F, 7, 2, 8);
shape7.setRotationPoint(-8F, 10F, -4F);
shape7.setTextureSize(64, 64);
shape7.mirror = true;
setRotation(shape7, 0F, 0F, 0F);
shape8 = new ModelRenderer(this, 21, 50);
shape8.addBox(0F, 0F, 0F, 5, 2, 8);
shape8.setRotationPoint(3F, 8F, -4F);
shape8.setTextureSize(64, 64);
shape8.mirror = true;
setRotation(shape8, 0F, 0F, 0F);
shape9 = new ModelRenderer(this, 0, 50);
shape9.addBox(0F, 0F, 0F, 5, 2, 8);
shape9.setRotationPoint(-8F, 8F, -4F);
shape9.setTextureSize(64, 64);
shape9.mirror = true;
setRotation(shape9, 0F, 0F, 0F);
shape10 = new ModelRenderer(this, 0, 61);
shape10.addBox(0F, 0F, 0F, 6, 2, 1);
shape10.setRotationPoint(-3F, 8F, -4F);
shape10.setTextureSize(64, 64);
shape10.mirror = true;
setRotation(shape10, 0F, 0F, 0F);
shape11 = new ModelRenderer(this, 14, 61);
shape11.addBox(0F, 0F, 0F, 6, 2, 1);
shape11.setRotationPoint(-3F, 8F, 3F);
shape11.setTextureSize(64, 64);
shape11.mirror = true;
setRotation(shape11, 0F, 0F, 0F);
}
public void render(Entity entity, float f, float f1, float f2, float f3, float f4, float f5) {
super.render(entity, f, f1, f2, f3, f4, f5);
setRotationAngles(f, f1, f2, f3, f4, f5, entity);
shape1.render(f5);
shape2.render(f5);
shape3.render(f5);
shape4.render(f5);
shape5.render(f5);
shape6.render(f5);
shape7.render(f5);
shape8.render(f5);
shape9.render(f5);
shape10.render(f5);
shape11.render(f5);
}
private void setRotation(ModelRenderer model, float x, float y, float z) {
model.rotateAngleX = x;
model.rotateAngleY = y;
model.rotateAngleZ = z;
}
public void setRotationAngles(float f, float f1, float f2, float f3, float f4, float f5, Entity entity) {
super.setRotationAngles(f, f1, f2, f3, f4, f5, entity);
}
}
@@ -0,0 +1,42 @@
package makeo.gadomancy.client.models;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.entity.Entity;
/**
* 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
*
* Created by makeo @ 08.10.2015 16:14
*/
public class ModelInfusionClawPart extends ModelBase {
//fields
ModelRenderer shape1;
public ModelInfusionClawPart(int num) {
textureWidth = 32;
textureHeight = 64;
shape1 = new ModelRenderer(this, 0, 8*num);
shape1.addBox(-3F, -1F, -3F, 6, 2, 6);
shape1.setRotationPoint(0F, 0F, 0F);
shape1.setTextureSize(32, 64);
shape1.mirror = true;
setRotation(shape1, 0F, 0F, 0F);
}
public void render(Entity entity, float f, float f1, float f2, float f3, float f4, float f5) {
super.render(entity, f, f1, f2, f3, f4, f5);
setRotationAngles(f, f1, f2, f3, f4, f5, entity);
shape1.render(f5);
}
private void setRotation(ModelRenderer model, float x, float y, float z) {
model.rotateAngleX = x;
model.rotateAngleY = y;
model.rotateAngleZ = z;
}
}
@@ -0,0 +1,89 @@
package makeo.gadomancy.client.models;
import makeo.gadomancy.common.utils.Injector;
import net.minecraft.client.Minecraft;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import org.lwjgl.opengl.GL11;
import thaumcraft.client.renderers.models.gear.ModelWand;
import thaumcraft.common.items.wands.ItemWandCasting;
import java.lang.reflect.Method;
/**
* 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 @ 19.10.2015 19:09
*/
public class ModelWandPart extends ModelWand {
private static final Method DRAW_RUNE = Injector.getMethod("drawRune", ModelWand.class, double.class, double.class, double.class, int.class, EntityPlayer.class);
private Injector injector;
private int runeCount;
public ModelWandPart(int height, int runeCount) {
this.injector = new Injector(this, ModelWand.class);
this.runeCount = runeCount;
Injector injector = new Injector(this, ModelWand.class);
ModelRenderer capBottom = injector.getField("CapBottom");
capBottom.cubeList.clear();
ModelRenderer rod = new ModelRenderer(this, 0, 8);
rod.addBox(-1.0F, -1.0F, -1.0F, 2, height, 2);
rod.setRotationPoint(0.0F, 2.0F, 0.0F);
rod.setTextureSize(64, 32);
rod.mirror = true;
rod.rotateAngleX = 0;
rod.rotateAngleY = 0;
rod.rotateAngleZ = 0;
injector.setField("Rod", rod);
}
@Override
public void render(ItemStack stack) {
ItemWandCasting wand = (ItemWandCasting) stack.getItem();
if(wand.hasRunes(stack)) {
ItemStack stackCopy = stack.copy();
stackCopy.func_150996_a(new ItemCustomWandCasting());
super.render(stackCopy);
GL11.glPushMatrix();
if(wand.isStaff(stack)) {
GL11.glTranslatef(0, 0.2f, 0);
}
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 200, 0);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, 1);
for (int side = 0; side < 4; side++) {
GL11.glRotatef(90, 0, 1, 0);
for (int a = 0; a < runeCount; a++) {
injector.invokeMethod(DRAW_RUNE, 0.36 + a * 0.14, -0.01, -0.08,
(a + side * 3) % 16, Minecraft.getMinecraft().thePlayer);
}
}
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glPopMatrix();
} else {
super.render(stack);
}
}
private static class ItemCustomWandCasting extends ItemWandCasting {
@Override
public boolean hasRunes(ItemStack stack) {
return false;
}
}
}
@@ -0,0 +1,51 @@
package makeo.gadomancy.client.renderers.block;
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.util.IIcon;
import net.minecraftforge.common.util.ForgeDirection;
/**
* 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
*
* Created by makeo @ 29.09.2015 21:18
*/
public abstract class BlockRenderingHandler implements ISimpleBlockRenderingHandler {
protected void renderAllFaces(RenderBlocks renderer, Block block, int x, int y, int z, IIcon icon) {
renderer.renderFaceYNeg(block, x, y, z, icon);
renderer.renderFaceYPos(block, x, y, z, icon);
renderer.renderFaceZNeg(block, x, y, z, icon);
renderer.renderFaceZPos(block, x, y, z, icon);
renderer.renderFaceXNeg(block, x, y, z, icon);
renderer.renderFaceXPos(block, x, y, z, icon);
}
protected void renderFace(int side, RenderBlocks renderer, Block block, int x, int y, int z, IIcon icon) {
switch (side) {
case 0: renderer.renderFaceYNeg(block, x, y, z, icon); break;
case 1: renderer.renderFaceYPos(block, x, y, z, icon); break;
case 2: renderer.renderFaceZNeg(block, x, y, z, icon); break;
case 3: renderer.renderFaceZPos(block, x, y, z, icon); break;
case 4: renderer.renderFaceXNeg(block, x, y, z, icon); break;
case 5: renderer.renderFaceXPos(block, x, y, z, icon); break;
}
}
protected void renderFace(ForgeDirection side, RenderBlocks renderer, Block block, int x, int y, int z, IIcon icon) {
renderFace(side.ordinal(), renderer, block, x, y, z, icon);
}
/*protected void renderFaceHollow(int side, RenderBlocks renderer, Block block, int x, int y, int z, IIcon icon,
int startX, int startY, int startZ, int endX, int endY, int endZ) {
}
protected void renderFacePartially(int side, RenderBlocks renderer, Block block, int x, int y, int z, IIcon icon,
int startX, int startY, int startZ, int endX, int endY, int endZ) {
}*/
}
@@ -0,0 +1,40 @@
package makeo.gadomancy.client.renderers.block;
import makeo.gadomancy.common.blocks.IBlockTransparent;
import makeo.gadomancy.common.registration.RegisteredBlocks;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.world.IBlockAccess;
/**
* 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
*
* Created by makeo @ 29.09.2015 20:53
*/
public class RenderBlockTransparent extends BlockRenderingHandler {
@Override
public void renderInventoryBlock(Block block, int metadata, int modelId, RenderBlocks renderer) {
}
@Override
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {
if(block instanceof IBlockTransparent) {
renderAllFaces(renderer, block, x, y, z, ((IBlockTransparent) block).getTransparentIcon());
}
return false;
}
@Override
public boolean shouldRender3DInInventory(int modelId) {
return false;
}
@Override
public int getRenderId() {
return RegisteredBlocks.rendererTransparentBlock;
}
}
@@ -0,0 +1,97 @@
package makeo.gadomancy.client.renderers.entity;
import makeo.gadomancy.api.GadomancyApi;
import makeo.gadomancy.api.golems.AdditionalGolemType;
import makeo.gadomancy.api.golems.cores.AdditionalGolemCore;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import thaumcraft.client.renderers.entity.RenderGolemBase;
import thaumcraft.client.renderers.models.entities.ModelGolem;
import thaumcraft.common.entities.golems.EntityGolemBase;
/**
* 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
*
* Created by makeo @ 12.03.2015 15:57
*/
public class RenderAdditionalGolemBase extends RenderGolemBase {
private ItemStack toolItem = null;
public RenderAdditionalGolemBase() {
super(new ModelGolem(false));
}
protected int shouldRenderPass(EntityLivingBase entity, int pass, float par3) {
if (pass != 0) {
return super.shouldRenderPass(entity, pass, par3);
}
EntityGolemBase golem = (EntityGolemBase) entity;
AdditionalGolemCore core = GadomancyApi.getAdditionalGolemCore(golem);
if (core != null) {
golem.getDataWatcher().getWatchedObject(21).setObject((byte) -1);
}
int ret = super.shouldRenderPass(entity, pass, par3);
//fix for render bug in tc
if (RenderGolemHelper.requiresRenderFix((EntityGolemBase) entity)) {
RenderGolemHelper.renderCarriedItemsFix(golem);
if(toolItem != null) {
RenderGolemHelper.renderToolItem(golem, toolItem, mainModel, renderManager);
}
}
if (core != null) {
golem.getDataWatcher().getWatchedObject(21).setObject((byte) 1);
RenderGolemHelper.renderCore(golem, core);
}
return ret;
}
@Override
protected void renderCarriedItems(EntityGolemBase golem, float par2) {
if (!RenderGolemHelper.requiresRenderFix(golem)) {
if(toolItem != null) {
RenderGolemHelper.renderToolItem(golem, toolItem, mainModel, renderManager);
}
super.renderCarriedItems(golem, par2);
}
}
@Override
public void render(EntityGolemBase golem, double par2, double par4, double par6, float par8, float par9) {
AdditionalGolemCore core = GadomancyApi.getAdditionalGolemCore(golem);
ItemStack carriedItem = null;
if(core != null) {
toolItem = core.getToolItem(golem);
carriedItem = golem.getCarriedForDisplay();
golem.getDataWatcher().getWatchedObject(16).setObject(null);
}
super.render(golem, par2, par4, par6, par8, par9);
if(carriedItem != null) {
golem.getDataWatcher().getWatchedObject(16).setObject(carriedItem);
toolItem = null;
}
}
@Override
protected ResourceLocation getEntityTexture(Entity entity) {
AdditionalGolemType type = GadomancyApi.getAdditionalGolemType(((EntityGolemBase) entity).getGolemType());
if (type != null) {
return type.getEntityTexture();
}
return super.getEntityTexture(entity);
}
}
@@ -0,0 +1,187 @@
package makeo.gadomancy.client.renderers.entity;
import makeo.gadomancy.api.golems.cores.AdditionalGolemCore;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.renderer.ItemRenderer;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import org.lwjgl.opengl.GL11;
import thaumcraft.client.renderers.models.entities.ModelGolem;
import thaumcraft.common.entities.golems.EntityGolemBase;
import java.awt.*;
/**
* 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
*
* Created by makeo @ 07.10.2015 13:18
*/
public class RenderGolemHelper {
private RenderGolemHelper() {}
public static void renderCore(EntityGolemBase golem, AdditionalGolemCore core) {
GL11.glPushMatrix();
GL11.glRotatef(180.0F, 1.0F, 0.0F, 0.0F);
GL11.glTranslatef(0.0875F, -0.96F, 0.15F + (golem.getGolemDecoration().contains("P") ? 0.03F : 0.0F));
GL11.glScaled(0.175D, 0.175D, 0.175D);
GL11.glRotatef(180.0F, 0.0F, 1.0F, 0.0F);
ItemStack coreItem = core.getItem();
IIcon icon = coreItem.getItem().getIcon(coreItem, 0);
float f1 = icon.getMaxU();
float f2 = icon.getMinV();
float f3 = icon.getMinU();
float f4 = icon.getMaxV();
Minecraft.getMinecraft().renderEngine.bindTexture(TextureMap.locationItemsTexture);
ItemRenderer.renderItemIn2D(Tessellator.instance, f1, f2, f3, f4, icon.getIconWidth(), icon.getIconHeight(), 0.2F);
GL11.glPopMatrix();
}
public static boolean requiresRenderFix(EntityGolemBase golem) {
ItemStack item = golem.getCarriedForDisplay();
byte core = golem.getCore();
return item != null && item.getItem().requiresMultipleRenderPasses() && core != 5 && core != 6 && core != 11;
}
public static void renderCarriedItemsFix(EntityGolemBase golem) {
GL11.glPushMatrix();
GL11.glScaled(0.4D, 0.4D, 0.4D);
GL11.glTranslatef(-0.5F, 2.5F, -1.25F);
GL11.glRotatef(180.0F, 1.0F, 0.0F, 0.0F);
ItemStack item = golem.getCarriedForDisplay();
int renderPass = 0;
do {
IIcon icon = item.getItem().getIcon(item, renderPass);
if (icon != null) {
Color color = new Color(item.getItem().getColorFromItemStack(item, renderPass));
GL11.glColor3ub((byte) color.getRed(), (byte) color.getGreen(), (byte) color.getBlue());
ItemRenderer.renderItemIn2D(Tessellator.instance, icon.getMaxU(), icon.getMinV(), icon.getMinU(),
icon.getMaxV(), icon.getIconWidth(), icon.getIconHeight(), 0.0625F);
GL11.glColor3f(1.0F, 1.0F, 1.0F);
}
renderPass++;
} while (renderPass < item.getItem().getRenderPasses(item.getItemDamage()));
GL11.glPopMatrix();
}
public static void renderToolItem(EntityGolemBase golem, ItemStack itemstack, ModelBase mainModel, RenderManager renderManager) {
GL11.glPushMatrix();
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
float angle = (float) (0.195 * Math.PI / -1 * ((ModelGolem) mainModel).golemRightArm.rotateAngleX);
float y = (float) (Math.cos(angle) * 1.15);
float z = (float) (Math.sin(angle) * 1.15);
GL11.glTranslatef(-0.25F, y, z * -0.5f);
GL11.glRotated(angle / Math.PI * 180f, -1, 0, 0);
float fs = 0.66F;
GL11.glScalef(fs, fs, fs);
net.minecraftforge.client.IItemRenderer customRenderer = net.minecraftforge.client.MinecraftForgeClient.getItemRenderer(itemstack, net.minecraftforge.client.IItemRenderer.ItemRenderType.EQUIPPED);
boolean is3D = (customRenderer != null && customRenderer.shouldUseRenderHelper(net.minecraftforge.client.IItemRenderer.ItemRenderType.EQUIPPED, itemstack, net.minecraftforge.client.IItemRenderer.ItemRendererHelper.BLOCK_3D));
Item item = itemstack.getItem();
float f1;
if (item instanceof ItemBlock && (is3D || RenderBlocks.renderItemIn3d(Block.getBlockFromItem(item).getRenderType())))
{
f1 = 0.5F;
GL11.glTranslatef(0.0F, 0.1875F, -0.3125F);
f1 *= 0.75F;
GL11.glRotatef(20.0F, 1.0F, 0.0F, 0.0F);
GL11.glRotatef(45.0F, 0.0F, 1.0F, 0.0F);
GL11.glScalef(-f1, -f1, f1);
}
else if (item == Items.bow)
{
f1 = 0.625F;
GL11.glTranslatef(0.0F, 0.125F, 0.3125F);
GL11.glRotatef(-20.0F, 0.0F, 1.0F, 0.0F);
GL11.glScalef(f1, -f1, f1);
GL11.glRotatef(-100.0F, 1.0F, 0.0F, 0.0F);
GL11.glRotatef(45.0F, 0.0F, 1.0F, 0.0F);
}
else if (item.isFull3D())
{
f1 = 0.625F;
if (item.shouldRotateAroundWhenRendering())
{
GL11.glRotatef(180.0F, 0.0F, 0.0F, 1.0F);
GL11.glTranslatef(0.0F, -0.125F, 0.0F);
}
GL11.glTranslatef(0.0F, 0.1875F, 0.0F);
GL11.glScalef(f1, -f1, f1);
GL11.glRotatef(-100.0F, 1.0F, 0.0F, 0.0F);
GL11.glRotatef(45.0F, 0.0F, 1.0F, 0.0F);
}
else
{
f1 = 0.375F;
GL11.glTranslatef(0.25F, 0.1875F, -0.1875F);
GL11.glScalef(f1, f1, f1);
GL11.glRotatef(60.0F, 0.0F, 0.0F, 1.0F);
GL11.glRotatef(-90.0F, 1.0F, 0.0F, 0.0F);
GL11.glRotatef(20.0F, 0.0F, 0.0F, 1.0F);
}
float f2;
int i;
float f5;
if (itemstack.getItem().requiresMultipleRenderPasses())
{
for (i = 0; i < itemstack.getItem().getRenderPasses(itemstack.getItemDamage()); ++i)
{
int j = itemstack.getItem().getColorFromItemStack(itemstack, i);
f5 = (float)(j >> 16 & 255) / 255.0F;
f2 = (float)(j >> 8 & 255) / 255.0F;
float f3 = (float)(j & 255) / 255.0F;
GL11.glColor4f(f5, f2, f3, 1.0F);
renderManager.itemRenderer.renderItem(golem, itemstack, i);
}
}
else
{
i = itemstack.getItem().getColorFromItemStack(itemstack, 0);
float f4 = (float)(i >> 16 & 255) / 255.0F;
f5 = (float)(i >> 8 & 255) / 255.0F;
f2 = (float)(i & 255) / 255.0F;
GL11.glColor4f(f4, f5, f2, 1.0F);
renderManager.itemRenderer.renderItem(golem, itemstack, 0);
}
GL11.glScaled(1.0D, 1.0D, 1.0D);
GL11.glPopMatrix();
}
}
@@ -0,0 +1,37 @@
package makeo.gadomancy.client.renderers.item;
import makeo.gadomancy.client.renderers.tile.RenderTileRemoteJar;
import makeo.gadomancy.common.blocks.tiles.TileRemoteJar;
import makeo.gadomancy.common.registration.RegisteredBlocks;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.item.ItemStack;
import net.minecraft.src.FMLRenderAccessLibrary;
import net.minecraftforge.client.IItemRenderer;
import org.lwjgl.opengl.GL11;
/**
* 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
*
* Created by makeo @ 17.10.2015 01:44
*/
public class ItemRenderRemoteJar extends ItemRenderTileEntity<TileRemoteJar> {
public ItemRenderRemoteJar(RenderTileRemoteJar render) {
super(render, new TileRemoteJar());
}
@Override
public void renderItem(IItemRenderer.ItemRenderType type, ItemStack stack, Object... data) {
GL11.glEnable(GL11.GL_ALPHA_TEST);
super.renderItem(type, stack, data);
GL11.glPushMatrix();
GL11.glTranslatef(0.5f, 0.5f, 0.5f);
FMLRenderAccessLibrary.renderInventoryBlock(RenderBlocks.getInstance(), RegisteredBlocks.blockRemoteJar, 0, RegisteredBlocks.blockRemoteJar.getRenderType());
GL11.glPopMatrix();
}
}
@@ -0,0 +1,55 @@
package makeo.gadomancy.client.renderers.item;
import makeo.gadomancy.client.util.FakeWorld;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.client.IItemRenderer;
import org.lwjgl.opengl.GL11;
/**
* 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
*
* Created by makeo @ 29.09.2015 18:29
*/
public class ItemRenderTileEntity<T extends TileEntity> implements IItemRenderer {
private static final World FAKE_WORLD = new FakeWorld();
private final TileEntitySpecialRenderer render;
protected final T tile;
public ItemRenderTileEntity(TileEntitySpecialRenderer render, T tile) {
this.render = render;
this.tile = tile;
if(tile.getWorldObj() == null) {
tile.setWorldObj(FAKE_WORLD);
}
}
@Override
public boolean handleRenderType(ItemStack item, ItemRenderType type) {
return true;
}
@Override
public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper) {
return true;
}
@Override
public void renderItem(ItemRenderType type, ItemStack item, Object... data) {
if(type == IItemRenderer.ItemRenderType.ENTITY)
GL11.glTranslatef(-0.5f, -0.5f, -0.5f);
if(type == ItemRenderType.INVENTORY) {
GL11.glTranslatef(0, -0.1f, 0);
}
this.render.renderTileEntityAt(tile, 0.0D, 0.0D, 0.0D, 0.0F);
}
}
@@ -0,0 +1,78 @@
package makeo.gadomancy.client.renderers.tile;
import makeo.gadomancy.client.models.ModelArcaneDropper;
import makeo.gadomancy.common.utils.SimpleResourceLocation;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.util.ForgeDirection;
import org.lwjgl.opengl.GL11;
import thaumcraft.client.renderers.tile.TileBellowsRenderer;
import thaumcraft.common.tiles.TileBellows;
/**
* 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
*
* Created by makeo @ 28.09.2015 20:00
*/
public class RenderTileArcaneDropper extends TileEntitySpecialRenderer {
private static final ResourceLocation RESOURCE = new SimpleResourceLocation("models/arcane_dropper.png");
private static final ModelBase MODEL = new ModelArcaneDropper();
private static final TileBellowsRenderer BELLOWS_RENDERER = new TileBellowsRenderer();
private static final TileBellows BELLOWS_TILE = new TileBellows();
@Override
public void renderTileEntityAt(TileEntity tile, double x, double y, double z, float partialTicks) {
GL11.glPushMatrix();
GL11.glTranslated(x + 0.5, y - 0.5, z + 0.5);
int metadata = tile.getBlockMetadata();
ForgeDirection side = ForgeDirection.getOrientation(metadata & 7);
if(side == ForgeDirection.UP) {
GL11.glRotatef(180, 1, 0, 0);
GL11.glTranslatef(0, -2, 0);
} else if(side != ForgeDirection.DOWN) {
GL11.glRotatef(-90, side.offsetZ, 0, -1*side.offsetX);
GL11.glTranslatef(side.offsetX, -1, side.offsetZ);
}
boolean flipped = (metadata & 8) == 8;
if(side == ForgeDirection.WEST || side == ForgeDirection.EAST) {
flipped = !flipped;
}
if(flipped) {
GL11.glRotatef(90, 0, 1, 0);
}
bindTexture(RESOURCE);
MODEL.render(null, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F);
renderBellow();
GL11.glRotatef(180, 0, 1, 0);
renderBellow();
GL11.glPopMatrix();
}
public void renderBellow() {
GL11.glPushMatrix();
GL11.glTranslatef(0, 0.75f, 0.25f);
GL11.glRotatef(90f, 0, 1, 0);
GL11.glTranslatef(-0.05f, 0.03f, 0f);
GL11.glScalef(0.6f, 0.44f, 0.55f);
BELLOWS_RENDERER.renderEntityAt(BELLOWS_TILE, 0, 0, 0, 0);
GL11.glPopMatrix();
}
}
@@ -0,0 +1,274 @@
package makeo.gadomancy.client.renderers.tile;
import makeo.gadomancy.client.models.ModelInfusionClawPart;
import makeo.gadomancy.client.models.ModelWandPart;
import makeo.gadomancy.common.blocks.tiles.TileInfusionClaw;
import makeo.gadomancy.common.utils.Injector;
import makeo.gadomancy.common.utils.SimpleResourceLocation;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MathHelper;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import net.minecraftforge.client.IItemRenderer;
import net.minecraftforge.common.util.ForgeDirection;
import org.lwjgl.opengl.GL11;
import thaumcraft.client.renderers.entity.RenderPrimalOrb;
import thaumcraft.client.renderers.item.ItemWandRenderer;
import thaumcraft.common.Thaumcraft;
import thaumcraft.common.config.ConfigItems;
import thaumcraft.common.entities.projectile.EntityPrimalOrb;
import thaumcraft.common.items.wands.ItemWandCasting;
import java.util.Random;
/**
* 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
*
* Created by makeo @ 05.10.2015 21:39
*/
public class RenderTileInfusionClaw extends TileEntitySpecialRenderer {
private static final ResourceLocation RESOURCE = new SimpleResourceLocation("models/infusion_claw.png");
private static final ModelInfusionClawPart[] MODELS;
private static final Random RANDOM = new Random();
private static final ItemWandRenderer WAND_RENDERER = new ItemWandRenderer();
private static final ItemWandRenderer STAFF_RENDERER = new ItemWandRenderer();
private static final RenderPrimalOrb RENDER_PRIMAL_ORB = new RenderPrimalOrb();
static {
MODELS = new ModelInfusionClawPart[8];
for (int i = 0; i < MODELS.length; i++) {
MODELS[i] = new ModelInfusionClawPart(i);
}
new Injector(WAND_RENDERER).setField("model", new ModelWandPart(7, 4));
new Injector(STAFF_RENDERER).setField("model", new ModelWandPart(7, 4));
RENDER_PRIMAL_ORB.setRenderManager(RenderManager.instance);
}
@Override
public void renderTileEntityAt(TileEntity tile, double x, double y, double z, float partialTicks) {
render((TileInfusionClaw) tile, x, y, z, partialTicks);
}
private void render(TileInfusionClaw tile, double x, double y, double z, float partialTicks) {
float ticks = Minecraft.getMinecraft().renderViewEntity.ticksExisted + partialTicks;
float elapsed = ticks - tile.lastRenderTick;
tile.lastRenderTick = ticks;
GL11.glPushMatrix();
GL11.glTranslated(x, y, z);
renderPart(tile, elapsed, ticks);
renderPrimalOrb(tile, elapsed);
GL11.glPopMatrix();
}
private void renderPart(TileInfusionClaw tile, float elapsed, float ticks) {
GL11.glPushMatrix();
GL11.glTranslatef(0.5f, 0.5f, 0.5f);
World world = tile.getWorldObj();
bindTexture(RESOURCE);
renderSides(tile, world, tile.xCoord, tile.yCoord, tile.zCoord, elapsed);
renderCircle(tile, elapsed);
renderWand(tile.getStackInSlot(0), ticks);
GL11.glPopMatrix();
}
private void renderCircle(TileInfusionClaw tile, float elapsed) {
GL11.glPushMatrix();
float speed = (float) Math.pow(1.1, Math.abs(tile.animationStates[9]));
if (speed > 50) {
speed = 50;
}
if (tile.animationStates[9] > 0) {
tile.animationStates[9] += 0.5 * elapsed;
if (tile.animationStates[9] > 20 * 5f) {
tile.animationStates[9] = -tile.animationStates[9];
ItemStack wandStack = tile.getStackInSlot(0);
if(wandStack != null) {
tile.animationStates[11] = ((ItemWandCasting)wandStack.getItem()).isStaff(wandStack) ? 0.5f : 0.1f;
}
}
} else if (tile.animationStates[9] < 0) {
tile.animationStates[9] += elapsed * 0.5;
if (tile.animationStates[9] > 0) {
tile.animationStates[9] = 0;
}
}
for (int i = 0; i < 4; i++) {
GL11.glPushMatrix();
tile.animationStates[10] += speed * (elapsed * 0.001 * Math.PI);
float angle = (float) (tile.animationStates[10] + (i * 0.5 * Math.PI));
float x = (float) Math.sin(angle);
float y = (float) Math.cos(angle);
float radius = 0.25f;
GL11.glTranslated(0, (1f / 16f) * Math.sin(angle / 1.4) + (1f / 16f), 0);
GL11.glTranslated(radius * x, -0.27, radius * y);
GL11.glRotated(45, Math.cos(angle), 0, -Math.sin(angle));
GL11.glScalef(0.75f, 0.75f, 0.75f);
renderPart(i);
GL11.glPopMatrix();
}
GL11.glPopMatrix();
}
private void renderWand(ItemStack wandStack, float ticks) {
GL11.glRotatef(((ticks/3) / 20.0F) * (180F / (float)Math.PI), 0, 1f, 0);
renderTopPart();
if (wandStack != null && wandStack.stackSize > 0) {
GL11.glPushMatrix();
ItemWandCasting item = (ItemWandCasting) ConfigItems.itemWandCasting;
ItemStack wandFocusStack = wandStack.copy();
item.setFocus(wandFocusStack, new ItemStack(ConfigItems.itemFocusPrimal));
GL11.glRotatef(180, 1, 0, 0);
GL11.glScalef(0.5f, 0.5f, 0.5f);
GL11.glTranslatef(0, MathHelper.sin((ticks / 3) / 10.0F) * 0.08F + 0.08F, 0);
GL11.glTranslatef(0, -1.4924f, 0);
if(item.isStaff(wandFocusStack)) {
GL11.glTranslatef(0, -0.5f, 0);
STAFF_RENDERER.renderItem(IItemRenderer.ItemRenderType.ENTITY, wandFocusStack);
} else {
WAND_RENDERER.renderItem(IItemRenderer.ItemRenderType.ENTITY, wandFocusStack);
}
GL11.glPopMatrix();
}
}
private void renderTopPart() {
GL11.glPushMatrix();
GL11.glTranslatef(0, (0.5f - (1f / 16f * 0.75f)), 0);
GL11.glScalef(0.75f, 0.75f, 0.75f);
renderPart(4);
GL11.glPopMatrix();
}
private void renderPrimalOrb(TileInfusionClaw tile, float elapsed) {
if(tile.animationStates[11] > 0) {
tile.animationStates[11] += elapsed / 70f;
GL11.glPushMatrix();
GL11.glTranslatef(0.5f, 0.75f - tile.animationStates[11], 0.5f);
GL11.glScalef(0.35f, 0.35f, 0.35f);
EntityPrimalOrb orb = new EntityPrimalOrb(tile.getWorldObj(), Minecraft.getMinecraft().thePlayer, true);
orb.ticksExisted = Minecraft.getMinecraft().renderViewEntity.ticksExisted;
RENDER_PRIMAL_ORB.renderEntityAt(orb, 0, 0, 0, 0, 0);
GL11.glPopMatrix();
if(0.75f - tile.animationStates[11] < -0.5f) {
tile.animationStates[11] = 0;
}
}
}
private void createSideZap(TileInfusionClaw tile) {
for(int i = 2; i < 6; i++) {
ForgeDirection dir = ForgeDirection.getOrientation(i);
createZap(tile, 0.5f + 0.5f*(float)dir.offsetX, 0.6f, 0.5f + 0.5f*(float)dir.offsetZ, 0.5f + dir.offsetX*0.2f, 0.2f, 0.5f + dir.offsetZ*0.2f);
playZapSound(tile.xCoord, tile.yCoord, tile.zCoord);
}
}
private void createZap(TileEntity tile, float startX, float startY, float startZ, float endX, float endY, float endZ) {
Thaumcraft.proxy.nodeBolt(Thaumcraft.proxy.getClientWorld(), tile.xCoord + startX, tile.yCoord + startY, tile.zCoord + startZ,
tile.xCoord + endX, tile.yCoord + endY, tile.zCoord + endZ);
}
private void playZapSound(float x, float y, float z) {
Thaumcraft.proxy.getClientWorld().playSound(x, y, z, "thaumcraft:zap", 0.1F, 1.0F + Thaumcraft.proxy.getClientWorld().rand.nextFloat() * 0.2F, false);
}
private void renderSides(TileInfusionClaw tile, World world, int x, int y, int z, float elapsed) {
GL11.glPushMatrix();
float speed = (float) Math.pow(1.1, Math.abs(tile.animationStates[8]));
if (tile.animationStates[8] > 0) {
tile.animationStates[8] += elapsed;
if (tile.animationStates[8] > 20 * 2.5f) {
tile.animationStates[8] = -tile.animationStates[8];
tile.animationStates[9] = 1;
createSideZap(tile);
}
} else if (tile.animationStates[8] < 0) {
tile.animationStates[8] += elapsed * 0.5;
if (tile.animationStates[8] > 0) {
tile.animationStates[8] = 0;
}
}
for (int i = 0; i < 4; i++) {
float heightMove = getNextMoveOffset(tile, i, speed, elapsed);
float widthMove = getNextMoveOffset(tile, i + 4, speed, elapsed);
ForgeDirection dir = ForgeDirection.getOrientation(i + 2);
boolean powered = world != null && world.getIndirectPowerLevelTo(x + dir.offsetX, y, z + dir.offsetZ, dir.ordinal()) > 0;
GL11.glPushMatrix();
GL11.glTranslatef(-dir.offsetZ * widthMove, heightMove, -dir.offsetX * widthMove);
GL11.glTranslated((0.5 - (1f / 16f * 0.75)) * dir.offsetX, 0, (0.5 - (1f / 16f * 0.75)) * dir.offsetZ);
GL11.glRotatef(90, -1 * dir.offsetZ, 0, dir.offsetX);
GL11.glScalef(0.75f, 0.75f, 0.75f);
renderRedstonePart(powered);
GL11.glPopMatrix();
}
GL11.glPopMatrix();
}
private float getNextMoveOffset(TileInfusionClaw tile, int id, float speed, float elapsed) {
tile.animationStates[id] += RANDOM.nextDouble() * 2 * elapsed * speed;
return (float) ((1d / 16d) * Math.sin(tile.animationStates[id] / 30));
}
private void renderRedstonePart(boolean powered) {
renderPart(powered ? 6 : 5);
}
private void renderPart(int num) {
MODELS[num].render(null, 0f, 0f, 0f, 0f, 0f, 0.0625f);
}
}
@@ -0,0 +1,89 @@
package makeo.gadomancy.client.renderers.tile;
import makeo.gadomancy.client.util.FakeWorld;
import makeo.gadomancy.common.utils.SimpleResourceLocation;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
import thaumcraft.client.renderers.models.ModelJar;
import thaumcraft.client.renderers.tile.TileJarRenderer;
import thaumcraft.client.renderers.tile.TileMirrorRenderer;
import thaumcraft.common.tiles.TileMirrorEssentia;
/**
* 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
*
* Created by makeo @ 14.10.2015 16:01
*/
public class RenderTileRemoteJar extends TileJarRenderer {
private static final ModelJar MODEL_JAR = new ModelJar();
private static final ResourceLocation OVERLAY_TEXTURE = new SimpleResourceLocation("models/jar_overlay.png");
@Override
public void renderTileEntityAt(TileEntity tile, double x, double y, double z, float partialTicks) {
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
GL11.glPushMatrix();
GL11.glTranslated(x, y, z);
GL11.glPushMatrix();
GL11.glTranslatef(0.45f/2, 0.003f, 0.45f/2);
GL11.glScalef(0.55f, 1, 0.55f);
TileMirrorRenderer renderer = new TileMirrorRenderer();
renderer.func_147497_a(this.field_147501_a);
if(field_147501_a.field_147553_e != null) {
renderer.renderTileEntityAt(createFakeTile(tile, true), 0, 0, 0, partialTicks);
}
GL11.glPopMatrix();
GL11.glDisable(GL11.GL_CULL_FACE);
GL11.glTranslatef(0.5f, 0.002f, 0.5f);
GL11.glRotatef(180, 0, 0, 1);
bindTexture(OVERLAY_TEXTURE);
GL11.glScalef(1.002f, 1f, 1.002f);
MODEL_JAR.renderAll();
GL11.glPopMatrix();
GL11.glPopAttrib();
super.renderTileEntityAt(tile, x, y, z, partialTicks);
}
private TileMirrorEssentia createFakeTile(TileEntity tile, boolean linked) {
TileMirrorEssentia fake = new TileMirrorEssentia();
fake.linked = linked;
fake.blockMetadata = 7;
if(tile.getWorldObj() == null) {
fake.setWorldObj(new FakeWorld());
} else {
fake.setWorldObj(tile.getWorldObj());
}
if(tile.getWorldObj() instanceof FakeWorld) {
EntityPlayer p = Minecraft.getMinecraft().thePlayer;
fake.xCoord = (int) p.posX;
fake.yCoord = (int) p.posY;
fake.zCoord = (int) p.posZ;
} else {
fake.xCoord = tile.xCoord;
fake.yCoord = tile.yCoord;
fake.zCoord = tile.zCoord;
}
return fake;
}
}
@@ -0,0 +1,99 @@
package makeo.gadomancy.client.renderers.tile;
import makeo.gadomancy.common.blocks.tiles.TileStickyJar;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import org.lwjgl.opengl.GL11;
import thaumcraft.common.tiles.TileJarFillable;
/**
* 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
*
* Created by makeo @ 14.07.2015 21:05
*/
public class RenderTileStickyJar extends TileEntitySpecialRenderer {
private static final RenderBlocks RENDER_BLOCKS = new RenderBlocks();
@Override
public void renderTileEntityAt(TileEntity tile, double x, double y, double z, float partialTicks) {
if(tile != null && tile instanceof TileStickyJar && ((TileStickyJar) tile).isValid()) {
TileStickyJar stickyJar = (TileStickyJar) tile;
TileJarFillable parent = stickyJar.getParent();
World world = tile.getWorldObj();
Block block = stickyJar.getParentBlock();
GL11.glPushMatrix();
GL11.glTranslated(x, y, z);
rotateJar(stickyJar.placedOn, ForgeDirection.getOrientation(stickyJar.facing));
//TESR
TileEntitySpecialRenderer renderer = TileEntityRendererDispatcher.instance.getSpecialRenderer(parent);
if(renderer != null) {
stickyJar.syncToParent();
renderer.renderTileEntityAt(parent, 0, 0, 0, partialTicks);
stickyJar.syncFromParent();
}
//ISimpleBlockHandler
GL11.glPushMatrix();
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
bindTexture(TextureMap.locationBlocksTexture);
RENDER_BLOCKS.blockAccess = world;
Tessellator tess = Tessellator.instance;
tess.startDrawingQuads();
tess.setNormal(0, -stickyJar.placedOn.offsetY, -Math.abs(stickyJar.placedOn.offsetZ + stickyJar.placedOn.offsetX));
tess.setTranslation(-tile.xCoord, -tile.yCoord, -tile.zCoord);
RENDER_BLOCKS.renderBlockByRenderType(block, tile.xCoord, tile.yCoord, tile.zCoord);
tess.setTranslation(0, 0, 0);
tess.draw();
GL11.glPopAttrib();
GL11.glPopMatrix();
GL11.glPopMatrix();
}
}
private void rotateJar(ForgeDirection placedOn, ForgeDirection facing) {
if(placedOn == ForgeDirection.UP) {
GL11.glTranslatef(Math.abs(facing.offsetZ), 1, Math.abs(facing.offsetX));
GL11.glRotatef(180, facing.offsetX, 0, facing.offsetZ);
} else if(placedOn != ForgeDirection.DOWN) {
GL11.glTranslatef(0.5f, 0.5f, 0.5f);
GL11.glRotatef(90, placedOn.offsetZ * -1, 0, placedOn.offsetX);
switch (placedOn) {
case NORTH: GL11.glRotatef(0, 0, 1, 0); break;
case EAST: GL11.glRotatef(-90, 0, 1, 0); break;
case SOUTH: GL11.glRotatef(180, 0, 1, 0); break;
case WEST: GL11.glRotatef(90, 0, 1, 0); break;
}
GL11.glTranslatef(-0.5f, -0.5f, -0.5f);
}
}
}
@@ -0,0 +1,40 @@
package makeo.gadomancy.client.textures;
import net.minecraft.client.renderer.texture.SimpleTexture;
import net.minecraft.client.resources.IResource;
import net.minecraft.client.resources.IResourceManager;
import net.minecraft.util.ResourceLocation;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
/**
* 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
*
* Created by makeo @ 04.10.2015 17:56
*/
public abstract class BaseTexture extends SimpleTexture {
public BaseTexture(ResourceLocation resourceLocation) {
super(resourceLocation);
}
protected BufferedImage loadImage(IResourceManager resourceManager, ResourceLocation location) throws IOException {
InputStream inputstream = null;
try {
IResource iresource = resourceManager.getResource(location);
inputstream = iresource.getInputStream();
return ImageIO.read(inputstream);
}
finally {
if (inputstream != null) {
inputstream.close();
}
}
}
}
@@ -0,0 +1,167 @@
package makeo.gadomancy.client.textures;
import makeo.gadomancy.api.GadomancyApi;
import makeo.gadomancy.api.golems.AdditionalGolemType;
import net.minecraft.client.renderer.texture.TextureUtil;
import net.minecraft.client.resources.IResource;
import net.minecraft.client.resources.IResourceManager;
import net.minecraft.client.resources.data.TextureMetadataSection;
import net.minecraft.util.ResourceLocation;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import thaumcraft.common.entities.golems.EnumGolemType;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
/**
* 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
*
* Created by makeo @ 07.09.2015 18:11
*/
public class GolemGuiTexture extends BaseTexture {
private static final Logger LOGGER = LogManager.getLogger();
@Override
public int getGlTextureId() {
return super.getGlTextureId();
}
public GolemGuiTexture(ResourceLocation textureLocation) {
super(textureLocation);
}
@Override
public void loadTexture(IResourceManager resourceManager) throws IOException {
this.deleteGlTexture();
InputStream inputstream = null;
try
{
IResource iresource = resourceManager.getResource(this.textureLocation);
inputstream = iresource.getInputStream();
BufferedImage bufferedimage = manipulateImage(resourceManager, ImageIO.read(inputstream));
boolean flag = false;
boolean flag1 = false;
if (iresource.hasMetadata())
{
try
{
TextureMetadataSection texturemetadatasection = (TextureMetadataSection)iresource.getMetadata("texture");
if (texturemetadatasection != null)
{
flag = texturemetadatasection.getTextureBlur();
flag1 = texturemetadatasection.getTextureClamp();
}
}
catch (RuntimeException runtimeexception)
{
LOGGER.warn("Failed reading metadata of: " + this.textureLocation, runtimeexception);
}
}
TextureUtil.uploadTextureImageAllocate(this.getGlTextureId(), bufferedimage, flag, flag1);
}
finally
{
if (inputstream != null)
{
inputstream.close();
}
}
}
private BufferedImage manipulateImage(IResourceManager resourceManager, BufferedImage image) throws IOException {
int scale = image.getWidth() / 256;
List<AdditionalGolemType> types = GadomancyApi.getAdditionalGolemTypes();
int newHeight = (24*scale) * (getMaxOrdinal() + 1);
BufferedImage newImg = new BufferedImage(image.getWidth(), newHeight < image.getHeight() ? image.getHeight() : newHeight, image.getType());
for(int x = 0; x < image.getWidth(); x++) {
for(int y = 0; y < image.getHeight(); y++) {
newImg.setRGB(x, y, image.getRGB(x, y));
}
}
for(AdditionalGolemType type : types) {
try {
int ordinal = type.getEnumEntry().ordinal();
BufferedImage slotImg = loadImage(resourceManager, type.getInvSlotTexture());
float slotScale = (24*scale) / (float)slotImg.getWidth();
if(slotScale > 1) {
slotImg = scaleImage(slotImg, slotScale, slotScale);
}
for(int x = 0; x < slotImg.getWidth(); x++) {
for(int y = 0; y < slotImg.getHeight(); y++) {
newImg.setRGB((184*scale) + x, ordinal * (24*scale) + y, slotImg.getRGB(x, y));
}
}
} catch (IOException e) {
LOGGER.warn("Failed loading golem inventory slot texture of: " + type.getModId() + ":" + type.getName());
}
}
return newImg;
}
private BufferedImage scaleImage(BufferedImage input, float xScale, float yScale) {
int newX = (int) (input.getWidth()*xScale);
int newY = (int) (input.getHeight()*yScale);
Image temp = input.getScaledInstance(newX, newY, Image.SCALE_REPLICATE);
BufferedImage img = new BufferedImage(newX, newY, input.getType());
Graphics2D graphics = img.createGraphics();
graphics.drawImage(temp, 0, 0, null);
graphics.dispose();
return img;
}
private int getMaxOrdinal() {
int max = 0;
for(EnumGolemType type : EnumGolemType.values()) {
if(type.ordinal() > max) {
max = type.ordinal();
}
}
return max;
}
}
@@ -0,0 +1,124 @@
package makeo.gadomancy.client.util;
import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.init.Blocks;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.EnumSkyBlock;
import net.minecraft.world.MinecraftException;
import net.minecraft.world.World;
import net.minecraft.world.WorldProvider;
import net.minecraft.world.chunk.IChunkProvider;
import net.minecraft.world.chunk.storage.IChunkLoader;
import net.minecraft.world.storage.IPlayerFileData;
import net.minecraft.world.storage.ISaveHandler;
import net.minecraft.world.storage.WorldInfo;
import java.io.File;
/**
* 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
*
* Created by makeo @ 16.10.2015 22:15
*/
public class FakeWorld extends World {
public FakeWorld() {
super(FakeSaveHandler.instance, "", null, FakeWorldProvider.instance, null);
}
@Override
public Block getBlock(int x, int y, int z) {
return Blocks.air;
}
@Override
protected IChunkProvider createChunkProvider() {
return null;
}
@Override
protected int func_152379_p() {
return 0;
}
@Override
public Entity getEntityByID(int p_73045_1_) {
return null;
}
@Override
public int getSkyBlockTypeBrightness(EnumSkyBlock p_72925_1_, int p_72925_2_, int p_72925_3_, int p_72925_4_) {
return 15;
}
@Override
public int getBlockMetadata(int x, int y, int z) {
return 0;
}
private static class FakeWorldInfo extends WorldInfo {
private static FakeWorldInfo instance = new FakeWorldInfo();
}
private static class FakeWorldProvider extends WorldProvider {
private static FakeWorldProvider instance = new FakeWorldProvider();
@Override
public String getDimensionName() {
return "FAKEWORLD";
}
}
private static class FakeSaveHandler implements ISaveHandler {
private static FakeSaveHandler instance = new FakeSaveHandler();
@Override
public WorldInfo loadWorldInfo() {
return FakeWorldInfo.instance;
}
@Override
public void checkSessionLock() throws MinecraftException {
}
@Override
public IChunkLoader getChunkLoader(WorldProvider p_75763_1_) {
return null;
}
@Override
public void saveWorldInfoWithPlayer(WorldInfo p_75755_1_, NBTTagCompound p_75755_2_) {
}
@Override
public void saveWorldInfo(WorldInfo p_75761_1_) {
}
@Override
public IPlayerFileData getSaveHandler() {
return null;
}
@Override
public void flush() {
}
@Override
public File getWorldDirectory() {
return null;
}
@Override
public File getMapFileFromName(String p_75758_1_) {
return null;
}
@Override
public String getWorldDirectoryName() {
return null;
}
}
}
@@ -0,0 +1,80 @@
package makeo.gadomancy.common;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.network.IGuiHandler;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.relauncher.Side;
import makeo.gadomancy.common.containers.ContainerInfusionClaw;
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.*;
import makeo.gadomancy.client.ClientProxy;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import thaumcraft.common.entities.golems.ContainerGolem;
import thaumcraft.common.entities.golems.EntityGolemBase;
/**
* 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
*
* Created by makeo @ 29.11.2014 14:18
*/
public class CommonProxy implements IGuiHandler {
public static final EventHandlerGolem EVENT_HANDLER_GOLEM = new EventHandlerGolem();
public void onConstruct() { }
public void preInitalize() {
PacketHandler.init();
RegisteredItems.preInit();
RegisteredBlocks.init();
RegisteredItems.init();
RegisteredGolemStuff.init();
}
public void initalize() {
NetworkRegistry.INSTANCE.registerGuiHandler(Gadomancy.instance, this);
MinecraftForge.EVENT_BUS.register(EVENT_HANDLER_GOLEM);
FMLCommonHandler.instance().bus().register(new EventHandlerNetwork());
MinecraftForge.EVENT_BUS.register(new EventHandlerWorld());
RegisteredRecipes.init();
}
public void postInitalize() {
RegisteredResearches.init();
RegisteredIntegrations.init();
RegisteredResearches.postInit();
}
@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
switch (ID) {
case 0:
return new ContainerGolem(player.inventory, ((EntityGolemBase)world.getEntityByID(x)).inventory);
case 1:
return new ContainerInfusionClaw(player.inventory, (IInventory) world.getTileEntity(x, y, z));
}
return null;
}
@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
return null;
}
public Side getSide() {
return this instanceof ClientProxy ? Side.CLIENT : Side.SERVER;
}
}
@@ -0,0 +1,77 @@
package makeo.gadomancy.common;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLConstructionEvent;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import makeo.gadomancy.api.GadomancyApi;
import makeo.gadomancy.common.api.DefaultApiHandler;
import makeo.gadomancy.common.data.ModConfig;
import makeo.gadomancy.common.data.ModData;
/**
* 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
*
* Created by makeo @ 29.11.2014 14:07
*/
@Mod(modid = Gadomancy.MODID, name = Gadomancy.NAME, version = Gadomancy.VERSION, dependencies="required-after:Thaumcraft@[4.1.1.11,);after:Waila")
public class Gadomancy
{
public static final String MODID = "gadomancy";
public static final String NAME = "Gadomancy";
public static final String VERSION = "1.0.0";
private static final String PROXY_CLIENT = "makeo.gadomancy.client.ClientProxy";
private static final String PROXY_SERVER = "makeo.gadomancy.common.CommonProxy";
private static ModData modData = null;
public static ModData getModData() {
return modData;
}
public static void loadModData() {
modData = new ModData("data");
modData.load();
}
public static void unloadModData() {
if(modData != null) {
modData.save();
modData = null;
}
}
@Mod.Instance(value = Gadomancy.MODID)
public static Gadomancy instance;
@SidedProxy(clientSide = PROXY_CLIENT, serverSide = PROXY_SERVER)
public static CommonProxy proxy;
@Mod.EventHandler
public void onConstruct(FMLConstructionEvent event) {
GadomancyApi.setInstance(new DefaultApiHandler());
proxy.onConstruct();
}
@Mod.EventHandler
public void preInit(FMLPreInitializationEvent event) {
proxy.preInitalize();
ModConfig.init(event.getSuggestedConfigurationFile());
}
@Mod.EventHandler
public void init(FMLInitializationEvent event) {
proxy.initalize();
}
@Mod.EventHandler
public void postInit(FMLPostInitializationEvent event) {
proxy.postInitalize();
}
}
@@ -0,0 +1,122 @@
package makeo.gadomancy.common.api;
import cpw.mods.fml.common.registry.GameRegistry;
import makeo.gadomancy.common.Gadomancy;
import makeo.gadomancy.api.ClickBehavior;
import makeo.gadomancy.api.golems.AdditionalGolemType;
import makeo.gadomancy.api.golems.cores.AdditionalGolemCore;
import makeo.gadomancy.api.internal.IApiHandler;
import makeo.gadomancy.common.data.ModConfig;
import makeo.gadomancy.common.entities.golems.ItemAdditionalGolemPlacer;
import makeo.gadomancy.common.entities.golems.nbt.ExtendedGolemProperties;
import makeo.gadomancy.common.registration.RegisteredBlocks;
import makeo.gadomancy.common.utils.GolemEnumHelper;
import makeo.gadomancy.common.utils.NBTHelper;
import makeo.gadomancy.common.utils.StringHelper;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import thaumcraft.common.entities.golems.EntityGolemBase;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 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
*
* Created by makeo @ 14.10.2015 14:38
*/
public class DefaultApiHandler implements IApiHandler {
private static Map<String, AdditionalGolemType> additionalGolemTypes = new HashMap<String, AdditionalGolemType>();
@Override
public boolean registerAdditionalGolemType(String name, String modId, AdditionalGolemType newType) {
String uniqueName = name.toUpperCase();
if(!additionalGolemTypes.containsKey(uniqueName)) {
GolemEnumHelper.addGolemType(uniqueName, newType);
ItemAdditionalGolemPlacer placerItem = new ItemAdditionalGolemPlacer(newType);
GameRegistry.registerItem(placerItem, "item" + StringHelper.firstToUpper(name.toLowerCase()) + "GolemPlacer");
newType.setModId(modId);
newType.setPlacerItem(placerItem);
additionalGolemTypes.put(uniqueName, newType);
return true;
}
return false;
}
@Override
public AdditionalGolemType getAdditionalGolemType(String name) {
return additionalGolemTypes.get(name.toUpperCase());
}
@Override
public List<AdditionalGolemType> getAdditionalGolemTypes() {
return new ArrayList<AdditionalGolemType>(additionalGolemTypes.values());
}
private static Map<String, AdditionalGolemCore> additionalGolemCores = new HashMap<String, AdditionalGolemCore>();
@Override
public AdditionalGolemCore getAdditionalGolemCore(EntityGolemBase golem) {
String coreName = golem.getDataWatcher().getWatchableObjectString(ModConfig.getGolemDatawatcherId());
if(!coreName.isEmpty()) {
return additionalGolemCores.get(coreName);
}
return null;
}
@Override
public AdditionalGolemCore getAdditionalGolemCore(ItemStack placer) {
if(NBTHelper.hasPersistentData(placer)) {
NBTTagCompound persistent = NBTHelper.getPersistentData(placer);
if(persistent.hasKey("Core")) {
return additionalGolemCores.get(persistent.getString("Core"));
}
}
return null;
}
@Override
public boolean registerAdditionalGolemCore(String name, AdditionalGolemCore core) {
if(!additionalGolemCores.containsKey(name)) {
core.setName(name);
additionalGolemCores.put(name, core);
return true;
}
return false;
}
@Override
public void setAdditionalGolemCore(EntityGolemBase golem, AdditionalGolemCore core) {
String coreName = core == null ? "" : core.getName();
golem.setCore(core == null ? -1 : core.getBaseCore());
golem.getDataWatcher().updateObject(ModConfig.getGolemDatawatcherId(), coreName);
if(!golem.worldObj.isRemote) {
NBTHelper.getPersistentData(golem).setString("Core", coreName);
((ExtendedGolemProperties)golem.getExtendedProperties(Gadomancy.MODID)).updateGolem();
} else {
golem.setupGolem();
golem.setupGolemInventory();
}
golem.worldObj.setEntityState(golem, (byte)7);
}
@Override
public List<AdditionalGolemCore> getAdditionalGolemCores() {
return new ArrayList<AdditionalGolemCore>(additionalGolemCores.values());
}
@Override
public void registerClawClickBehavior(ClickBehavior clickBehavior) {
RegisteredBlocks.registerClawClickBehavior(clickBehavior);
}
}
@@ -0,0 +1,158 @@
package makeo.gadomancy.common.blocks;
import makeo.gadomancy.common.blocks.tiles.TileArcaneDropper;
import makeo.gadomancy.common.registration.RegisteredItems;
import net.minecraft.block.material.Material;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.MathHelper;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import java.util.List;
/**
* 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
*
* Created by makeo @ 28.09.2015 20:15
*/
public class BlockArcaneDropper extends BlockTransparent {
public BlockArcaneDropper() {
super(Material.rock);
setHardness(3.5f);
setCreativeTab(RegisteredItems.creativeTab);
}
@Override
public boolean hasTileEntity(int metadata) {
return true;
}
@Override
public TileArcaneDropper createTileEntity(World world, int metadata) {
return new TileArcaneDropper();
}
@Override
protected String getTextureName() {
return "thaumcraft:pedestal_top";
}
@Override
public boolean isOpaqueCube(){
return false;
}
@Override
public boolean isSideSolid(IBlockAccess world, int x, int y, int z, ForgeDirection side) {
int metadata = world.getBlockMetadata(x, y, z);
ForgeDirection direction = ForgeDirection.getOrientation(metadata & 7);
boolean flipped = (metadata & 8) == 8;
if(direction == ForgeDirection.SOUTH
|| direction == ForgeDirection.NORTH) {
flipped = !flipped;
}
ForgeDirection rotated = direction.getRotation(flipped ? ForgeDirection.getOrientation((direction.ordinal() + 4) % 6) : ForgeDirection.getOrientation((direction.ordinal() + 2) % 6));
return direction != side && rotated != side && rotated.getOpposite() != side;
}
@Override
public int onBlockPlaced(World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ, int metadata) {
return side;
}
protected void setBlockBounds(AxisAlignedBB box) {
super.minX = box.minX;
super.minY = box.minY;
super.minZ = box.minZ;
super.maxX = box.maxX;
super.maxY = box.maxY;
super.maxZ = box.maxZ;
}
private static final AxisAlignedBB[] COLLISION_BOXES = new AxisAlignedBB[]{
AxisAlignedBB.getBoundingBox(0, 0, 0, 1, 0.3125f, 1),//down
AxisAlignedBB.getBoundingBox(0, 0.6875f, 0, 1, 1, 1),//up
AxisAlignedBB.getBoundingBox(0, 0, 0, 1, 1, 0.3125f),//north
AxisAlignedBB.getBoundingBox(0, 0, 0.6875f, 1, 1, 1),//south
AxisAlignedBB.getBoundingBox(0, 0, 0, 0.3125f, 1, 1),//west
AxisAlignedBB.getBoundingBox(0.6875f, 0, 0, 1, 1, 1), //east
};
public void addCollisionBoxesToList(World world, int x, int y, int z, AxisAlignedBB boundingBox, List list, Entity entity) {
ForgeDirection side = ForgeDirection.getOrientation(world.getBlockMetadata(x, y, z) & 7);
for(int i = 0; i < COLLISION_BOXES.length; i++) {
if(i != side.ordinal()) {
this.setBlockBounds(COLLISION_BOXES[i]);
super.addCollisionBoxesToList(world, x, y, z, boundingBox, list, entity);
}
}
if(side.offsetX + side.offsetY + side.offsetZ < 0) {
this.setBlockBounds(side.offsetX * -0.125f, side.offsetY * -0.125f, side.offsetZ * -0.125f, 1f, 1f, 1f);
} else {
this.setBlockBounds(0f, 0f, 0f, 1 - side.offsetX * 0.125f, 1 - side.offsetY * 0.125f, 1 - side.offsetZ * 0.125f);
}
super.addCollisionBoxesToList(world, x, y, z, boundingBox, list, entity);
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
}
@Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entity, ItemStack stack) {
int metadata = world.getBlockMetadata(x, y, z);
ForgeDirection side = ForgeDirection.getOrientation(metadata);
float yaw = MathHelper.wrapAngleTo180_float(entity.rotationYaw);
float pitch = entity.rotationPitch;
boolean flipped;
if(side == ForgeDirection.UP || side == ForgeDirection.DOWN) {
yaw += 180;
flipped = yaw > 315 || yaw < 45 || (yaw < 225 && yaw > 135);
} else {
switch (side.getOpposite()) {
case WEST:
yaw -= 90;
break;
case NORTH:
yaw = (180 - Math.abs(yaw)) * (yaw < 0 ? 1 : -1);
break;
case EAST:
yaw += 90;
break;
}
flipped = Math.abs(yaw) < Math.abs(pitch);
}
metadata |= flipped ? 8 : 0;
world.setBlockMetadataWithNotify(x, y, z, metadata, 2);
}
@Override
public boolean hasComparatorInputOverride() {
return true;
}
@Override
public int getComparatorInputOverride(World world, int x, int y, int z, int side) {
return Container.calcRedstoneFromInventory((IInventory) world.getTileEntity(x, y, z));
}
}
@@ -0,0 +1,121 @@
package makeo.gadomancy.common.blocks;
import makeo.gadomancy.common.Gadomancy;
import makeo.gadomancy.api.ClickBehavior;
import makeo.gadomancy.common.blocks.tiles.TileInfusionClaw;
import makeo.gadomancy.common.registration.RegisteredBlocks;
import makeo.gadomancy.common.registration.RegisteredItems;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.world.World;
import java.util.Random;
/**
* 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
*
* Created by makeo @ 05.10.2015 21:38
*/
public class BlockInfusionClaw extends BlockTransparent {
private static final Random RANDOM = new Random();
public BlockInfusionClaw() {
super(Material.rock);
setHardness(3.5f);
setCreativeTab(RegisteredItems.creativeTab);
}
@Override
protected String getTextureName() {
return "thaumcraft:pedestal_top";
}
@Override
public void onNeighborBlockChange(World world, int x, int y, int z, Block block) {
if(!world.isRemote) {
TileInfusionClaw tile = (TileInfusionClaw) world.getTileEntity(x, y, z);
tile.updateRedstone(world.isBlockIndirectlyGettingPowered(x, y, z));
}
}
@Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entity, ItemStack stack) {
if(entity instanceof EntityPlayer) {
TileInfusionClaw tile = (TileInfusionClaw) world.getTileEntity(x, y, z);
tile.setOwner((EntityPlayer) entity);
}
}
@Override
public TileEntity createTileEntity(World world, int metadata) {
return new TileInfusionClaw();
}
@Override
public boolean isOpaqueCube() {
return false;
}
@Override
public boolean hasTileEntity(int metadata) {
return true;
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int p_149727_6_, float p_149727_7_, float p_149727_8_, float p_149727_9_) {
if(!world.isRemote) {
TileInfusionClaw tile = (TileInfusionClaw) world.getTileEntity(x, y, z);
if(tile.hasOwner()) {
player.openGui(Gadomancy.instance, 1, world, x, y, z);
} else if(tile.setOwner(player)) {
player.addChatComponentMessage(new ChatComponentTranslation("gadomancy.info.InfusionClaw.owner"));
}
}
return true;
}
@Override
public void breakBlock(World world, int x, int y, int z, Block block, int metadata) {
TileInfusionClaw tile = (TileInfusionClaw) world.getTileEntity(x, y, z);
ItemStack wandStack = tile.getStackInSlot(0);
if(wandStack != null && wandStack.stackSize > 0) {
float f = RANDOM.nextFloat() * 0.8F + 0.1F;
float f1 = RANDOM.nextFloat() * 0.8F + 0.1F;
float f2 = RANDOM.nextFloat() * 0.8F + 0.1F;
EntityItem entityItem = new EntityItem(world, x + f, y + f1, z + f2, wandStack.copy());
float f3 = 0.05F;
entityItem.motionX = RANDOM.nextGaussian() * f3;
entityItem.motionY = RANDOM.nextGaussian() * f3 + 0.2F;
entityItem.motionZ = RANDOM.nextGaussian() * f3;
world.spawnEntityInWorld(entityItem);
}
}
@Override
public boolean hasComparatorInputOverride() {
return true;
}
@Override
public int getComparatorInputOverride(World world, int x, int y, int z, int side) {
if(y > 0) {
ClickBehavior behavior = RegisteredBlocks.getClawClickBehavior(world, x, y - 1, z);
if(behavior != null) {
return behavior.getComparatorOutput();
}
}
return 0;
}
}
@@ -0,0 +1,62 @@
package makeo.gadomancy.common.blocks;
import makeo.gadomancy.common.Gadomancy;
import makeo.gadomancy.common.blocks.tiles.TileRemoteJar;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import thaumcraft.common.blocks.BlockJar;
import thaumcraft.common.config.ConfigItems;
import thaumcraft.common.tiles.TileJarFillable;
import java.util.List;
/**
* 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
*
* Created by makeo @ 14.10.2015 14:56
*/
public class BlockRemoteJar extends BlockJar {
public BlockRemoteJar() {
//setCreativeTab(RegisteredItems.creativeTab);
setCreativeTab(null);
}
@Override
public void getSubBlocks(Item item, CreativeTabs tab, List list) {
list.add(new ItemStack(item, 1, 0));
}
@Override
public TileEntity createTileEntity(World world, int metadata) {
return new TileRemoteJar();
}
@Override
public void registerBlockIcons(IIconRegister ir) {
super.registerBlockIcons(ir);
this.iconJarSide = ir.registerIcon(Gadomancy.MODID + ":jar_remote_side");
this.iconJarTop = ir.registerIcon(Gadomancy.MODID + ":jar_remote_top");
this.iconJarBottom = ir.registerIcon(Gadomancy.MODID + ":transparent");
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float these, float are, float variables) {
ItemStack heldItem = player.getHeldItem();
if (heldItem != null && heldItem.getItem() == ConfigItems.itemEssence) {
if(!world.isRemote) {
BlockStickyJar.handlePhial(world, x, y, z, player, heldItem, (TileJarFillable) world.getTileEntity(x, y, z));
}
return true;
}
return super.onBlockActivated(world, x, y, z, player, side, these, are, variables);
}
}
@@ -0,0 +1,299 @@
package makeo.gadomancy.common.blocks;
import makeo.gadomancy.common.Gadomancy;
import makeo.gadomancy.common.blocks.tiles.TileStickyJar;
import makeo.gadomancy.common.registration.RegisteredBlocks;
import makeo.gadomancy.common.registration.RegisteredItems;
import makeo.gadomancy.common.registration.StickyJarInfo;
import makeo.gadomancy.common.utils.NBTHelper;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import thaumcraft.api.aspects.Aspect;
import thaumcraft.api.aspects.AspectList;
import thaumcraft.api.aspects.IEssentiaContainerItem;
import thaumcraft.common.blocks.BlockJar;
import thaumcraft.common.config.ConfigItems;
import thaumcraft.common.items.ItemEssence;
import thaumcraft.common.tiles.TileJarFillable;
import java.util.ArrayList;
import java.util.Map;
/**
* 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
*
* Created by makeo @ 13.07.2015 15:42
*/
public class BlockStickyJar extends BlockJar implements IBlockTransparent {
public BlockStickyJar() {
setCreativeTab(null);
}
private IIcon iconTransparent;
@Override
public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side) {
TileEntity tile = world.getTileEntity(x, y, z);
if(tile instanceof TileStickyJar) {
TileStickyJar stickyJar = (TileStickyJar) tile;
if(stickyJar.isValid()) {
return stickyJar.getParentBlock().getIcon(world, x, y, z, side);
}
}
return iconTransparent;
}
@Override
public void registerBlockIcons(IIconRegister ir) {
super.registerBlockIcons(ir);
iconTransparent = ir.registerIcon(Gadomancy.MODID + ":transparent");
}
@Override
public IIcon getTransparentIcon() {
return iconTransparent;
}
public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z) {
super.setBlockBoundsBasedOnState(world, x, y, z);
TileEntity tile = world.getTileEntity(x, y, z);
if (tile instanceof TileStickyJar) {
flipBlockBounds((TileStickyJar) tile);
}
}
private void flipBlockBounds(TileStickyJar stickyJar) {
ForgeDirection placedOn = stickyJar.placedOn;
if (placedOn != ForgeDirection.DOWN) {
float minX = (float) getBlockBoundsMinX();
float minY = (float) getBlockBoundsMinY();
float minZ = (float) getBlockBoundsMinZ();
float maxX = (float) getBlockBoundsMaxX();
float maxY = (float) getBlockBoundsMaxY();
float maxZ = (float) getBlockBoundsMaxZ();
float temp;
if (placedOn == ForgeDirection.NORTH || placedOn == ForgeDirection.SOUTH) {
temp = minZ;
minZ = minY;
minY = temp;
temp = maxZ;
maxZ = maxY;
maxY = temp;
} else if (placedOn == ForgeDirection.WEST || placedOn == ForgeDirection.EAST) {
temp = minX;
minX = minY;
minY = temp;
temp = maxX;
maxX = maxY;
maxY = temp;
}
if (placedOn == ForgeDirection.UP || placedOn == ForgeDirection.SOUTH || placedOn == ForgeDirection.EAST) {
minX = 1 - minX;
minY = 1 - minY;
minZ = 1 - minZ;
maxX = 1 - maxX;
maxY = 1 - maxY;
maxZ = 1 - maxZ;
temp = minX;
minX = maxX;
maxX = temp;
temp = minY;
minY = maxY;
maxY = temp;
temp = minZ;
minZ = maxZ;
maxZ = temp;
}
this.minX = minX;
this.minY = minY;
this.minZ = minZ;
this.maxX = maxX;
this.maxY = maxY;
this.maxZ = maxZ;
}
}
@Override
public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z, EntityPlayer player) {
TileEntity tile = world.getTileEntity(x, y, z);
if (tile instanceof TileStickyJar) {
ItemStack stack = ((TileStickyJar) tile).getParentBlock().getPickBlock(target, world, x, y, z, player);
NBTHelper.getData(stack).setBoolean("isStickyJar", true);
}
return null;
}
@Override
public TileStickyJar createTileEntity(World world, int metadata) {
return new TileStickyJar();
}
@Override
public int getRenderType() {
return RegisteredBlocks.rendererTransparentBlock;
}
public void onBlockPlacedOn(TileStickyJar tile, EntityLivingBase player) {
if (tile.placedOn != ForgeDirection.UP && tile.placedOn != ForgeDirection.DOWN) {
float pitch = player.rotationPitch;
float yaw = MathHelper.wrapAngleTo180_float(player.rotationYaw);
switch (tile.placedOn) {
case WEST:
yaw -= 90;
break;
case NORTH:
yaw = (180 - Math.abs(yaw)) * (yaw < 0 ? 1 : -1);
break;
case EAST:
yaw += 90;
break;
}
if (Math.abs(yaw) < Math.abs(pitch)) {
tile.facing = pitch < 0 ? ForgeDirection.SOUTH.ordinal() : ForgeDirection.NORTH.ordinal();
} else {
tile.facing = yaw < 0 ? ForgeDirection.EAST.ordinal() : ForgeDirection.WEST.ordinal();
}
}
}
@Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase ent, ItemStack stack) {
TileEntity tile = world.getTileEntity(x, y, z);
if (tile instanceof TileStickyJar) {
TileStickyJar stickyJar = (TileStickyJar) tile;
if (stickyJar.isValid()) {
stickyJar.getParentBlock().onBlockPlacedBy(world, x, y, z, ent, stack);
}
onBlockPlacedOn(stickyJar, ent);
}
}
public boolean isOpaqueCube() {
return false;
}
@Override
public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune) {
TileEntity tile = world.getTileEntity(x, y, z);
if (tile != null && tile instanceof TileStickyJar && ((TileStickyJar) tile).isValid()) {
ArrayList<ItemStack> drops = ((TileStickyJar) tile).getParentBlock()
.getDrops(world, x, y, z, world.getBlockMetadata(x, y, z), fortune);
boolean found = false;
for (ItemStack drop : drops) {
if (RegisteredItems.isStickyableJar(drop)) {
NBTHelper.getData(drop).setBoolean("isStickyJar", true);
found = true;
break;
}
}
if (!found) {
ItemStack item = new ItemStack(Items.slime_ball, 1);
drops.add(item);
}
return drops;
}
return new ArrayList<ItemStack>();
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float these, float are, float variables) {
TileEntity tile = world.getTileEntity(x, y, z);
if (tile instanceof TileStickyJar) {
TileStickyJar tileStickyJar = (TileStickyJar) tile;
StickyJarInfo info = RegisteredBlocks.getStickyJarInfo(tileStickyJar.getParentBlock(), world.getBlockMetadata(x, y, z));
ItemStack heldItem = player.getHeldItem();
if (info.needsPhialHandling() && heldItem != null && heldItem.getItem() == ConfigItems.itemEssence) {
if(!world.isRemote) {
handlePhial(world, x, y, z, player, heldItem, tileStickyJar);
}
return true;
}
boolean handleAspectFilter = info.needsLabelHandling() && heldItem != null && heldItem.getItem() == ConfigItems.itemResource
&& heldItem.getItemDamage() == 13 && tileStickyJar.aspectFilter == null
&& (((IEssentiaContainerItem) heldItem.getItem()).getAspects(heldItem) != null || tileStickyJar.amount != 0);
ForgeDirection newDir = tileStickyJar.changeDirection(ForgeDirection.getOrientation(side));
boolean result = ((TileStickyJar) tile).getParentBlock().onBlockActivated(world, x, y, z, player, newDir.ordinal(), these, are, variables);
if (handleAspectFilter) {
tileStickyJar.facing = newDir.ordinal();
tileStickyJar.markDirty();
}
return result;
}
return false;
}
public static void handlePhial(World world, int x, int y, int z, EntityPlayer player, ItemStack stack, TileJarFillable tile) {
ItemEssence itemEssence = (ItemEssence) ConfigItems.itemEssence;
AspectList aspects = itemEssence.getAspects(stack);
if(aspects != null) {
Map.Entry<Aspect, Integer> entry = aspects.aspects.entrySet().iterator().next();
Aspect jarAspect = tile.aspectFilter == null ? tile.aspect : tile.aspectFilter;
if((jarAspect == null || entry.getKey() == jarAspect) && tile.amount + entry.getValue() <= tile.maxAmount) {
tile.addToContainer(entry.getKey(), entry.getValue());
stack.stackSize--;
ItemStack essenceStack = new ItemStack(itemEssence, 1, 0);
if (!player.inventory.addItemStackToInventory(essenceStack)) {
world.spawnEntityInWorld(new EntityItem(world, x + 0.5F, y + 0.5F, z + 0.5F, essenceStack));
}
player.inventoryContainer.detectAndSendChanges();
}
} else {
Aspect aspect = tile.aspect;
if(aspect != null && tile.takeFromContainer(aspect, 8)) {
stack.stackSize--;
ItemStack essenceStack = new ItemStack(itemEssence, 1, 1);
itemEssence.setAspects(essenceStack, new AspectList().add(aspect, 8));
if (!player.inventory.addItemStackToInventory(essenceStack)) {
world.spawnEntityInWorld(new EntityItem(world, x + 0.5F, y + 0.5F, z + 0.5F, essenceStack));
}
player.inventoryContainer.detectAndSendChanges();
}
}
}
}
@@ -0,0 +1,44 @@
package makeo.gadomancy.common.blocks;
import makeo.gadomancy.common.Gadomancy;
import makeo.gadomancy.common.registration.RegisteredBlocks;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.util.IIcon;
/**
* 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
*
* Created by makeo @ 29.09.2015 22:07
*/
public abstract class BlockTransparent extends Block implements IBlockTransparent {
protected BlockTransparent(Material material) {
super(material);
}
private IIcon iconTransparent;
public IIcon getTransparentIcon() {
return iconTransparent;
}
@Override
public void registerBlockIcons(IIconRegister ir) {
iconTransparent = ir.registerIcon(Gadomancy.MODID + ":transparent");
super.registerBlockIcons(ir);
}
@Override
public int getRenderType() {
return RegisteredBlocks.rendererTransparentBlock;
}
@Override
public boolean renderAsNormalBlock() {
return false;
}
}
@@ -0,0 +1,15 @@
package makeo.gadomancy.common.blocks;
import net.minecraft.util.IIcon;
/**
* 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
*
* Created by makeo @ 06.10.2015 21:26
*/
public interface IBlockTransparent {
IIcon getTransparentIcon();
}
@@ -0,0 +1,44 @@
package makeo.gadomancy.common.blocks.tiles;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
/**
* 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
*
* Created by makeo @ 07.10.2015 18:39
*/
public class SynchronizedTileEntity extends TileEntity {
public void readFromNBT(NBTTagCompound compound) {
super.readFromNBT(compound);
readCustomNBT(compound);
}
public void readCustomNBT(NBTTagCompound compound) {
}
public void writeToNBT(NBTTagCompound compound) {
super.writeToNBT(compound);
writeCustomNBT(compound);
}
public void writeCustomNBT(NBTTagCompound compound) {
}
public Packet getDescriptionPacket() {
NBTTagCompound compound = new NBTTagCompound();
writeCustomNBT(compound);
return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 255, compound);
}
public void onDataPacket(NetworkManager manager, S35PacketUpdateTileEntity paket) {
super.onDataPacket(manager, paket);
readCustomNBT(paket.func_148857_g());
}
}
@@ -0,0 +1,238 @@
package makeo.gadomancy.common.blocks.tiles;
import makeo.gadomancy.common.registration.RegisteredBlocks;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import thaumcraft.common.lib.utils.InventoryUtils;
import java.util.ArrayList;
import java.util.List;
/**
* 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
*
* Created by makeo @ 28.09.2015 20:13
*/
public class TileArcaneDropper extends TileEntity implements IInventory, ISidedInventory {
private static final double RADIUS = 1.5;
private List<EntityItem> items = new ArrayList<EntityItem>();
private final List<EntityItem> dropQueue = new ArrayList<EntityItem>();
private int count = 0;
private int removedCount = 0;
private EntityItem removedEntity = null;
@Override
public void updateEntity() {
removedCount = 0;
removedEntity = null;
if(dropQueue.size() > 0) {
for(int i = 0; i < dropQueue.size(); i++) {
EntityItem item = dropQueue.get(i);
if(!item.isDead && !worldObj.loadedEntityList.contains(item)) {
getWorldObj().spawnEntityInWorld(item);
dropQueue.remove(i);
i--;
}
}
}
if(count > 20) {
count = 0;
World world = getWorldObj();
if(!world.isRemote) {
int oldSize = items.size();
updateInventory();
if(oldSize != 0 || items.size() != 0) {
//Comparator...
world.notifyBlockChange(xCoord, yCoord, zCoord, getBlockType());
}
}
}
count++;
}
private void updateInventory() {
ForgeDirection dir = ForgeDirection.getOrientation(getBlockMetadata() & 7);
double x = this.xCoord + dir.offsetX*2 + 0.5;
double y = this.yCoord + dir.offsetY*2 + 0.5;
double z = this.zCoord + dir.offsetZ*2 + 0.5;
AxisAlignedBB box = AxisAlignedBB.getBoundingBox(x, y, z, x, y, z).expand(RADIUS, RADIUS, RADIUS);
items = getWorldObj().getEntitiesWithinAABB(EntityItem.class, box);
//Add 10 empty slots
for(int i = 0; i < 10; i++) {
items.add(null);
}
}
private EntityItem dropItem(ItemStack stack) {
if(removedEntity != null && removedEntity.isDead) {
for(EntityItem entityItem : items) {
if(entityItem == removedEntity) {
if(InventoryUtils.areItemStacksEqualStrict(removedEntity.getEntityItem(), stack)
&& removedEntity.getEntityItem().stackSize + removedCount == stack.stackSize) {
removedEntity.getEntityItem().stackSize += removedCount;
removedEntity.isDead = false;
removedCount = 0;
removedEntity = null;
return entityItem;
}
}
}
}
ForgeDirection side = ForgeDirection.getOrientation(getBlockMetadata() & 7);
double x = this.xCoord + 0.5 + side.offsetX*0.5;
double y = this.yCoord + 0.25 + side.offsetY*0.5;
double z = this.zCoord + 0.5 + side.offsetZ*0.5;
EntityItem entityItem = new EntityItem(getWorldObj(), x, y, z, stack.copy());//
entityItem.motionX = side.offsetX*0.1;
entityItem.motionY = side.offsetY*0.1;
entityItem.motionZ = side.offsetZ*0.1;
entityItem.delayBeforeCanPickup = 3;
//prevent stackOverflows
dropQueue.add(entityItem);
return entityItem;
}
@Override
public int getSizeInventory() {
updateInventory();
return items.size();
}
@Override
public ItemStack getStackInSlot(int slot) {
updateInventory();
EntityItem entity = items.get(slot);
return entity == null || entity.isDead ? null : entity.getEntityItem();
}
@Override
public ItemStack decrStackSize(int slot, int amount) {
ItemStack stack = getStackInSlot(slot);
if(stack.stackSize - amount <= 0) {
setInventorySlotContents(slot, null);
return stack.copy();
}
ItemStack newStack = stack.copy();
newStack.stackSize = amount;
stack.stackSize -= amount;
removedEntity = items.get(slot);
removedCount = amount;
return newStack;
}
@Override
public void setInventorySlotContents(int slot, ItemStack stack) {
EntityItem oldEntity = items.get(slot);
if(oldEntity != null) {
oldEntity.setDead();
}
if(stack != null && stack.stackSize > 0) {
if(oldEntity != null && InventoryUtils.areItemStacksEqualStrict(oldEntity.getEntityItem(), stack)) {
oldEntity.getEntityItem().stackSize = stack.stackSize;
oldEntity.isDead = false;
} else {
items.set(slot, dropItem(stack));
}
}
}
@Override
public boolean isItemValidForSlot(int slot, ItemStack stack) {
return true;
}
@Override
public int getInventoryStackLimit() {
return 64;
}
@Override
public ItemStack getStackInSlotOnClosing(int p_70304_1_) {
return null;
}
@Override
public String getInventoryName() {
return RegisteredBlocks.blockArcaneDropper.getLocalizedName();
}
@Override
public boolean hasCustomInventoryName() {
return true;
}
@Override
public boolean isUseableByPlayer(EntityPlayer player) {
return false;
}
@Override
public void openInventory() {
}
@Override
public void closeInventory() {
}
@Override
public int[] getAccessibleSlotsFromSide(int side) {
int[] slots = new int[getSizeInventory()];
for(int i = 0; i < slots.length; i++) {
slots[i] = i;
}
return slots;
}
@Override
public boolean canInsertItem(int slot, ItemStack stack, int side) {
return RegisteredBlocks.blockArcaneDropper
.isSideSolid(getWorldObj(), this.xCoord, this.yCoord, this.zCoord, ForgeDirection.getOrientation(side));
}
@Override
public boolean canExtractItem(int slot, ItemStack stack, int side) {
if(canInsertItem(slot, stack, side)) {
EntityItem entityItem = items.get(slot);
return entityItem == null || entityItem.delayBeforeCanPickup <= 0;
}
return false;
}
}
@@ -0,0 +1,393 @@
package makeo.gadomancy.common.blocks.tiles;
import cpw.mods.fml.common.ObfuscationReflectionHelper;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import makeo.gadomancy.common.Gadomancy;
import makeo.gadomancy.api.ClickBehavior;
import makeo.gadomancy.common.entities.fake.AdvancedFakePlayer;
import makeo.gadomancy.common.network.PacketHandler;
import makeo.gadomancy.common.network.packets.PacketStartAnimation;
import makeo.gadomancy.common.registration.RegisteredBlocks;
import makeo.gadomancy.common.utils.NBTHelper;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.management.ItemInWorldManager;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraft.world.storage.IPlayerFileData;
import net.minecraft.world.storage.SaveHandler;
import net.minecraftforge.common.util.ForgeDirection;
import thaumcraft.api.aspects.Aspect;
import thaumcraft.api.aspects.AspectList;
import thaumcraft.common.Thaumcraft;
import thaumcraft.common.config.ConfigItems;
import thaumcraft.common.items.wands.ItemWandCasting;
import thaumcraft.common.items.wands.foci.ItemFocusPrimal;
import thaumcraft.common.lib.research.ResearchManager;
import java.io.File;
import java.util.ArrayList;
import java.util.Random;
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
*
* Created by makeo @ 05.10.2015 22:32
*/
public class TileInfusionClaw extends SynchronizedTileEntity implements IInventory, ISidedInventory {
private static final UUID FAKE_UUID = UUID.fromString("b23c8c3f-d7bd-49b3-970a-8e86728bab82");
private static final Random RANDOM = new Random();
private static final ItemWandCasting WAND_ITEM = (ItemWandCasting) ConfigItems.itemWandCasting;
private static final ItemFocusPrimal WAND_FOCUS = (ItemFocusPrimal) ConfigItems.itemFocusPrimal;
private static final AspectList MAX_WAND_COST = new AspectList().add(Aspect.WATER, 250).add(Aspect.AIR, 250).add(Aspect.EARTH, 250).add(Aspect.FIRE, 250).add(Aspect.ORDER, 250).add(Aspect.ENTROPY, 250);
private ItemInWorldManager im = null;
private Boolean redstoneState = null;
private int count = 0;
private String player = null;
private ItemStack wandStack = null;
private boolean isLocked = false;
private int cooldown;
@SideOnly(Side.CLIENT)
public float lastRenderTick;
/**
* 0-3: heightMov sides
* 4-7: widthMov sides
* 8: sides exp. speed
* 9: center exp. speed
* 10: rotation center
* 11: primal orb offset
*/
@SideOnly(Side.CLIENT)
public float[] animationStates;
public TileInfusionClaw() {
if(Gadomancy.proxy.getSide() == Side.CLIENT) {
animationStates = new float[12];
EntityLivingBase entity = Minecraft.getMinecraft().renderViewEntity;
lastRenderTick = entity == null ? 0 : entity.ticksExisted;
}
}
@Override
public void updateEntity() {
World world = getWorldObj();
if(!world.isRemote) {
if(redstoneState == null) {
redstoneState = world.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord);
}
if(cooldown > 0) {
cooldown--;
if(cooldown == (int)(7.5f*20)) {
performClickBlock();
}
}
if(count > 20) {
count = 0;
if(yCoord > 0) {
//Comparator...
world.notifyBlockChange(xCoord, yCoord, zCoord, getBlockType());
}
}
count++;
}
}
@Override
public void readCustomNBT(NBTTagCompound compound) {
if(compound.hasKey("player")) {
player = compound.getString("player");
}
wandStack = NBTHelper.getStack(compound, "wandStack");
isLocked = compound.getBoolean("isLocked");
}
@Override
public void writeCustomNBT(NBTTagCompound compound) {
if(hasOwner()) {
compound.setString("player", player);
}
if(wandStack != null) {
NBTHelper.setStack(compound, "wandStack", wandStack);
}
compound.setBoolean("isLocked", isLocked);
}
private void markForUpdate() {
markDirty();
getWorldObj().markBlockForUpdate(xCoord, yCoord, zCoord);
}
public void updateRedstone(boolean state) {
if(redstoneState != null && state && !redstoneState) {
startClickBlock();
}
redstoneState = state;
}
public boolean isLocked() {
return isLocked;
}
public void setIsLocked(boolean isLocked) {
this.isLocked = isLocked;
if(!getWorldObj().isRemote) {
markForUpdate();
}
}
public boolean setOwner(EntityPlayer player) {
World world = getWorldObj();
if(!world.isRemote && isValidOwner(player)) {
this.player = player.getCommandSenderName();
markForUpdate();
return true;
}
return false;
}
public boolean isValidOwner(EntityPlayer player) {
return !AdvancedFakePlayer.isFakePlayer(player);
}
private ArrayList<String> research = null;
private void loadResearch(EntityPlayer fakePlayer) {
boolean online = false;
for(String username : MinecraftServer.getServer().getAllUsernames()) {
if(username.equals(player)) {
online = true;
break;
}
}
if(online) {
this.research = ResearchManager.getResearchForPlayer(player);
} else {
if(research == null) {
Thaumcraft.proxy.getCompletedResearch().put(fakePlayer.getCommandSenderName(), new ArrayList<String>());
IPlayerFileData playerNBTManagerObj = MinecraftServer.getServer().worldServerForDimension(0).getSaveHandler().getSaveHandler();
SaveHandler sh = (SaveHandler)playerNBTManagerObj;
File dir = ObfuscationReflectionHelper.getPrivateValue(SaveHandler.class, sh, "playersDirectory", "field_75771_c");
File file1 = new File(dir, player + ".thaum");
File file2 = new File(dir, player + ".thaumbak");
ResearchManager.loadPlayerData(fakePlayer, file1, file2, false);
this.research = ResearchManager.getResearchForPlayerSafe(fakePlayer.getCommandSenderName());
}
}
Thaumcraft.proxy.getCompletedResearch().put(fakePlayer.getCommandSenderName(), research == null ? new ArrayList<String>() : research);
}
public String getOwner() {
return player;
}
public boolean hasOwner() {
return player != null;
}
private void startClickBlock() {
if(!isRunning()) {
ClickBehavior behavior = getClickBehavior(getWorldObj(), xCoord, yCoord-1, zCoord);
if(behavior != null && (!behavior.hasVisCost() || hasSufficientVis())) {
startRunning();
}
}
}
private void performClickBlock() {
World world = getWorldObj();
int x = xCoord;
int y = yCoord - 1;
int z = zCoord;
ClickBehavior behavior = getClickBehavior(world, x, y, z);
if(behavior != null) {
AdvancedFakePlayer fakePlayer = new AdvancedFakePlayer((WorldServer) world, FAKE_UUID);
loadResearch(fakePlayer);
if(behavior.hasVisCost()) {
if(hasSufficientVis()) {
consumeVis(fakePlayer);
} else {
return;
}
}
if(im == null) {
im = new ItemInWorldManager(world);
} else {
im.setWorld((WorldServer) world);
}
this.im.activateBlockOrUseItem(fakePlayer, world, new ItemStack(WAND_ITEM), x, y, z, ForgeDirection.UP.ordinal(), 0.5F, 0.5F, 0.5F);
addInstability(behavior);
}
}
private ClickBehavior getClickBehavior(World world, int x, int y, int z) {
if(y >= 0 && !world.isRemote && world instanceof WorldServer && hasOwner()
&& !world.isAirBlock(x, y, z) && wandStack != null && wandStack.stackSize > 0) {
return RegisteredBlocks.getClawClickBehavior(world, x, y, z);
}
return null;
}
public boolean isRunning() {
if(getWorldObj().isRemote) {
return animationStates[8] + animationStates[9] + animationStates[11] != 0;
}
return cooldown > 0;
}
private void startRunning() {
PacketHandler.INSTANCE.sendToAllAround(new PacketStartAnimation((byte)0, xCoord, yCoord, zCoord),
new NetworkRegistry.TargetPoint(getWorldObj().provider.dimensionId, xCoord + 0.5, yCoord + 0.5, zCoord + 0.5, 48));
cooldown = 22*20;
}
private void addInstability(ClickBehavior behavior) {
int instability = 23;
int maxVis = WAND_ITEM.getMaxVis(wandStack);
instability += maxVis < 100 ? 3 : -2;
instability -= Math.floor((maxVis > 300 ? 300 : maxVis) / 300f * 10f);
instability -= WAND_ITEM.isStaff(wandStack) ? 6 : -1;
instability += Math.floor((WAND_ITEM.getCap(wandStack).getBaseCostModifier() - 0.4) * 3);
instability -= WAND_ITEM.getCap(wandStack) == ConfigItems.WAND_CAP_VOID ? 3 : 0;
instability -= WAND_ITEM.getRod(wandStack) == ConfigItems.STAFF_ROD_PRIMAL ? 6 : 0;
behavior.addInstability(instability);
}
private boolean hasSufficientVis() {
return wandStack != null && wandStack.stackSize > 0 && WAND_ITEM.consumeAllVis(wandStack, null, MAX_WAND_COST, false, false);
}
private void consumeVis(EntityPlayer player) {
WAND_ITEM.consumeAllVis(wandStack, player, WAND_FOCUS.getVisCost(wandStack), true, false);
markForUpdate();
}
@Override
public int getSizeInventory() {
return 1;
}
@Override
public ItemStack getStackInSlot(int slot) {
return wandStack;
}
@Override
public ItemStack decrStackSize(int slot, int amount) {
if(isRunning()) {
return null;
}
if(amount > 0) {
ItemStack result = wandStack.copy();
wandStack = null;
markForUpdate();
return result;
}
return null;
}
@Override
public ItemStack getStackInSlotOnClosing(int p_70304_1_) {
return null;
}
@Override
public void setInventorySlotContents(int slot, ItemStack stack) {
wandStack = stack;
markForUpdate();
}
@Override
public String getInventoryName() {
return null;
}
@Override
public boolean hasCustomInventoryName() {
return false;
}
@Override
public int getInventoryStackLimit() {
return 1;
}
@Override
public boolean isUseableByPlayer(EntityPlayer player) {
return true;
}
@Override
public void openInventory() {
}
@Override
public void closeInventory() {
}
@Override
public boolean isItemValidForSlot(int slot, ItemStack stack) {
if(isRunning()) {
return false;
}
if(stack.getItem() == WAND_ITEM) {
return !WAND_ITEM.isSceptre(stack) && WAND_ITEM.getFocus(stack) == null;
}
return false;
}
@Override
public int[] getAccessibleSlotsFromSide(int side) {
return new int[]{0};
}
@Override
public boolean canInsertItem(int slot, ItemStack stack, int side) {
return !isRunning() && side > 0 && side < 6;
}
@Override
public boolean canExtractItem(int slot, ItemStack stack, int side) {
return (!isLocked() || !hasSufficientVis()) && canInsertItem(slot, stack, side);
}
}
@@ -0,0 +1,80 @@
package makeo.gadomancy.common.blocks.tiles;
import thaumcraft.common.tiles.TileJarFillable;
import java.util.*;
/**
* 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
*
* Created by makeo @ 14.10.2015 15:06
*/
public class TileRemoteJar extends TileJarFillable {
public UUID networkId = null;
private int count = 0;
@Override
public void updateEntity() {
super.updateEntity();
if (count % 5 == 0 && !getWorldObj().isRemote && networkId != null && amount < maxAmount) {
count = 0;
boolean containsThis = false;
List<TileRemoteJar> network = getNetwork(networkId);
Collections.sort(network, new Comparator<TileRemoteJar>() {
@Override
public int compare(TileRemoteJar o1, TileRemoteJar o2) {
return o2.amount - o1.amount;
}
});
for(int i = 0; i < network.size(); i++) {
TileRemoteJar jar = network.get(i);
if(jar == this) {
containsThis = true;
continue;
}
if(jar.isInvalid()) {
network.remove(i);
i--;
continue;
}
if((amount+1) < jar.amount && this.addToContainer(jar.aspect, 1) == 0) {
jar.takeFromContainer(jar.aspect, 1);
break;
}
}
if(!containsThis) {
network.add(this);
}
}
count++;
}
private static Map<UUID, List<TileRemoteJar>> networks = new HashMap<UUID, List<TileRemoteJar>>();
private static List<TileRemoteJar> getNetwork(UUID id) {
List<TileRemoteJar> network = networks.get(id);
if(network == null) {
network = new ArrayList<TileRemoteJar>();
networks.put(id, network);
}
return network;
}
public void markForUpdate() {
markDirty();
getWorldObj().markBlockForUpdate(xCoord, yCoord, zCoord);
}
}
@@ -0,0 +1,454 @@
package makeo.gadomancy.common.blocks.tiles;
import cpw.mods.fml.common.registry.GameData;
import makeo.gadomancy.common.utils.Injector;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.init.Blocks;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import thaumcraft.api.ThaumcraftApiHelper;
import thaumcraft.api.aspects.Aspect;
import thaumcraft.api.aspects.AspectList;
import thaumcraft.api.aspects.IEssentiaTransport;
import thaumcraft.common.tiles.TileJarFillable;
import java.lang.reflect.Field;
/**
* 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
*
* Created by makeo @ 13.07.2015 15:48
*/
public class TileStickyJar extends TileJarFillable {
private Block parentBlock;
private Integer parentMetadata = 0;
private TileJarFillable parent = null;
public ForgeDirection placedOn;
private final Injector injector;
private Field fieldCount;
public TileStickyJar() {
injector = new Injector(null, TileJarFillable.class);
fieldCount = Injector.getField("count", TileJarFillable.class);
}
public Block getParentBlock() {
return parentBlock;
}
public TileJarFillable getParent() {
return parent;
}
public boolean isValid() {
return parentBlock != null && parent != null;
}
private boolean needsRenderUpdate = false;
public void init(TileJarFillable parent, Block parentBlock, int parentMetadata, ForgeDirection placedOn) {
this.parent = parent;
this.placedOn = placedOn;
parent.xCoord = xCoord;
parent.yCoord = yCoord;
parent.zCoord = zCoord;
syncFromParent();
this.parent.setWorldObj(getWorldObj());
this.parentBlock = parentBlock;
this.parentMetadata = parentMetadata;
this.injector.setObject(this.parent);
markDirty();
needsRenderUpdate = true;
}
private void sync(TileJarFillable from, TileJarFillable to) {
to.aspect = from.aspect;
to.aspectFilter = from.aspectFilter;
to.amount = from.amount;
to.maxAmount = from.maxAmount;
to.facing = from.facing;
to.forgeLiquid = from.forgeLiquid;
to.lid = from.lid;
}
public void syncToParent() {
sync(this, parent);
}
public void syncFromParent() {
sync(parent, this);
}
private int count;
@Override
public void updateEntity() {
if(!isValid()) {
if(!getWorldObj().isRemote) {
getWorldObj().setBlock(this.xCoord, this.yCoord, this.zCoord, Blocks.air);
}
return;
}
if(getWorldObj().isRemote && needsRenderUpdate) {
needsRenderUpdate = false;
Minecraft.getMinecraft().renderGlobal.markBlockForUpdate(xCoord, yCoord, zCoord);
}
syncToParent();
if ((!this.worldObj.isRemote) && (++this.count % 5 == 0) && (this.amount < this.maxAmount)) {
fillJar();
}
injector.setField(fieldCount, 1);
parent.updateEntity();
syncFromParent();
}
@Override
public void setWorldObj(World world) {
super.setWorldObj(world);
if(parent != null)
parent.setWorldObj(worldObj);
}
private void fillJar() {
ForgeDirection inputDir = placedOn.getOpposite();
TileEntity te = ThaumcraftApiHelper.getConnectableTile(parent.getWorldObj(), parent.xCoord, parent.yCoord, parent.zCoord, inputDir);
if (te != null)
{
IEssentiaTransport ic = (IEssentiaTransport)te;
if (!ic.canOutputTo(ForgeDirection.DOWN)) {
return;
}
Aspect ta = null;
if (parent.aspectFilter != null) {
ta = parent.aspectFilter;
} else if ((parent.aspect != null) && (parent.amount > 0)) {
ta = parent.aspect;
} else if ((ic.getEssentiaAmount(inputDir.getOpposite()) > 0) &&
(ic.getSuctionAmount(inputDir.getOpposite()) < getSuctionAmount(ForgeDirection.UP)) && (getSuctionAmount(ForgeDirection.UP) >= ic.getMinimumSuction())) {
ta = ic.getEssentiaType(inputDir.getOpposite());
}
if ((ta != null) && (ic.getSuctionAmount(inputDir.getOpposite()) < getSuctionAmount(ForgeDirection.UP))) {
addToContainer(ta, ic.takeEssentia(ta, 1, inputDir.getOpposite()));
}
}
}
@Override
public void readCustomNBT(NBTTagCompound compound) {
String parentType = compound.getString("parentType");
if(parentType.length() > 0) {
Block block = GameData.getBlockRegistry().getObject(parentType);
if(block != null && compound.hasKey("parent") && compound.hasKey("parentMetadata")) {
NBTTagCompound data = compound.getCompoundTag("parent");
int metadata = compound.getInteger("parentMetadata");
TileEntity tile = block.createTileEntity(getWorldObj(), metadata);
if(tile instanceof TileJarFillable) {
placedOn = ForgeDirection.getOrientation(compound.getInteger("placedOn"));
tile.readFromNBT(data);
init((TileJarFillable) tile, block, metadata, placedOn);
}
}
}
if(!isValid() && !getWorldObj().isRemote) {
getWorldObj().setBlockToAir(xCoord, yCoord, zCoord);
}
}
@Override
public void writeCustomNBT(NBTTagCompound compound) {
if(isValid()) {
compound.setString("parentType", GameData.getBlockRegistry().getNameForObject(parentBlock));
compound.setInteger("parentMetadata", parentMetadata);
syncToParent();
NBTTagCompound data = new NBTTagCompound();
parent.writeToNBT(data);
compound.setTag("parent", data);
compound.setInteger("placedOn", placedOn.ordinal());
}
}
@Override
public AspectList getAspects() {
if(isValid()) {
syncToParent();
AspectList result = parent.getAspects();
syncFromParent();
return result;
}
return new AspectList();
}
@Override
public void setAspects(AspectList paramAspectList) {
if(isValid()) {
syncToParent();
parent.getAspects();
syncFromParent();
}
}
@Override
public boolean doesContainerAccept(Aspect paramAspect) {
if(isValid()) {
syncToParent();
boolean result = parent.doesContainerAccept(paramAspect);
syncFromParent();
return result;
}
return false;
}
@Override
public int addToContainer(Aspect paramAspect, int paramInt) {
if(isValid()) {
syncToParent();
int result = parent.addToContainer(paramAspect, paramInt);
syncFromParent();
return result;
}
return paramInt;
}
@Override
public boolean takeFromContainer(Aspect paramAspect, int paramInt) {
if(isValid()) {
syncToParent();
boolean result = parent.takeFromContainer(paramAspect, paramInt);
syncFromParent();
return result;
}
return false;
}
@Override
public boolean takeFromContainer(AspectList paramAspectList) {
if(isValid()) {
syncToParent();
boolean result = parent.takeFromContainer(paramAspectList);
syncFromParent();
return result;
}
return false;
}
@Override
public boolean doesContainerContainAmount(Aspect paramAspect, int paramInt) {
if(isValid()) {
syncToParent();
boolean result = parent.doesContainerContainAmount(paramAspect, paramInt);
syncFromParent();
return result;
}
return false;
}
@Override
public boolean doesContainerContain(AspectList paramAspectList) {
if(isValid()) {
syncToParent();
boolean result = parent.doesContainerContain(paramAspectList);
syncFromParent();
return result;
}
return false;
}
@Override
public int containerContains(Aspect paramAspect) {
if(isValid()) {
syncToParent();
int result = parent.containerContains(paramAspect);
syncFromParent();
return result;
}
return 0;
}
@Override
public boolean isConnectable(ForgeDirection face) {
if(isValid()) {
syncToParent();
return parent.isConnectable(changeDirection(face));
}
return false;
}
@Override
public boolean canInputFrom(ForgeDirection face) {
if(isValid()) {
syncToParent();
boolean result = parent.canInputFrom(changeDirection(face));
syncFromParent();
return result;
}
return false;
}
@Override
public boolean canOutputTo(ForgeDirection face) {
if(isValid()) {
syncToParent();
boolean result = parent.canOutputTo(changeDirection(face));
syncFromParent();
return result;
}
return false;
}
public ForgeDirection changeDirection(ForgeDirection face) {
if(placedOn == ForgeDirection.UP) {
if(face == ForgeDirection.UP || face == ForgeDirection.DOWN) {
return face.getOpposite();
}
return face;
}
if(placedOn == ForgeDirection.DOWN) {
return face;
}
if(face == ForgeDirection.UP) {
return ForgeDirection.NORTH;
}
if(face == ForgeDirection.DOWN) {
return ForgeDirection.SOUTH;
}
if(face == placedOn) {
return ForgeDirection.DOWN;
}
if(face == placedOn.getOpposite()) {
return ForgeDirection.UP;
}
switch (placedOn) {
case EAST: return face == ForgeDirection.NORTH ? ForgeDirection.WEST : ForgeDirection.EAST;
case SOUTH: return face.getOpposite();
case WEST: return face == ForgeDirection.SOUTH ? ForgeDirection.WEST : ForgeDirection.EAST;
}
return face;
}
@Override
public void setSuction(Aspect paramAspect, int paramInt) {
if(isValid()) {
syncToParent();
parent.setSuction(paramAspect, paramInt);
syncFromParent();
}
}
@Override
public Aspect getSuctionType(ForgeDirection paramForgeDirection) {
if(isValid()) {
syncToParent();
Aspect result = parent.getSuctionType(changeDirection(paramForgeDirection));
syncFromParent();
return result;
}
return null;
}
@Override
public int getSuctionAmount(ForgeDirection paramForgeDirection) {
if(isValid()) {
syncToParent();
int result = parent.getSuctionAmount(changeDirection(paramForgeDirection));
syncFromParent();
return result;
}
return 0;
}
@Override
public int takeEssentia(Aspect paramAspect, int paramInt, ForgeDirection paramForgeDirection) {
if(isValid()) {
syncToParent();
int result = parent.takeEssentia(paramAspect, paramInt, changeDirection(paramForgeDirection));
syncFromParent();
return result;
}
return paramInt;
}
@Override
public int addEssentia(Aspect paramAspect, int paramInt, ForgeDirection paramForgeDirection) {
if(isValid()) {
syncToParent();
int result = parent.addEssentia(paramAspect, paramInt, changeDirection(paramForgeDirection));
syncFromParent();
return result;
}
return paramInt;
}
@Override
public Aspect getEssentiaType(ForgeDirection paramForgeDirection) {
if(isValid()) {
syncToParent();
Aspect result = parent.getEssentiaType(changeDirection(paramForgeDirection));
syncFromParent();
return result;
}
return null;
}
@Override
public int getEssentiaAmount(ForgeDirection paramForgeDirection) {
if(isValid()) {
syncToParent();
int result = parent.getEssentiaAmount(changeDirection(paramForgeDirection));
syncFromParent();
return result;
}
return 0;
}
@Override
public int getMinimumSuction() {
if(isValid()) {
syncToParent();
int result = parent.getMinimumSuction();
syncFromParent();
return result;
}
return 0;
}
@Override
public boolean renderExtendedTube() {
if(isValid()) {
syncToParent();
boolean result = parent.renderExtendedTube();
syncFromParent();
return result;
}
return false;
}
}
@@ -0,0 +1,108 @@
package makeo.gadomancy.common.containers;
import makeo.gadomancy.common.blocks.tiles.TileInfusionClaw;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
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
*
* Created by makeo @ 09.10.2015 20:34
*/
public class ContainerInfusionClaw extends Container {
public final InventoryPlayer playerInv;
public final IInventory clawInv;
public ContainerInfusionClaw(InventoryPlayer playerInv, IInventory clawInv) {
this.playerInv = playerInv;
this.clawInv = clawInv;
addSlotToContainer(new FilteredSlot(clawInv, 0, 80, 32));
bindPlayerInventory();
}
protected void bindPlayerInventory() {
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 9; j++) {
addSlotToContainer(new Slot(this.playerInv, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
}
}
for (int i = 0; i < 9; i++) {
addSlotToContainer(new Slot(this.playerInv, i, 8 + i * 18, 142));
}
}
@Override
public ItemStack transferStackInSlot(EntityPlayer player, int slotIndex) {
if(((TileInfusionClaw)clawInv).isRunning()) {
return null;
}
ItemStack itemstack = null;
Slot slot = (Slot) this.inventorySlots.get(slotIndex);
if (slot != null && slot.getHasStack()) {
ItemStack itemstack1 = slot.getStack();
itemstack = itemstack1.copy();
if (slotIndex == 0) {
if (!this.mergeItemStack(itemstack1, 1, this.inventorySlots.size(), true)) {
return null;
}
} else {
if(!((Slot)inventorySlots.get(0)).isItemValid(itemstack1)) {
return null;
}
if (!this.mergeItemStack(itemstack1, 0, 1, false)) {
return null;
}
}
if (itemstack1.stackSize == 0) {
slot.putStack(null);
} else {
slot.onSlotChanged();
}
}
return itemstack;
}
@Override
public boolean enchantItem(EntityPlayer player, int value) {
((TileInfusionClaw)clawInv).setIsLocked(value == 1);
return false;
}
/*public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int slot) {
ItemStack stack = null;
Slot slotObject = (Slot) this.inventorySlots.get(slot);
if(slotObject != null && slotObject.getHasStack()) {
ItemStack stackInSlot = slotObject.getStack();
if (!mergeItemStack(stackInSlot, 0, 1, false)) {
return null;
}
if (stackInSlot.stackSize == 0) {
slotObject.putStack(null);
} else {
slotObject.onSlotChanged();
}
}
return stack;
}*/
@Override
public boolean canInteractWith(EntityPlayer player) {
return clawInv.isUseableByPlayer(player);
}
}
@@ -0,0 +1,24 @@
package makeo.gadomancy.common.containers;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
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
*
* Created by makeo @ 10.10.2015 13:49
*/
public class FilteredSlot extends Slot {
public FilteredSlot(IInventory inventory, int slotNumber, int xDisplayPosition, int yDisplayPosition) {
super(inventory, slotNumber, xDisplayPosition, yDisplayPosition);
}
@Override
public boolean isItemValid(ItemStack stack) {
return inventory.isItemValidForSlot(slotNumber, stack);
}
}
@@ -0,0 +1,61 @@
package makeo.gadomancy.common.crafting;
import makeo.gadomancy.api.GadomancyApi;
import makeo.gadomancy.api.golems.AdditionalGolemType;
import makeo.gadomancy.common.entities.golems.upgrades.GolemUpgrade;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import thaumcraft.api.aspects.AspectList;
import thaumcraft.api.crafting.InfusionRecipe;
import thaumcraft.common.config.ConfigItems;
import thaumcraft.common.entities.golems.EnumGolemType;
import java.util.ArrayList;
/**
* 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
*
* Created by makeo @ 21.07.2015 20:16
*/
public class InfusionUpgradeRecipe extends InfusionRecipe {
private static final ItemStack DEFAULT_OUTPUT = new ItemStack(Blocks.dirt);
private final GolemUpgrade upgrade;
private InfusionUpgradeRecipe(String research, GolemUpgrade upgrade, int inst, AspectList aspects2, ItemStack input, ItemStack[] recipe) {
super(research, DEFAULT_OUTPUT, inst, aspects2, input, recipe);
this.upgrade = upgrade;
}
@Override
public boolean matches(ArrayList<ItemStack> input, ItemStack central, World world, EntityPlayer player) {
return super.matches(input, central, world, player) && !upgrade.hasUpgrade(central);
}
@Override
public Object getRecipeOutput(ItemStack input) {
ItemStack output = input.copy();
upgrade.addUpgrade(output);
return output;
}
public static InfusionUpgradeRecipe[] createRecipes(String research, GolemUpgrade upgrade, int inst, AspectList aspects, ItemStack[] recipe) {
InfusionUpgradeRecipe[] recipes = new InfusionUpgradeRecipe[EnumGolemType.values().length];
for(int i = 0; i < EnumGolemType.values().length ; i++) {
EnumGolemType type = EnumGolemType.values()[i];
AdditionalGolemType addType = GadomancyApi.getAdditionalGolemType(type);
Item input = addType == null ? ConfigItems.itemGolemPlacer : addType.getPlacerItem();
recipes[i] = new InfusionUpgradeRecipe(research, upgrade, inst, aspects, new ItemStack(input, 1, type.ordinal()), recipe);
}
return recipes;
}
}
@@ -0,0 +1,114 @@
package makeo.gadomancy.common.crafting;
import makeo.gadomancy.common.registration.RegisteredItems;
import makeo.gadomancy.common.research.SimpleResearchItem;
import makeo.gadomancy.common.utils.NBTHelper;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import thaumcraft.api.aspects.Aspect;
import thaumcraft.api.aspects.AspectList;
import thaumcraft.api.crafting.IArcaneRecipe;
/**
* 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
*
* Created by makeo @ 13.07.2015 19:21
*/
public class RecipeStickyJar implements IArcaneRecipe {
@Override
public boolean matches(IInventory inv, World world, EntityPlayer player) {
return getJarItem(inv) != null;
}
@Override
public ItemStack getCraftingResult(IInventory inv) {
ItemStack jarItem = getJarItem(inv);
if(jarItem != null) {
ItemStack result = jarItem.copy();
result.stackSize = 1;
NBTHelper.getData(result).setBoolean("isStickyJar", true);
return result;
}
return null;
}
private ItemStack getJarItem(IInventory inv) {
int itemCount = 0;
int invWidth = (int) Math.sqrt(inv.getSizeInventory());
ItemStack jarItem = null;
for(int i = 0; i < invWidth*invWidth; i++) {
ItemStack current = inv.getStackInSlot(i);
if(current != null) {
itemCount++;
if(itemCount > 2) {
return null;
}
if(jarItem == null) {
if(current.getItem() == Items.slime_ball) {
return null;
}
boolean isSticky = RegisteredItems.isStickyableJar(current) && (!current.hasTagCompound()
|| !current.getTagCompound().getBoolean("isStickyJar"));
if(current.getItem() != Items.slime_ball && !isSticky) {
return null;
}
if(isSticky) {
int slimeSlot = i + invWidth;
if(slimeSlot < 0 || slimeSlot > inv.getSizeInventory()) {
return null;
}
ItemStack slime = inv.getStackInSlot(slimeSlot);
if(slime == null || slime.getItem() != Items.slime_ball) {
return null;
}
jarItem = current;
}
}
}
}
return jarItem;
}
@Override
public int getRecipeSize() {
return 10;
}
@Override
public ItemStack getRecipeOutput() {
return null;
}
@Override
public AspectList getAspects() {
return new AspectList().add(Aspect.WATER, 10).add(Aspect.EARTH, 10);
}
@Override
public AspectList getAspects(IInventory inv) {
return null;
}
@Override
public String getResearch() {
return SimpleResearchItem.getFullName("STICKYJAR");
}
}
@@ -0,0 +1,37 @@
package makeo.gadomancy.common.data;
import net.minecraftforge.common.config.Configuration;
import java.io.File;
/**
* 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
*
* Created by makeo @ 15.09.2015 18:25
*/
public class ModConfig {
private static Configuration config;
private ModConfig() {}
public static void init(File file) {
config = new Configuration(file);
config.load();
getGolemDatawatcherId();
config.save();
}
private static int golemDatawatcherId = -1;
public static int getGolemDatawatcherId() {
if(golemDatawatcherId < 0) {
golemDatawatcherId = config.getInt("datawatcherId", "golem", 29, 0, 31, "Do not edit unless you know what are you doing!");
}
return golemDatawatcherId;
}
}
@@ -0,0 +1,116 @@
package makeo.gadomancy.common.data;
import com.google.gson.Gson;
import cpw.mods.fml.common.FMLLog;
import makeo.gadomancy.common.Gadomancy;
import net.minecraft.server.MinecraftServer;
import java.io.*;
import java.util.HashMap;
import java.util.Map;
/**
* 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
*
* Created by makeo @ 26.07.2015 18:15
*/
public class ModData {
private static final Gson GSON = new Gson();
private String name;
private File file;
private Map<String, Object> data = new HashMap<String, Object>();
public ModData(String name, File directory) {
if(directory == null)
throw new IllegalArgumentException("Directory is null!");
this.name = name;
this.file = new File(directory, name + ".dat");
}
public ModData(String name) {
this(name, geDefaultDirectory());
}
private static File geDefaultDirectory() {
MinecraftServer server = MinecraftServer.getServer();
if(server != null && server.getEntityWorld() != null) {
File file = server.getEntityWorld().getSaveHandler().getWorldDirectory();
if(file != null) {
return new File(file, Gadomancy.MODID);
}
}
return null;
}
public <T> T get(String key, T defaultValue) {
if(data.containsKey(key)) {
return (T) data.get(key);
}
data.put(key, defaultValue);
return defaultValue;
}
public <T> T get(String key) {
return get(key, null);
}
public void set(String key, Object value) {
data.put(key, value);
}
public boolean contains(String key) {
return data.containsKey(key);
}
public boolean load() {
if(file.exists()) {
FileInputStream in = null;
try {
in = new FileInputStream(file);
data = (Map<String, Object>) new ObjectInputStream(in).readObject();
} catch (Exception e) { //IOException | ClassCastException | JsonSyntaxException | ClassNotFoundException
e.printStackTrace();
return false;
} finally {
if(in != null)
try {
in.close();
} catch (IOException ignored) { }
}
}
return true;
}
public boolean save() {
if(!file.getParentFile().exists() && !file.getParentFile().mkdirs()) {
FMLLog.warning("Failed to create directory: \"" + file.toString() + "\"!");
return false;
}
FileOutputStream out = null;
try {
if(!file.exists())
file.createNewFile();
out = new FileOutputStream(file);
new ObjectOutputStream(out).writeObject(data);
} catch (Exception e) {//JsonIOException | IOException
e.printStackTrace();
return false;
} finally {
if(out != null)
try {
out.close();
} catch (IOException ignored) { }
}
return true;
}
}
@@ -0,0 +1,322 @@
package makeo.gadomancy.common.entities.ai;
import makeo.gadomancy.common.entities.fake.AdvancedFakePlayer;
import makeo.gadomancy.common.entities.fake.GolemFakePlayer;
import net.minecraft.block.Block;
import net.minecraft.entity.ai.EntityAIBase;
import net.minecraft.init.Blocks;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.server.management.ItemInWorldManager;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ChunkCoordinates;
import net.minecraft.world.WorldServer;
import net.minecraftforge.common.util.ForgeDirection;
import thaumcraft.common.config.Config;
import thaumcraft.common.entities.golems.EntityGolemBase;
import thaumcraft.common.entities.golems.Marker;
import thaumcraft.common.lib.utils.InventoryUtils;
import java.util.*;
/**
* 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
*
* Created by makeo @ 17.09.2015 20:22
*/
public class AIBreakBlock extends EntityAIBase {
private static final int BLACKLIST_TICKS = 20*40;
private EntityGolemBase golem;
private AdvancedFakePlayer player;
private Marker currentMarker;
private boolean hasValidTool = false;
private Map<Marker, Integer> blacklist = new HashMap<Marker, Integer>();
private int blacklistCount = 0;
public AIBreakBlock(EntityGolemBase golem) {
this.golem = golem;
if (golem.worldObj instanceof WorldServer) {
this.player = new GolemFakePlayer((WorldServer) golem.worldObj, golem);
}
setMutexBits(3);
}
@Override
public boolean shouldExecute() {
if (golem.ticksExisted % Config.golemDelay > 0) {
return false;
}
currentMarker = getNextMarker();
if(!hasValidTool()) {
if(isInHomeRange()) {
return true;
}
return false;
}
return currentMarker != null;
}
private int count = 0;
private int clickCount = 0;
@Override
public boolean continueExecuting() {
if(hasValidTool) {
if(!hasBlock(currentMarker)) {
return false;
}
if(distanceSquaredToGolem(currentMarker) < 1) {
if(golem.getCarried() == null) {
golem.startActionTimer();
} else {
golem.startRightArmTimer();
}
if(clickCount % (7 - Math.min(6, golem.getGolemStrength())) == 0) {
doLeftClick();
}
clickCount++;
golem.getLookHelper().setLookPosition(currentMarker.x + 0.5D, currentMarker.y + 0.5D, currentMarker.z + 0.5D, 30.0F, 30.0F);
count = 0;
} else {
if(count == 20) {
count = 0;
ForgeDirection dir = ForgeDirection.getOrientation(currentMarker.side);
boolean path = golem.getNavigator().tryMoveToXYZ(currentMarker.x + 0.5D + dir.offsetX, currentMarker.y + 0.5D + dir.offsetY, currentMarker.z + 0.5D + dir.offsetZ, golem.getAIMoveSpeed());
if(!path) {
if (blacklistCount > 10) {
blacklist.put(currentMarker, golem.ticksExisted);
return false;
}
blacklistCount++;
}
}
count++;
clickCount = 0;
}
} else {
if(golem.ticksExisted % Config.golemDelay > 0) {
if(isInHomeRange()) {
IInventory homeChest = getHomeChest();
if(homeChest != null) {
trySwitchTool(homeChest);
}
} else {
return false;
}
}
}
return true;
}
@Override
public void resetTask() {
currentMarker = null;
blacklistCount = 0;
cancelLeftClick();
}
public void doLeftClick() {
ItemStack tool = golem.getCarried();
player.setHeldItem(tool);
player.theItemInWorldManager.updateBlockRemoving();
if (this.player.theItemInWorldManager.durabilityRemainingOnBlock == -1 || !this.player.theItemInWorldManager.isDestroyingBlock)
{
this.player.theItemInWorldManager.onBlockClicked(currentMarker.x, currentMarker.y, currentMarker.z, currentMarker.side);
}
else if (this.player.theItemInWorldManager.durabilityRemainingOnBlock >= 9)
{
this.player.theItemInWorldManager.uncheckedTryHarvestBlock(currentMarker.x, currentMarker.y, currentMarker.z);
this.player.theItemInWorldManager.durabilityRemainingOnBlock = -1;
if (tool != null) {
Block block = golem.worldObj.getBlock(currentMarker.x, currentMarker.y, currentMarker.z);
tool.getItem().onBlockDestroyed(tool, golem.worldObj, block, currentMarker.x, currentMarker.y, currentMarker.z, this.player);
}
}
hasValidTool();
golem.updateCarried();
}
public void cancelLeftClick() {
ItemInWorldManager manager = player.theItemInWorldManager;
if(manager.isDestroyingBlock)
player.theItemInWorldManager.cancelDestroyingBlock(manager.partiallyDestroyedBlockX, manager.partiallyDestroyedBlockY, manager.partiallyDestroyedBlockZ);
}
private Marker getNextMarker() {
List<Marker> markers = golem.getMarkers();
Collections.sort(markers, new Comparator<Marker>() {
@Override
public int compare(Marker m1, Marker m2) {
return (int) (distanceSquaredToGolem(m1) - distanceSquaredToGolem(m2));
}
});
for(Marker marker : markers) {
if(isValid(marker)) {
return marker;
}
}
return null;
}
private double distanceSquaredToGolem(Marker marker) {
return distanceSquaredToGolem(marker.x, marker.y, marker.z, marker.side);
}
private double distanceSquaredToGolem(double x, double y, double z, int facing) {
ForgeDirection dir = ForgeDirection.getOrientation(facing);
return this.golem.getDistanceSq(x + 0.5 + (0.5*dir.offsetX),
y + 0.5 + (0.5*dir.offsetY), z + 0.5 + (0.5*dir.offsetZ));
}
private boolean isInHomeRange() {
ChunkCoordinates home = golem.getHomePosition();
return golem.getDistanceSq(home.posX + 0.5, home.posY + 0.5, home.posZ + 0.5) < 3;
}
private boolean hasBlock(Marker marker) {
return marker != null && !golem.worldObj.isAirBlock(marker.x, marker.y, marker.z);
}
private boolean isValid(Marker marker) {
if(marker == null) return false;
if(blacklist.containsKey(marker)) {
if(blacklist.get(marker) + BLACKLIST_TICKS >= golem.ticksExisted) {
return false;
} else {
blacklist.remove(marker);
}
}
float range = golem.getRange();
if(golem.getHomePosition().getDistanceSquared(marker.x, marker.y, marker.z) > range * range) {
return false;
}
Block block = golem.worldObj.getBlock(marker.x, marker.y, marker.z);
if(!block.isAir(golem.worldObj, marker.x, marker.y, marker.z)) {
ItemStack blockStack = new ItemStack(Item.getItemFromBlock(block));
boolean empty = true;
for(int slot = 0; slot < golem.inventory.slotCount; slot++) {
ItemStack stack = golem.inventory.inventory[slot];
if(stack != null && Block.getBlockFromItem(stack.getItem()) != Blocks.air) {
empty = false;
if((marker.color == -1 || marker.color == golem.colors[slot])
&& InventoryUtils.areItemStacksEqual(blockStack, stack,
golem.checkOreDict(), golem.ignoreDamage(), golem.ignoreNBT())) {
return true;
}
}
}
if(empty) {
return true;
}
}
return false;
}
private IInventory getHomeChest() {
ChunkCoordinates coords = golem.getHomePosition();
ForgeDirection facing = ForgeDirection.getOrientation(golem.homeFacing);
TileEntity tile = golem.worldObj.getTileEntity(coords.posX - facing.offsetX, coords.posY - facing.offsetY, coords.posZ - facing.offsetZ);
if(tile != null && tile instanceof IInventory) {
return (IInventory) tile;
}
return null;
}
private void trySwitchTool(IInventory inv) {
for(int slot = 0; slot < inv.getSizeInventory(); slot++) {
ItemStack stack = inv.getStackInSlot(slot);
ItemStack current = golem.getCarried();
if(current != null) {
current = InventoryUtils.insertStack(inv, current, golem.homeFacing, true);
if(current != null) {
return;
}
golem.setCarried(null);
if(hasValidTool()) {
hasValidTool = true;
return;
}
}
if(stack != null && isValidTool(stack)) {
stack = stack.copy();
stack.stackSize = 1;
stack = InventoryUtils.extractStack(inv, stack, golem.homeFacing, false, false, false, true);
if(stack != null) {
golem.setCarried(stack);
golem.updateCarried();
player.setHeldItem(stack);
hasValidTool = true;
break;
}
}
}
}
private boolean hasValidTool() {
hasValidTool = isValidTool(golem.getCarried());
return hasValidTool;
}
private boolean isValidTool(ItemStack tool) {
if(tool == null || Block.getBlockFromItem(tool.getItem()) == Blocks.air) {
boolean empty = true;
for(int slot = 0; slot < golem.inventory.slotCount; slot++) {
ItemStack stack = golem.inventory.inventory[slot];
if(stack != null && Block.getBlockFromItem(stack.getItem()) == Blocks.air
&& (currentMarker == null || golem.colors[slot] == -1 || currentMarker.color == -1 || golem.colors[slot] == currentMarker.color)) {
empty = false;
if(tool == null) {
return false;
}
if(InventoryUtils.areItemStacksEqual(tool, stack,
golem.checkOreDict(), golem.ignoreDamage(), golem.ignoreNBT())) {
return true;
}
}
}
if(empty && tool == null) {
return true;
}
}
return false;
}
}
@@ -0,0 +1,65 @@
package makeo.gadomancy.common.entities.fake;
import com.mojang.authlib.GameProfile;
import makeo.gadomancy.common.Gadomancy;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.WorldServer;
import net.minecraftforge.common.util.FakePlayer;
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
*
* Created by makeo @ 19.09.2015 17:14
*/
public class AdvancedFakePlayer extends FakePlayer {
protected static final UUID DEFAULT_UUID = UUID.fromString("d36a4fa5-c70e-4358-8418-9ed683687d0a");
public AdvancedFakePlayer(WorldServer world, UUID uuid, String name) {
super(world, new GameProfile(uuid, name));
this.playerNetServerHandler = new FakeNetServerHandler(MinecraftServer.getServer(), this);
}
public AdvancedFakePlayer(WorldServer world, UUID uuid) {
this(world, uuid, "[" + Gadomancy.MODID + ":" + uuid.hashCode() + "]");
}
public AdvancedFakePlayer(WorldServer world) {
this(world, DEFAULT_UUID);
}
public void setHeldItem(ItemStack item) {
inventory.currentItem = 0;
inventory.mainInventory[0] = item;
}
public static boolean isFakePlayer(EntityPlayer player) {
if(!player.worldObj.isRemote) {
if(player.getClass() != EntityPlayerMP.class) {
return true;
}
EntityPlayerMP mp = (EntityPlayerMP) player;
if(mp.playerNetServerHandler == null
|| !MinecraftServer.getServer().getConfigurationManager().playerEntityList.contains(player)
|| mp.getPlayerIP() == null || mp.getPlayerIP().trim().isEmpty()) {
return true;
}
try {
mp.playerNetServerHandler.netManager.getSocketAddress().toString();
} catch (Exception e) {
return true;
}
}
return false;
}
}
@@ -0,0 +1,219 @@
package makeo.gadomancy.common.entities.fake;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.util.concurrent.GenericFutureListener;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.network.*;
import net.minecraft.network.play.client.*;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.IChatComponent;
import javax.crypto.SecretKey;
import java.net.SocketAddress;
/**
* 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
*
* Created by makeo @ 19.09.2015 17:26
*/
public class FakeNetServerHandler extends NetHandlerPlayServer {
public FakeNetServerHandler(MinecraftServer server, EntityPlayerMP player) {
super(server, new NetworkManagerFake(), player);
}
@Override
public void onNetworkTick() {
}
@Override
public void setPlayerLocation(double p_147364_1_, double p_147364_3_, double p_147364_5_, float p_147364_7_, float p_147364_8_) {
}
@Override
public void onDisconnect(IChatComponent p_147231_1_) {
}
@Override
public void onConnectionStateTransition(EnumConnectionState p_147232_1_, EnumConnectionState p_147232_2_) {
}
@Override
public void kickPlayerFromServer(String p_147360_1_) {
}
@Override
public void sendPacket(Packet p_147359_1_) {
}
@Override
public void processInput(C0CPacketInput p_147358_1_) {
}
@Override
public void processPlayer(C03PacketPlayer p_147347_1_) {
}
@Override
public void processPlayerDigging(C07PacketPlayerDigging p_147345_1_) {
}
@Override
public void processPlayerBlockPlacement(C08PacketPlayerBlockPlacement p_147346_1_) {
}
@Override
public void processVanilla250Packet(C17PacketCustomPayload p_147349_1_) {
}
@Override
public void processClientSettings(C15PacketClientSettings p_147352_1_) {
}
@Override
public void processTabComplete(C14PacketTabComplete p_147341_1_) {
}
@Override
public void processPlayerAbilities(C13PacketPlayerAbilities p_147348_1_) {
}
@Override
public void processKeepAlive(C00PacketKeepAlive p_147353_1_) {
}
@Override
public void processUpdateSign(C12PacketUpdateSign p_147343_1_) {
}
@Override
public void processConfirmTransaction(C0FPacketConfirmTransaction p_147339_1_) {
}
@Override
public void processCreativeInventoryAction(C10PacketCreativeInventoryAction p_147344_1_) {
}
@Override
public void processEnchantItem(C11PacketEnchantItem p_147338_1_) {
}
@Override
public void processClickWindow(C0EPacketClickWindow p_147351_1_) {
}
@Override
public void processCloseWindow(C0DPacketCloseWindow p_147356_1_) {
}
@Override
public void processClientStatus(C16PacketClientStatus p_147342_1_) {
}
@Override
public void processUseEntity(C02PacketUseEntity p_147340_1_) {
}
@Override
public void processEntityAction(C0BPacketEntityAction p_147357_1_) {
}
@Override
public void processAnimation(C0APacketAnimation p_147350_1_) {
}
@Override
public void processChatMessage(C01PacketChatMessage p_147354_1_) {
}
@Override
public void processHeldItemChange(C09PacketHeldItemChange p_147355_1_) {
}
private static class NetworkManagerFake extends NetworkManager {
public NetworkManagerFake() {
super(false);
}
@Override
public void channelActive(ChannelHandlerContext p_channelActive_1_) throws Exception {
}
@Override
public void setConnectionState(EnumConnectionState p_150723_1_) {
}
@Override
public void channelInactive(ChannelHandlerContext p_channelInactive_1_) {
}
@Override
public void exceptionCaught(ChannelHandlerContext p_exceptionCaught_1_, Throwable p_exceptionCaught_2_) {
}
@Override
protected void channelRead0(ChannelHandlerContext p_channelRead0_1_, Packet p_channelRead0_2_) {
}
@Override
public void setNetHandler(INetHandler p_150719_1_) {
}
@Override
public void scheduleOutboundPacket(Packet p_150725_1_, GenericFutureListener... p_150725_2_) {
}
@Override
public void processReceivedPackets() {
}
@Override
public SocketAddress getSocketAddress() {
return null;
}
@Override
public void closeChannel(IChatComponent p_150718_1_) {
}
@Override
public boolean isLocalChannel() {
return true;
}
@Override
public void enableEncryption(SecretKey p_150727_1_) {
}
@Override
public boolean isChannelOpen() {
return false;
}
@Override
public INetHandler getNetHandler() {
return null;
}
@Override
public IChatComponent getExitMessage() {
return null;
}
@Override
public void disableAutoRead() {
}
@Override
protected void channelRead0(ChannelHandlerContext p_channelRead0_1_, Object p_channelRead0_2_) {
}
@Override
public Channel channel() {
return null;
}
}
}
@@ -0,0 +1,86 @@
package makeo.gadomancy.common.entities.fake;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.world.WorldServer;
import thaumcraft.common.entities.golems.EntityGolemBase;
import java.util.Collection;
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
*
* Created by makeo @ 19.09.2015 18:02
*/
public class GolemFakePlayer extends AdvancedFakePlayer {
private EntityGolemBase golem;
public GolemFakePlayer(WorldServer world, EntityGolemBase golem, UUID uuid) {
super(world, uuid);
this.golem = golem;
}
public GolemFakePlayer(WorldServer world, EntityGolemBase golem) {
this(world, golem, AdvancedFakePlayer.DEFAULT_UUID);
}
@Override
public Collection getActivePotionEffects() {
return golem.getActivePotionEffects();
}
@Override
public boolean isPotionActive(int p_82165_1_) {
return golem.isPotionActive(p_82165_1_);
}
@Override
public boolean isPotionActive(Potion p_70644_1_) {
return golem.isPotionActive(p_70644_1_);
}
@Override
public void clearActivePotions() {
golem.clearActivePotions();
}
@Override
public void addPotionEffect(PotionEffect p_70690_1_) {
golem.addPotionEffect(p_70690_1_);
}
@Override
public boolean isPotionApplicable(PotionEffect p_70687_1_) {
return golem.isPotionApplicable(p_70687_1_);
}
@Override
public void removePotionEffect(int p_82170_1_) {
golem.removePotionEffect(p_82170_1_);
}
@Override
public void removePotionEffectClient(int p_70618_1_) {
golem.removePotionEffectClient(p_70618_1_);
}
@Override
public PotionEffect getActivePotionEffect(Potion p_70660_1_) {
return golem.getActivePotionEffect(p_70660_1_);
}
@Override
public void curePotionEffects(ItemStack curativeItem) {
golem.curePotionEffects(curativeItem);
}
@Override
protected void updatePotionEffects() {
}
}
@@ -0,0 +1,101 @@
package makeo.gadomancy.common.entities.golems;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import makeo.gadomancy.api.golems.AdditionalGolemType;
import makeo.gadomancy.common.registration.RegisteredItems;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;
import thaumcraft.common.entities.golems.ItemGolemPlacer;
import java.util.List;
/**
* 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
*
* Created by makeo @ 02.06.2015 23:05
*/
public class ItemAdditionalGolemPlacer extends Item {
private final ItemGolemPlacer placer = new ItemGolemPlacer();
private final AdditionalGolemType type;
public ItemAdditionalGolemPlacer(AdditionalGolemType type) {
setCreativeTab(RegisteredItems.creativeTab);
setMaxStackSize(1);
this.type = type;
}
@Override
public void registerIcons(IIconRegister ir) {
placer.registerIcons(ir);
type.registerIcons(ir);
}
@Override
public boolean getHasSubtypes() {
return true;
}
@Override
public void getSubItems(Item item, CreativeTabs tab, List list) {
list.add(new ItemStack(type.getPlacerItem(), 1, type.getEnumEntry().ordinal()));
}
public IIcon getIcon(ItemStack stack, int pass) {
int typePasses = type.getRenderPasses();
if(pass < typePasses) {
return type.getIcon(stack, pass);
}
return placer.getIcon(stack, pass - typePasses + 1);
}
@SideOnly(Side.CLIENT)
public int getRenderPasses(int metadata) {
return type.getRenderPasses() + placer.getRenderPasses(metadata) - 1;
}
@Override
public IIcon getIconFromDamage(int damage) {
return type.getIcon(new ItemStack(this, 1, damage), 0);
}
@SideOnly(Side.CLIENT)
public boolean requiresMultipleRenderPasses() {
return true;
}
public String getUnlocalizedName(ItemStack stack) {
return getUnlocalizedName();
}
@Override
public String getUnlocalizedName() {
return type.getUnlocalizedName();
}
public boolean getShareTag() {
return placer.getShareTag();
}
@Override
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean par4) {
placer.addInformation(stack, player, list, par4);
}
public boolean doesSneakBypassUse(World world, int x, int y, int z, EntityPlayer player) {
return placer.doesSneakBypassUse(world, x, y, z, player);
}
@Override
public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) {
return placer.onItemUseFirst(stack, player, world, x, y, z, side, hitX, hitY, hitZ);
}
}
@@ -0,0 +1,56 @@
package makeo.gadomancy.common.entities.golems.cores;
import makeo.gadomancy.api.golems.cores.AdditionalGolemCore;
import makeo.gadomancy.common.entities.ai.AIBreakBlock;
import makeo.gadomancy.common.registration.RegisteredItems;
import net.minecraft.entity.ai.EntityAILookIdle;
import net.minecraft.entity.ai.EntityAIWatchClosest;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import thaumcraft.common.entities.ai.misc.AIOpenDoor;
import thaumcraft.common.entities.ai.misc.AIReturnHome;
import thaumcraft.common.entities.golems.EntityGolemBase;
/**
* 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
*
* Created by makeo @ 31.08.2015 13:38
*/
public class BreakGolemCore extends AdditionalGolemCore {
@Override
public void setupGolem(EntityGolemBase golem) {
golem.tasks.addTask(0, new AIBreakBlock(golem));
golem.tasks.addTask(5, new AIOpenDoor(golem, true));
golem.tasks.addTask(6, new AIReturnHome(golem));
golem.tasks.addTask(7, new EntityAIWatchClosest(golem, EntityPlayer.class, 6.0F));
golem.tasks.addTask(8, new EntityAILookIdle(golem));
}
@Override
public boolean hasGui() {
return true;
}
@Override
public ItemStack getToolItem(EntityGolemBase golem) {
return golem.getCarriedForDisplay();
}
@Override
public String getUnlocalizedGuiText() {
return "gadomancy.golemblurb.breakcore";
}
@Override
public String getUnlocalizedName() {
return "gadomancy.golem.breakcore";
}
@Override
public ItemStack getItem() {
return new ItemStack(RegisteredItems.itemGolemCoreBreak);
}
}
@@ -0,0 +1,75 @@
package makeo.gadomancy.common.entities.golems.cores;
import makeo.gadomancy.api.GadomancyApi;
import net.minecraft.entity.ai.EntityAIBase;
import net.minecraft.entity.ai.EntityAITasks;
import thaumcraft.common.entities.golems.EntityGolemBase;
import java.util.ArrayList;
import java.util.Collection;
/**
* 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
*
* Created by makeo @ 25.08.2015 22:24
*/
public class EntityAITasksWrapper extends EntityAITasks {
private final EntityGolemBase golem;
private final EntityAITasks original;
private boolean locked = true;
public EntityAITasksWrapper(EntityGolemBase golem) {
super(golem.targetTasks.theProfiler);
this.golem = golem;
this.original = golem.targetTasks;
this.taskEntries = new WrapperList(original.taskEntries);
this.original.taskEntries = this.taskEntries;
}
private class WrapperList extends ArrayList {
private WrapperList(Collection c) {
super(c);
}
@Override
public void clear() {
if(!isLocked()) {
super.clear();
}
}
}
public void unlock() {
locked = false;
}
public void lock() {
locked = true;
}
public boolean isLocked() {
return locked && GadomancyApi.getAdditionalGolemCore(golem) != null;
}
@Override
public void addTask(int index, EntityAIBase ai) {
if(!isLocked()) {
original.addTask(index, ai);
}
}
@Override
public void removeTask(EntityAIBase ai) {
original.removeTask(ai);
}
@Override
public void onUpdateTasks() {
original.onUpdateTasks();
}
}
@@ -0,0 +1,151 @@
package makeo.gadomancy.common.entities.golems.nbt;
import makeo.gadomancy.common.Gadomancy;
import makeo.gadomancy.api.GadomancyApi;
import makeo.gadomancy.api.golems.AdditionalGolemType;
import makeo.gadomancy.api.golems.cores.AdditionalGolemCore;
import makeo.gadomancy.common.data.ModConfig;
import makeo.gadomancy.common.entities.golems.cores.EntityAITasksWrapper;
import makeo.gadomancy.common.utils.NBTHelper;
import net.minecraft.entity.Entity;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import net.minecraftforge.common.IExtendedEntityProperties;
import thaumcraft.common.entities.golems.EntityGolemBase;
/**
* 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
*
* Created by makeo @ 28.07.2015 17:25
*/
public class ExtendedGolemProperties implements IExtendedEntityProperties {
private static final String TYPE_TAG = "golemTypeOverride";
private static final String FORGE_TAG = "ForgeData";
private EntityGolemBase golem;
private boolean updateHealth = false;
private float health;
private EntityAITasksWrapper wrapper = null;
public ExtendedGolemProperties(EntityGolemBase golem) {
this.golem = golem;
}
public boolean shouldUpdateHealth() {
return updateHealth;
}
public void resetUpdateHealth() {
updateHealth = false;
}
public float getHealth() {
return health;
}
@Override
public void saveNBTData(NBTTagCompound compound) {
AdditionalGolemType type = GadomancyApi.getAdditionalGolemType(golem.getGolemType());
if(type != null) {
NBTTagCompound entityData;
if(compound.hasKey(FORGE_TAG)) {
entityData = compound.getCompoundTag(FORGE_TAG);
} else {
entityData = new NBTTagCompound();
compound.setTag(FORGE_TAG, entityData);
}
writeAdvancedGolemType(entityData, type);
golem.ridingEntity = new OverrideRidingEntity(golem, compound, golem.ridingEntity);
}
}
private static void writeAdvancedGolemType(NBTTagCompound base, AdditionalGolemType type) {
NBTTagCompound compound;
if(base.hasKey(Gadomancy.MODID)) {
compound = base.getCompoundTag(Gadomancy.MODID);
} else {
compound = new NBTTagCompound();
base.setTag(Gadomancy.MODID, compound);
}
compound.setString(TYPE_TAG, type.getEnumEntry().name());
}
@Override
public void loadNBTData(NBTTagCompound compound) {
if(compound.hasKey("GolemType")) {
AdditionalGolemType type = readAdvancedGolemType(golem.getEntityData());
if(type != null) {
byte lastType = compound.getByte("GolemType");
compound.setTag("GolemType", new OverrideNBTTagByte(lastType, (byte)type.getEnumEntry().ordinal()));
health = compound.getFloat("HealF") * -1;
updateHealth = true;
}
}
updateGolemCore();
}
public void updateGolemCore() {
if(!golem.worldObj.isRemote) {
if(NBTHelper.hasPersistentData(golem)) {
NBTTagCompound persistent = NBTHelper.getPersistentData(golem);
if(persistent.hasKey("Core")) {
for(AdditionalGolemCore core : GadomancyApi.getAdditionalGolemCores()) {
if(core.getName().equals(persistent.getString("Core"))) {
golem.getDataWatcher().updateObject(ModConfig.getGolemDatawatcherId(), core.getName());
break;
}
}
}
}
}
}
public void setWrapperIfNeeded() {
if(wrapper == null) {
wrapper = new EntityAITasksWrapper(golem);
golem.tasks = wrapper;
updateGolem();
}
}
public void updateGolem() {
wrapper.unlock();
golem.setupGolem();
golem.setupGolemInventory();
AdditionalGolemCore core = GadomancyApi.getAdditionalGolemCore(golem);
if(core != null) {
wrapper.taskEntries.clear();
golem.targetTasks.taskEntries.clear();
core.setupGolem(golem);
core.setupGolemInventory(golem);
wrapper.lock();
}
}
private static AdditionalGolemType readAdvancedGolemType(NBTTagCompound base) {
if(base.hasKey(Gadomancy.MODID)) {
NBTTagCompound compound = base.getCompoundTag(Gadomancy.MODID);
if(compound.hasKey(TYPE_TAG)) {
return GadomancyApi.getAdditionalGolemType(compound.getString(TYPE_TAG));
}
}
return null;
}
@Override
public void init(Entity entity, World world) {
}
}
@@ -0,0 +1,31 @@
package makeo.gadomancy.common.entities.golems.nbt;
import net.minecraft.nbt.NBTTagByte;
/**
* 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
*
* Created by makeo @ 28.07.2015 17:03
*/
public class OverrideNBTTagByte extends NBTTagByte {
private boolean override = true;
private byte overrideData;
public OverrideNBTTagByte(byte data, byte overrideData) {
super(data);
this.overrideData = overrideData;
}
@Override
public byte func_150290_f() {
if(override) {
override = false;
return overrideData;
}
return super.func_150290_f();
}
}
@@ -0,0 +1,60 @@
package makeo.gadomancy.common.entities.golems.nbt;
import net.minecraft.entity.Entity;
import net.minecraft.nbt.NBTTagCompound;
import thaumcraft.common.entities.golems.EntityGolemBase;
import thaumcraft.common.entities.golems.EnumGolemType;
/**
* 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
*
* Created by makeo @ 28.07.2015 18:11
*/
public class OverrideRidingEntity extends Entity {
private static final EnumGolemType DEFAULT_TYPE = EnumGolemType.WOOD;
private EntityGolemBase golem;
private NBTTagCompound compound;
private Entity ridingEntity;
public OverrideRidingEntity(EntityGolemBase golem, NBTTagCompound compound, Entity ridingEntity) {
super(golem.worldObj);
Entity.nextEntityID--;
this.golem = golem;
this.compound = compound;
this.ridingEntity = ridingEntity;
}
@Override
public boolean writeMountToNBT(NBTTagCompound compound) {
this.compound.setFloat("HealF", golem.getHealth() * -1);
this.compound.setByte("GolemType", (byte) DEFAULT_TYPE.ordinal());
boolean result = false;
if(ridingEntity != null) {
result = ridingEntity.writeMountToNBT(compound);
}
golem.ridingEntity = ridingEntity;
return result;
}
@Override
protected void entityInit() {
}
@Override
protected void readEntityFromNBT(NBTTagCompound p_70037_1_) {
}
@Override
protected void writeEntityToNBT(NBTTagCompound p_70014_1_) {
}
}
@@ -0,0 +1,47 @@
package makeo.gadomancy.common.entities.golems.types;
import makeo.gadomancy.api.golems.AdditionalGolemType;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraft.util.ResourceLocation;
/**
* 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
*
* Created by makeo @ 29.07.2015 00:15
*/
public class RemovedGolemType extends AdditionalGolemType {
public RemovedGolemType() {
super(0, 0, 0, false, 0, 0, 1000, 0);
}
@Override
public String getUnlocalizedName() {
return "";
}
private IIcon icon;
@Override
public void registerIcons(IIconRegister ir) {
icon = ir.registerIcon("");
}
@Override
public IIcon getIcon(ItemStack stack, int pass) {
return icon;
}
@Override
public ResourceLocation getEntityTexture() {
return new ResourceLocation("");
}
@Override
public ResourceLocation getInvSlotTexture() {
return new ResourceLocation("");
}
}
@@ -0,0 +1,49 @@
package makeo.gadomancy.common.entities.golems.types;
import makeo.gadomancy.common.Gadomancy;
import makeo.gadomancy.api.golems.AdditionalGolemType;
import makeo.gadomancy.common.utils.SimpleResourceLocation;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraft.util.ResourceLocation;
/**
* 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
*
* Created by makeo @ 28.07.2015 02:39
*/
public class SilverwoodGolemType extends AdditionalGolemType {
public SilverwoodGolemType() {
super(20, 3, 0.36F, false, 3, 8, 75, 1);
}
@Override
public String getUnlocalizedName() {
return "item.ItemGolemPlacer.silverwood";
}
private IIcon icon;
@Override
public void registerIcons(IIconRegister ir) {
icon = ir.registerIcon(Gadomancy.MODID + ":golem_silverwood");
}
@Override
public IIcon getIcon(ItemStack stack, int pass) {
return icon;
}
@Override
public ResourceLocation getEntityTexture() {
return new SimpleResourceLocation("models/golem_silverwood.png");
}
@Override
public ResourceLocation getInvSlotTexture() {
return new SimpleResourceLocation("gui/default_slot.png");
}
}
@@ -0,0 +1,106 @@
package makeo.gadomancy.common.entities.golems.upgrades;
import makeo.gadomancy.common.Gadomancy;
import makeo.gadomancy.common.utils.NBTHelper;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagByte;
import net.minecraft.nbt.NBTTagCompound;
import thaumcraft.common.entities.golems.EntityGolemBase;
/**
* 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
*
* Created by makeo @ 16.06.2015 14:38
*/
public abstract class GolemUpgrade<T extends NBTBase> {
private static final String UPGRADE_COMPOUND = "upgrades";
public abstract String getName();
public String getTagName() {
return getName();
}
public String getText() {
return Gadomancy.MODID.toLowerCase() + ".upgrades." + getName().toLowerCase();
}
public ItemStack getUpgradeItem() {
return null;
}
protected T createUpgradeData() {
return null;
}
protected T getUpgradeData(ItemStack stack) {
return getUpgradeData(NBTHelper.getPersistentData(stack));
}
protected T getUpgradeData(EntityGolemBase golem) {
return getUpgradeData(NBTHelper.getPersistentData(golem));
}
protected T getUpgradeData(NBTTagCompound compound) {
if(compound.hasKey(UPGRADE_COMPOUND)) {
NBTTagCompound upgrades = compound.getCompoundTag(UPGRADE_COMPOUND);
try {
return (T) upgrades.getTag(getTagName());
} catch (ClassCastException ignored) {}
}
return null;
}
public boolean hasUpgrade(ItemStack stack) {
return hasUpgrade(NBTHelper.getPersistentData(stack));
}
public boolean hasUpgrade(EntityGolemBase golem) {
return hasUpgrade(NBTHelper.getPersistentData(golem));
}
protected boolean hasUpgrade(NBTTagCompound compound) {
return getUpgradeData(compound) != null;
}
public void addUpgrade(ItemStack stack) {
addUpgrade(NBTHelper.getPersistentData(stack));
}
public void addUpgrade(EntityGolemBase golem) {
addUpgrade(NBTHelper.getPersistentData(golem));
}
protected void addUpgrade(NBTTagCompound compound) {
NBTTagCompound upgrades = compound.getCompoundTag(UPGRADE_COMPOUND);
if(!compound.hasKey(UPGRADE_COMPOUND)) {
compound.setTag(UPGRADE_COMPOUND, upgrades);
}
NBTBase data = createUpgradeData();
upgrades.setTag(getTagName(), data == null ? new NBTTagByte((byte)1) : data);
}
public void removeUpgrade(ItemStack stack) {
removeUpgrade(NBTHelper.getPersistentData(stack));
}
public void removeUpgrade(EntityGolemBase golem) {
removeUpgrade(NBTHelper.getPersistentData(golem));
}
protected void removeUpgrade(NBTTagCompound compound) {
if(compound.hasKey(UPGRADE_COMPOUND)) {
compound.removeTag(getTagName());
}
}
@Override
public boolean equals(Object obj) {
return obj instanceof GolemUpgrade && ((GolemUpgrade) obj).getName().equals(getName());
}
}
@@ -0,0 +1,112 @@
package makeo.gadomancy.common.entities.golems.upgrades;
import cpw.mods.fml.common.network.NetworkRegistry;
import makeo.gadomancy.common.registration.RegisteredGolemStuff;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.DamageSource;
import thaumcraft.common.entities.golems.EntityGolemBase;
import thaumcraft.common.entities.golems.EnumGolemType;
import thaumcraft.common.lib.network.PacketHandler;
import thaumcraft.common.lib.network.fx.PacketFXShield;
/**
* 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
*
* Created by makeo @ 16.06.2015 12:50
*/
public class GolemUpgradeRunicShield extends GolemUpgrade {
private static final String LAST_DISCHARGE_TAG = "lastRunicDischarge";
@Override
public String getName() {
return "runicShield";
}
public float absorb(EntityGolemBase golem, float amount, DamageSource source) {
float charge = getCharge(golem);
if(Math.floor(charge) > 0) {
sendShieldEffect(golem, source);
float rest = (float)(Math.floor(charge) - amount);
float chargeRest = charge - (float)Math.floor(charge);
if(rest <= 0) {
setCharge(golem, chargeRest);
return rest * -1;
} else {
setCharge(golem, (float)Math.floor(rest) + chargeRest);
return 0;
}
}
return amount;
}
private void sendShieldEffect(EntityGolemBase golem, DamageSource source) {
int target = -1;
if (source.getEntity() != null) {
target = source.getEntity().getEntityId();
} else if (source == DamageSource.fall) {
target = -2;
} else if (source == DamageSource.fallingBlock) {
target = -3;
}
PacketHandler.INSTANCE.sendToAllAround(new PacketFXShield(golem.getEntityId(), target),
new NetworkRegistry.TargetPoint(golem.worldObj.provider.dimensionId, golem.posX, golem.posY, golem.posZ, 64.0D));
}
public float getCharge(EntityGolemBase golem) {
int elapsed = golem.ticksExisted - getLastDischarge(golem);
float charge = elapsed * getRechargeSpeed(golem);
float limit = getChargeLimit(golem);
return charge > limit ? limit : charge;
}
private void setCharge(EntityGolemBase golem, float charge) {
int ticksNeeded = Math.round(charge / getRechargeSpeed(golem));
setLastDischarge(golem, golem.ticksExisted - ticksNeeded);
}
private void setLastDischarge(EntityGolemBase golem, Integer ticks) {
golem.getEntityData().setInteger(LAST_DISCHARGE_TAG, ticks);
}
private int getLastDischarge(EntityGolemBase golem) {
NBTTagCompound compound = golem.getEntityData();
if(!compound.hasKey(LAST_DISCHARGE_TAG)) {
compound.setInteger(LAST_DISCHARGE_TAG, golem.ticksExisted);
return golem.ticksExisted;
}
return compound.getInteger(LAST_DISCHARGE_TAG);
}
private float getRechargeSpeed(EntityGolemBase golem) {
return 0.02f;
}
public int getChargeLimit(EntityGolemBase golem) {
return getChargeLimit(golem.getGolemType(), golem.getMaxHealth());
}
public int getChargeLimit(ItemStack stack) {
EnumGolemType type = EnumGolemType.getType(stack.getItemDamage());
float maxHealth = type.health;
if(stack.hasTagCompound() && stack.getTagCompound().hasKey("deco")
&& stack.getTagCompound().getString("deco").contains("H")) {
maxHealth += 5;
}
return getChargeLimit(type, maxHealth);
}
private int getChargeLimit(EnumGolemType type, float maxHealth) {
if(type == RegisteredGolemStuff.typeSilverwood.getEnumEntry()) {
return (int)maxHealth;
}
return (int)(maxHealth / 2.6);
}
}
@@ -0,0 +1,59 @@
package makeo.gadomancy.common.entities.player;
import makeo.gadomancy.common.utils.NBTHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import net.minecraftforge.common.IExtendedEntityProperties;
/**
* 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
*
* Created by makeo @ 05.07.2015 12:39
*/
public class ExtendedPlayerProperties implements IExtendedEntityProperties {
private static final int TRANSFORM_INDEX = 26;
private static final ExtendedPlayerProperties DEFAULTS = new ExtendedPlayerProperties(null);
private final EntityPlayer player;
private boolean isTransformed = false;
public ExtendedPlayerProperties(EntityPlayer player) {
this.player = player;
}
@Override
public void saveNBTData(NBTTagCompound compound) {
NBTTagCompound modData = NBTHelper.getPersistentData(compound);
modData.setBoolean("isTransformed", isTransformed);
}
@Override
public void loadNBTData(NBTTagCompound compound) {
NBTTagCompound modData = NBTHelper.getPersistentData(compound);
isTransformed = NBTHelper.getBoolean(modData, "isTransformed", DEFAULTS.isTransformed);
player.getDataWatcher().updateObject(TRANSFORM_INDEX, isTransformed);
}
@Override
public void init(Entity entity, World world) {
player.getDataWatcher().addObject(TRANSFORM_INDEX, isTransformed);
}
public static boolean isTransformed(EntityPlayer player) {
return false;
}
public void setTransformed(boolean isTransformed) {
this.isTransformed = isTransformed;
}
}
@@ -0,0 +1,269 @@
package makeo.gadomancy.common.events;
import cpw.mods.fml.common.eventhandler.EventPriority;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import makeo.gadomancy.common.Gadomancy;
import makeo.gadomancy.api.GadomancyApi;
import makeo.gadomancy.api.golems.AdditionalGolemType;
import makeo.gadomancy.api.golems.cores.AdditionalGolemCore;
import makeo.gadomancy.api.golems.events.GolemDropPlacerEvent;
import makeo.gadomancy.api.golems.events.PlacerCreateGolemEvent;
import makeo.gadomancy.common.data.ModConfig;
import makeo.gadomancy.common.entities.golems.ItemAdditionalGolemPlacer;
import makeo.gadomancy.common.entities.golems.nbt.ExtendedGolemProperties;
import makeo.gadomancy.common.registration.RegisteredGolemStuff;
import makeo.gadomancy.common.utils.NBTHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.StatCollector;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.EntityEvent;
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
import net.minecraftforge.event.entity.PlaySoundAtEntityEvent;
import net.minecraftforge.event.entity.living.LivingHurtEvent;
import net.minecraftforge.event.entity.player.AttackEntityEvent;
import net.minecraftforge.event.entity.player.EntityInteractEvent;
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import thaumcraft.common.config.ConfigItems;
import thaumcraft.common.entities.golems.EntityGolemBase;
import thaumcraft.common.entities.golems.EnumGolemType;
import thaumcraft.common.entities.golems.ItemGolemPlacer;
import thaumcraft.common.items.wands.ItemWandCasting;
import java.util.HashMap;
import java.util.Map;
/**
* 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
*
* Created by makeo @ 13.03.2015 13:56
*/
public class EventHandlerGolem {
@SubscribeEvent(priority = EventPriority.LOWEST)
public void on(EntityEvent.EntityConstructing e) {
if(e.entity instanceof EntityGolemBase) {
EntityGolemBase golem = (EntityGolemBase) e.entity;
golem.registerExtendedProperties(Gadomancy.MODID, new ExtendedGolemProperties(golem));
golem.getDataWatcher().addObject(ModConfig.getGolemDatawatcherId(), "");
}
}
@SubscribeEvent(priority = EventPriority.HIGHEST)
public void on(EntityEvent.EnteringChunk event) {
if(event.entity instanceof EntityGolemBase) {
EntityGolemBase golem = (EntityGolemBase) event.entity;
if(GadomancyApi.isAdditionalGolemType(golem.getGolemType())) {
ExtendedGolemProperties props = (ExtendedGolemProperties)event.entity.getExtendedProperties(Gadomancy.MODID);
if(props.shouldUpdateHealth()) {
props.resetUpdateHealth();
golem.setHealth(props.getHealth());
}
}
}
}
@SubscribeEvent(priority = EventPriority.LOWEST, receiveCanceled = true)
public void on(EntityJoinWorldEvent event) {
if(event.world.isRemote && event.entity instanceof EntityGolemBase) {
System.out.println();
}
if(!event.entity.worldObj.isRemote && event.entity instanceof EntityGolemBase) {
EntityGolemBase golem = (EntityGolemBase) event.entity;
ExtendedGolemProperties props = (ExtendedGolemProperties) golem.getExtendedProperties(Gadomancy.MODID);
if(props != null) {
props.setWrapperIfNeeded();
}
}
if (event.entity instanceof EntityItem) {
EntityItem item = (EntityItem) event.entity;
ItemStack stack = item.getEntityItem();
if (stack.getItem() == ConfigItems.itemGolemPlacer) {
AdditionalGolemType type = GadomancyApi.getAdditionalGolemType(EnumGolemType.getType(stack.getItemDamage()));
if (type != null) {
ItemStack fakePlacer = new ItemStack(type.getPlacerItem());
fakePlacer.setTagCompound(stack.getTagCompound());
fakePlacer.setItemDamage(stack.getItemDamage());
item.setEntityItemStack(fakePlacer);
}
}
}
}
@SubscribeEvent(priority = EventPriority.LOWEST)
public void on(PlayerInteractEvent e) {
if(!e.world.isRemote && e.action == PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK) {
ItemStack itemInHand = e.entityPlayer.getHeldItem();
if(itemInHand != null && (itemInHand.getItem() instanceof ItemGolemPlacer
|| itemInHand.getItem() instanceof ItemAdditionalGolemPlacer)) {
int entityId = Entity.nextEntityID;
if(itemInHand.getItem().onItemUseFirst(itemInHand, e.entityPlayer, e.world, e.x, e.y, e.z, e.face, 0, 0, 0)) {
e.setCanceled(true);
Entity entity = e.world.getEntityByID(entityId);
if(entity != null && entity instanceof EntityGolemBase) {
EntityGolemBase golem = (EntityGolemBase) entity;
//move persistent data to entity
golem.getEntityData().setTag(Gadomancy.MODID, NBTHelper.getPersistentData(itemInHand).copy());
MinecraftForge.EVENT_BUS.post(new PlacerCreateGolemEvent(e.entityPlayer, golem, itemInHand));
ExtendedGolemProperties props = (ExtendedGolemProperties) golem.getExtendedProperties(Gadomancy.MODID);
if(props != null) {
props.updateGolemCore();
props.updateGolem();
}
//update runic shielding
if(RegisteredGolemStuff.upgradeRunicShield.hasUpgrade(golem)) {
RegisteredGolemStuff.upgradeRunicShield.getCharge(golem);
}
}
}
}
}
}
private final Map<EntityGolemBase, EntityPlayer> markedGolems = new HashMap<EntityGolemBase, EntityPlayer>();
@SubscribeEvent(priority = EventPriority.HIGHEST, receiveCanceled = true)
public void on(PlaySoundAtEntityEvent event) {
if(!event.entity.worldObj.isRemote && event.entity instanceof EntityGolemBase
&& event.name.equals("thaumcraft:zap") && event.volume == 0.5F && event.pitch == 1.0F) {
EntityGolemBase golem = (EntityGolemBase) event.entity;
if(markedGolems.containsKey(golem)) {
EntityPlayer player = markedGolems.get(golem);
markedGolems.remove(golem);
AdditionalGolemCore core = GadomancyApi.getAdditionalGolemCore(golem);
boolean movedPlacer = false;
boolean movedCore = core == null || !player.isSneaking();
for(EntityItem entityItem : golem.capturedDrops) {
ItemStack item = entityItem.getEntityItem();
if(!movedCore && item.getItem() == ConfigItems.itemGolemCore) {
entityItem.setEntityItemStack(core.getItem());
}
if(!movedPlacer && item.getItem() instanceof ItemGolemPlacer
|| item.getItem() instanceof ItemAdditionalGolemPlacer) {
//move persistent data to item
NBTTagCompound persistent = (NBTTagCompound) NBTHelper.getPersistentData(golem).copy();
if(player.isSneaking()) {
persistent.removeTag("Core");
}
NBTHelper.getData(item).setTag(Gadomancy.MODID, persistent);
event.entity.setDead();
entityItem.setEntityItemStack(item);
MinecraftForge.EVENT_BUS.post(new GolemDropPlacerEvent(player, entityItem, golem));
movedPlacer = true;
}
event.entity.worldObj.spawnEntityInWorld(entityItem);
}
golem.capturedDrops.clear();
golem.captureDrops = false;
}
}
}
@SubscribeEvent(priority = EventPriority.LOWEST)
public void on(AttackEntityEvent event) {
ItemStack heldItem = event.entityPlayer.getHeldItem();
if(heldItem != null && heldItem.getItem() == ConfigItems.itemGolemBell && event.target instanceof EntityGolemBase
&& !event.target.worldObj.isRemote && !event.target.isDead) {
event.target.captureDrops = true;
markedGolems.put((EntityGolemBase) event.target, event.entityPlayer);
}
}
@SubscribeEvent(priority = EventPriority.NORMAL)
public void on(LivingHurtEvent event) {
if (!event.entity.worldObj.isRemote && event.entity instanceof EntityGolemBase) {
EntityGolemBase golem = (EntityGolemBase) event.entity;
if(event.ammount > 0 && RegisteredGolemStuff.upgradeRunicShield.hasUpgrade(golem)) {
event.ammount = RegisteredGolemStuff.upgradeRunicShield.absorb(golem, event.ammount, event.source);
}
}
}
@SubscribeEvent(priority = EventPriority.LOWEST)
public void on(EntityInteractEvent event) {
ItemStack heldItem = event.entityPlayer.getHeldItem();
if(event.target instanceof EntityGolemBase) {
EntityGolemBase golem = (EntityGolemBase) event.target;
if(golem.getCore() < 0) {
if(heldItem != null) {
AdditionalGolemCore core = null;
for(AdditionalGolemCore entry : GadomancyApi.getAdditionalGolemCores()) {
if(entry.getItem().isItemEqual(heldItem)) {
core = entry;
break;
}
}
if(core != null) {
GadomancyApi.setAdditionalGolemCore(golem, core);
event.setCanceled(true);
}
}
} else if(!event.target.worldObj.isRemote) {
if(heldItem == null
|| (heldItem.getItem() != ConfigItems.itemGolemBell
&& heldItem.getItem() != ConfigItems.itemGolemUpgrade
&& heldItem.getItem() != ConfigItems.itemGolemDecoration
&& !(heldItem.getItem() instanceof ItemWandCasting))) {
AdditionalGolemCore core = GadomancyApi.getAdditionalGolemCore(golem);
if(core != null) {
if(core.hasGui() && !core.openGui(event.entityPlayer, golem)) {
event.entityPlayer.openGui(Gadomancy.instance, 0, golem.worldObj, golem.getEntityId(), 0, 0);
}
event.setCanceled(true);
}
}
}
}
}
@SubscribeEvent(priority = EventPriority.LOWEST)
public void on(ItemTooltipEvent event) {
if(event.itemStack != null) {
if(event.itemStack.getItem() instanceof ItemGolemPlacer
|| event.itemStack.getItem() instanceof ItemAdditionalGolemPlacer) {
if(RegisteredGolemStuff.upgradeRunicShield.hasUpgrade(event.itemStack)) {
event.toolTip.add("§6" + StatCollector.translateToLocal("item.runic.charge") + " +" + RegisteredGolemStuff.upgradeRunicShield.getChargeLimit(event.itemStack));
}
AdditionalGolemCore core = GadomancyApi.getAdditionalGolemCore(event.itemStack);
if(core != null) {
String searchStr = StatCollector.translateToLocal("item.ItemGolemCore.name");
for(int i = 0; i < event.toolTip.size(); i++) {
String line = event.toolTip.get(i);
if(line.contains(searchStr)) {
int index = line.indexOf('\u00a7', searchStr.length()) + 2;
event.toolTip.remove(i);
event.toolTip.add(i, line.substring(0, index) + StatCollector.translateToLocal(core.getUnlocalizedName()));
break;
}
}
}
}
}
}
}
@@ -0,0 +1,26 @@
package makeo.gadomancy.common.events;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.PlayerEvent;
import makeo.gadomancy.common.network.PacketHandler;
import makeo.gadomancy.common.network.packets.PacketUpdateGolemTypeOrder;
import makeo.gadomancy.common.utils.GolemEnumHelper;
import net.minecraft.entity.player.EntityPlayerMP;
/**
* 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
*
* Created by makeo @ 30.07.2015 18:26
*/
public class EventHandlerNetwork {
@SubscribeEvent
public void on(PlayerEvent.PlayerLoggedInEvent e) {
EntityPlayerMP p = (EntityPlayerMP) e.player;
if(!p.playerNetServerHandler.netManager.isLocalChannel()) {
PacketHandler.INSTANCE.sendTo(new PacketUpdateGolemTypeOrder(GolemEnumHelper.getCurrentMapping()), p);
}
}
}
@@ -0,0 +1,110 @@
package makeo.gadomancy.common.events;
import cpw.mods.fml.common.eventhandler.EventPriority;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import makeo.gadomancy.common.Gadomancy;
import makeo.gadomancy.common.blocks.tiles.TileStickyJar;
import makeo.gadomancy.common.registration.RegisteredBlocks;
import makeo.gadomancy.common.registration.RegisteredItems;
import makeo.gadomancy.common.utils.GolemEnumHelper;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.server.MinecraftServer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.StatCollector;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.event.entity.EntityEvent;
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.event.world.WorldEvent;
import thaumcraft.common.tiles.TileJarFillable;
import java.util.HashMap;
import java.util.Map;
/**
* 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
*
* Created by makeo @ 05.07.2015 13:20
*/
public class EventHandlerWorld {
@SubscribeEvent(priority = EventPriority.LOWEST)
public void on(EntityEvent.EntityConstructing e) {
if(e.entity instanceof EntityPlayer) {
//e.entity.registerExtendedProperties(Gadomancy.MODID, new ExtendedPlayerProperties((EntityPlayer) e.entity));
}
}
@SubscribeEvent(priority = EventPriority.NORMAL)
public void on(WorldEvent.Load e) {
if(!e.world.isRemote && e.world.equals(MinecraftServer.getServer().getEntityWorld())) {
Gadomancy.loadModData();
GolemEnumHelper.validateSavedMapping();
GolemEnumHelper.reorderEnum();
}
}
@SubscribeEvent(priority = EventPriority.NORMAL)
public void on(WorldEvent.Unload e) {
if(!e.world.isRemote && e.world.equals(MinecraftServer.getServer().getEntityWorld())) {
Gadomancy.unloadModData();
}
}
private Map<EntityPlayer, Integer> interacts = null;
@SubscribeEvent(priority = EventPriority.LOWEST, receiveCanceled = true)
public void on(BlockEvent.PlaceEvent e) {
if(e.isCanceled()) {
if(interacts != null)
interacts.remove(e.player);
} else {
if(!e.world.isRemote && isStickyJar(e.itemInHand)) {
TileEntity parent = e.world.getTileEntity(e.x, e.y, e.z);
if(parent instanceof TileJarFillable) {
int metadata = e.world.getBlockMetadata(e.x, e.y, e.z);
e.world.setBlock(e.x, e.y, e.z, RegisteredBlocks.blockStickyJar, metadata, 2);
TileEntity tile = e.world.getTileEntity(e.x, e.y, e.z);
if(tile instanceof TileStickyJar) {
Integer sideHit = interacts.get(e.player);
((TileStickyJar) tile).init((TileJarFillable) parent, e.placedBlock, metadata,
ForgeDirection.getOrientation(sideHit == null ? 1 : sideHit).getOpposite());
RegisteredBlocks.blockStickyJar.onBlockPlacedBy(e.world, e.x, e.y, e.z, e.player, e.itemInHand);
}
}
}
}
}
@SubscribeEvent(priority = EventPriority.LOWEST)
public void on(PlayerInteractEvent e) {
if(!e.world.isRemote && e.action == PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK
&& isStickyJar(e.entityPlayer.getHeldItem())) {
if(interacts == null) {
interacts = new HashMap<EntityPlayer, Integer>();
}
interacts.put(e.entityPlayer, e.face);
}
}
private boolean isStickyJar(ItemStack stack) {
return stack != null && RegisteredItems.isStickyableJar(stack)
&& stack.hasTagCompound() && stack.stackTagCompound.getBoolean("isStickyJar");
}
@SubscribeEvent(priority = EventPriority.NORMAL)
public void on(ItemTooltipEvent e) {
if(e.toolTip.size() > 0 && e.itemStack.hasTagCompound()) {
if(e.itemStack.stackTagCompound.getBoolean("isStickyJar")) {
e.toolTip.add(1, "§a" + StatCollector.translateToLocal("gadomancy.lore.stickyjar"));
}
}
}
}
@@ -0,0 +1,30 @@
package makeo.gadomancy.common.integration;
import makeo.gadomancy.common.registration.RegisteredBlocks;
import makeo.gadomancy.common.registration.RegisteredItems;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
/**
* 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
*
* Created by makeo @ 04.10.2015 02:30
*/
public class IntegrationAutomagy extends IntegrationMod {
@Override
public String getModId() {
return "Automagy";
}
@Override
protected void doInit() {
Block infinityJar = Block.getBlockFromName("Automagy:blockCreativeJar");
if(infinityJar != null) {
RegisteredBlocks.registerStickyJar(infinityJar, 3, false, true);
RegisteredItems.registerStickyJar(Item.getItemFromBlock(infinityJar), 3);
}
}
}
@@ -0,0 +1,30 @@
package makeo.gadomancy.common.integration;
import cpw.mods.fml.common.Loader;
/**
* 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
*
* Created by makeo @ 09.07.2015 15:29
*/
public abstract class IntegrationMod {
public abstract String getModId();
private boolean isPresent = false;
public final boolean isPresent() {
return isPresent;
}
public final void init() {
if(Loader.isModLoaded(getModId())) {
isPresent = true;
doInit();
}
}
protected abstract void doInit();
}
@@ -0,0 +1,47 @@
package makeo.gadomancy.common.integration;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import makeo.gadomancy.common.utils.Injector;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import java.lang.reflect.Method;
/**
* 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
*
* Created by makeo @ 09.07.2015 14:45
*/
public class IntegrationMorph extends IntegrationMod {
private static final Injector INJECTOR = new Injector();
private Method methodHasMorph = null;
@Override
public String getModId() {
return "Morph";
}
@Override
protected void doInit() {
//methodHasMorph = Injector.getMethod("hasMorph", "morph.common.core.ApiHandler", String.class, Boolean.class);
//if(methodHasMorph == null) {
// FMLLog.severe("Morph mod is loaded but failed to find method \"hasMorph\"!");
//}
}
@SideOnly(Side.CLIENT)
public boolean isMorphed() {
if(methodHasMorph != null) {
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
Boolean result = INJECTOR.invokeMethod(methodHasMorph, player.getCommandSenderName(), true);
return result != null ? result : false;
}
return false;
}
}
@@ -0,0 +1,31 @@
package makeo.gadomancy.common.integration;
import makeo.gadomancy.common.registration.RegisteredBlocks;
import makeo.gadomancy.common.registration.RegisteredItems;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
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
*
* Created by makeo @ 04.10.2015 01:52
*/
public class IntegrationThaumicExploration extends IntegrationMod {
@Override
public String getModId() {
return "ThaumicExploration";
}
@Override
protected void doInit() {
Block trashJar = Block.getBlockFromName("ThaumicExploration:trashJar");
if(trashJar != null) {
RegisteredBlocks.registerStickyJar(trashJar, 0, false, true);
RegisteredItems.registerStickyJar(Item.getItemFromBlock(trashJar), 0, new ItemStack(trashJar));
}
}
}
@@ -0,0 +1,106 @@
package makeo.gadomancy.common.integration.thaumichorizions;
import com.google.common.collect.BiMap;
import com.kentington.thaumichorizons.client.renderer.entity.RenderGolemTH;
import com.kentington.thaumichorizons.common.entities.EntityGolemTH;
import com.kentington.thaumichorizons.common.items.ItemGolemBellTH;
import com.kentington.thaumichorizons.common.tiles.TileVat;
import com.kentington.thaumichorizons.common.tiles.TileVatMatrix;
import cpw.mods.fml.client.registry.RenderingRegistry;
import cpw.mods.fml.common.registry.ExistingSubstitutionException;
import cpw.mods.fml.common.registry.FMLControlledNamespacedRegistry;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import makeo.gadomancy.common.Gadomancy;
import makeo.gadomancy.api.ClickBehavior;
import makeo.gadomancy.common.integration.IntegrationMod;
import makeo.gadomancy.common.registration.RegisteredBlocks;
import makeo.gadomancy.common.utils.Injector;
import makeo.gadomancy.client.ClientProxy;
import makeo.gadomancy.common.CommonProxy;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.entity.RendererLivingEntity;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraftforge.event.entity.PlaySoundAtEntityEvent;
import thaumcraft.common.config.ConfigItems;
/**
* 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
*
* Created by makeo @ 07.10.2015 13:10
*/
public class IntegrationThaumicHorizions extends IntegrationMod {
private static Block modMatrix;
@Override
public String getModId() {
return "ThaumicHorizons";
}
@Override
protected void doInit() {
if(Gadomancy.proxy.getSide() == Side.CLIENT) {
RendererLivingEntity render = ClientProxy.unregisterRenderer(EntityGolemTH.class, RenderGolemTH.class);
if(render != null) {
RenderingRegistry.registerEntityRenderingHandler(EntityGolemTH.class, new RenderAdditionalGolemTH(render.mainModel));
}
modMatrix = Block.getBlockFromName("ThaumicHorizons:modMatrix");
RegisteredBlocks.registerClawClickBehavior(new ClickBehavior(true) {
private TileVat vat;
@Override
public boolean isValidForBlock() {
if (block == modMatrix && metadata == 0) {
this.vat = ((TileVatMatrix) world.getTileEntity(x, y, z)).getVat();
return vat != null;
}
return false;
}
@Override
public int getComparatorOutput() {
return (vat.mode != 0 && vat.mode != 4) ? 15 : 0;
}
@Override
public void addInstability(int instability) {
vat.instability += Math.ceil(instability * 0.5);
}
});
}
undoSubstitution("Thaumcraft:GolemBell");
ItemGolemBellOverride override = new ItemGolemBellOverride();
try {
GameRegistry.addSubstitutionAlias("Thaumcraft:GolemBell", GameRegistry.Type.ITEM, override);
} catch (ExistingSubstitutionException ignored) { }
ConfigItems.itemGolemBell = override;
}
private void undoSubstitution(String name) {
Injector registry = new Injector(GameRegistry.Type.ITEM.getRegistry(), FMLControlledNamespacedRegistry.class);
BiMap map = registry.invokeMethod("getPersistentSubstitutions");
map.remove(name);
}
public static class ItemGolemBellOverride extends ItemGolemBellTH {
@Override
public boolean onLeftClickEntity(ItemStack stack, EntityPlayer player, Entity entity) {
boolean result = super.onLeftClickEntity(stack, player, entity);
if(result && !entity.worldObj.isRemote && entity instanceof EntityGolemTH
&& entity.isDead && player.isSneaking()) {
CommonProxy.EVENT_HANDLER_GOLEM.on(new PlaySoundAtEntityEvent(entity, "thaumcraft:zap", 0.5f, 1.0f));
}
return result;
}
}
}
@@ -0,0 +1,101 @@
package makeo.gadomancy.common.integration.thaumichorizions;
import com.kentington.thaumichorizons.client.renderer.entity.RenderGolemTH;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import makeo.gadomancy.api.GadomancyApi;
import makeo.gadomancy.api.golems.AdditionalGolemType;
import makeo.gadomancy.api.golems.cores.AdditionalGolemCore;
import makeo.gadomancy.client.renderers.entity.RenderGolemHelper;
import net.minecraft.client.model.ModelBase;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import thaumcraft.common.entities.golems.EntityGolemBase;
/**
* 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
*
* Created by makeo @ 07.10.2015 13:09
*/
@SideOnly(Side.CLIENT)
public class RenderAdditionalGolemTH extends RenderGolemTH {
private ItemStack toolItem = null;
public RenderAdditionalGolemTH(ModelBase mainModel) {
super(mainModel);
}
protected int shouldRenderPass(EntityLivingBase entity, int pass, float par3) {
if (pass != 0) {
return super.shouldRenderPass(entity, pass, par3);
}
EntityGolemBase golem = (EntityGolemBase) entity;
AdditionalGolemCore core = GadomancyApi.getAdditionalGolemCore(golem);
if (core != null) {
golem.getDataWatcher().getWatchedObject(21).setObject((byte) -1);
}
int ret = super.shouldRenderPass(entity, pass, par3);
//fix for render bug in tc
if (RenderGolemHelper.requiresRenderFix((EntityGolemBase) entity)) {
RenderGolemHelper.renderCarriedItemsFix(golem);
if(toolItem != null) {
RenderGolemHelper.renderToolItem(golem, toolItem, mainModel, renderManager);
}
}
if (core != null) {
golem.getDataWatcher().getWatchedObject(21).setObject((byte) 1);
RenderGolemHelper.renderCore(golem, core);
}
return ret;
}
@Override
protected void renderCarriedItems(EntityGolemBase golem, float par2) {
if (!RenderGolemHelper.requiresRenderFix(golem)) {
if(toolItem != null) {
RenderGolemHelper.renderToolItem(golem, toolItem, mainModel, renderManager);
}
super.renderCarriedItems(golem, par2);
}
}
@Override
public void render(EntityGolemBase golem, double par2, double par4, double par6, float par8, float par9) {
AdditionalGolemCore core = GadomancyApi.getAdditionalGolemCore(golem);
ItemStack carriedItem = null;
if(core != null) {
toolItem = core.getToolItem(golem);
carriedItem = golem.getCarriedForDisplay();
golem.getDataWatcher().getWatchedObject(16).setObject(null);
}
super.render(golem, par2, par4, par6, par8, par9);
if(carriedItem != null) {
golem.getDataWatcher().getWatchedObject(16).setObject(carriedItem);
toolItem = null;
}
}
@Override
protected ResourceLocation getEntityTexture(Entity entity) {
AdditionalGolemType type = GadomancyApi.getAdditionalGolemType(((EntityGolemBase) entity).getGolemType());
if (type != null) {
return type.getEntityTexture();
}
return super.getEntityTexture(entity);
}
}
@@ -0,0 +1,66 @@
package makeo.gadomancy.common.integration.waila;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.ModContainer;
import makeo.gadomancy.api.GadomancyApi;
import makeo.gadomancy.api.golems.AdditionalGolemType;
import makeo.gadomancy.common.utils.ColorHelper;
import mcp.mobius.waila.api.IWailaConfigHandler;
import mcp.mobius.waila.api.IWailaEntityAccessor;
import mcp.mobius.waila.api.IWailaEntityProvider;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import thaumcraft.common.entities.golems.EntityGolemBase;
import java.util.List;
/**
* 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
*
* Created by makeo @ 25.07.2015 14:14
*/
public class AdvancedGolemProvider implements IWailaEntityProvider {
@Override
public Entity getWailaOverride(IWailaEntityAccessor data, IWailaConfigHandler config) {
return null;
}
@Override
public List<String> getWailaHead(Entity paramEntity, List<String> strings, IWailaEntityAccessor data, IWailaConfigHandler config) {
return null;
}
@Override
public List<String> getWailaBody(Entity paramEntity, List<String> strings, IWailaEntityAccessor data, IWailaConfigHandler config) {
return null;
}
@Override
public List<String> getWailaTail(Entity paramEntity, List<String> strings, IWailaEntityAccessor data, IWailaConfigHandler config) {
if(data.getEntity() instanceof EntityGolemBase) {
AdditionalGolemType type = GadomancyApi.getAdditionalGolemType(((EntityGolemBase) data.getEntity()).getGolemType());
if(type != null && strings.size() > 0) {
String oldMod = strings.get(strings.size() - 1);
ModContainer container = Loader.instance().getIndexedModList().get(type.getModId());
if(container != null) {
String mod = ColorHelper.extractColors(oldMod) + container.getName();
strings.remove(strings.size() - 1);
strings.add(mod);
}
}
}
return strings;
}
@Override
public NBTTagCompound getNBTData(EntityPlayerMP paramEntityPlayerMP, Entity paramEntity, NBTTagCompound paramNBTTagCompound, World paramWorld) {
return null;
}
}
@@ -0,0 +1,51 @@
package makeo.gadomancy.common.integration.waila;
import makeo.gadomancy.common.blocks.tiles.TileInfusionClaw;
import mcp.mobius.waila.api.*;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
import java.util.List;
/**
* 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
*
* Created by makeo @ 07.10.2015 18:02
*/
public class InfusionClawProvider implements IWailaDataProvider {
@Override
public ItemStack getWailaStack(IWailaDataAccessor paramIWailaDataAccessor, IWailaConfigHandler paramIWailaConfigHandler) {
return null;
}
@Override
public List<String> getWailaHead(ItemStack paramItemStack, List<String> paramList, IWailaDataAccessor paramIWailaDataAccessor, IWailaConfigHandler paramIWailaConfigHandler) {
return null;
}
@Override
public List<String> getWailaBody(ItemStack paramItemStack, List<String> strings, IWailaDataAccessor dataAccessor, IWailaConfigHandler paramIWailaConfigHandler) {
TileInfusionClaw tile = (TileInfusionClaw) dataAccessor.getTileEntity();
if(tile.hasOwner()) {
strings.add(StatCollector.translateToLocal("gadomancy.info.InfusionClaw.waila") + " " + tile.getOwner());
}
return strings;
}
@Override
public List<String> getWailaTail(ItemStack paramItemStack, List<String> paramList, IWailaDataAccessor dataAccessor, IWailaConfigHandler paramIWailaConfigHandler) {
return null;
}
@Override
public NBTTagCompound getNBTData(EntityPlayerMP paramEntityPlayerMP, TileEntity paramTileEntity, NBTTagCompound paramNBTTagCompound, World paramWorld, int paramInt1, int paramInt2, int paramInt3) {
return null;
}
}
@@ -0,0 +1,37 @@
package makeo.gadomancy.common.integration.waila;
import makeo.gadomancy.common.blocks.BlockInfusionClaw;
import makeo.gadomancy.common.blocks.tiles.TileStickyJar;
import makeo.gadomancy.common.integration.IntegrationMod;
import mcp.mobius.waila.api.impl.ModuleRegistrar;
import thaumcraft.common.entities.golems.EntityGolemBase;
/**
* 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
*
* Created by makeo @ 24.07.2015 14:48
*/
public class IntegrationWaila extends IntegrationMod {
@Override
public String getModId() {
return "Waila";
}
@Override
protected void doInit() {
registerProviders(ModuleRegistrar.instance());
}
public static void registerProviders(ModuleRegistrar registrar) {
StickyJarProvider stickyJarProvider = new StickyJarProvider();
registrar.registerTailProvider(stickyJarProvider, TileStickyJar.class);
registrar.registerStackProvider(stickyJarProvider, TileStickyJar.class);
registrar.registerTailProvider(new AdvancedGolemProvider(), EntityGolemBase.class);
registrar.registerBodyProvider(new InfusionClawProvider(), BlockInfusionClaw.class);
}
}
@@ -0,0 +1,82 @@
package makeo.gadomancy.common.integration.waila;
import makeo.gadomancy.common.Gadomancy;
import makeo.gadomancy.common.blocks.tiles.TileStickyJar;
import makeo.gadomancy.common.utils.ColorHelper;
import mcp.mobius.waila.api.IWailaConfigHandler;
import mcp.mobius.waila.api.IWailaDataAccessor;
import mcp.mobius.waila.api.IWailaDataProvider;
import mcp.mobius.waila.api.impl.ModuleRegistrar;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
/**
* 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
*
* Created by makeo @ 24.07.2015 16:43
*/
public class StickyJarProvider implements IWailaDataProvider {
@Override
public ItemStack getWailaStack(IWailaDataAccessor data, IWailaConfigHandler config) {
if(data.getTileEntity() instanceof TileStickyJar) {
TileStickyJar stickyJar = (TileStickyJar) data.getTileEntity();
if(stickyJar.isValid()) {
ItemStack stack = new ItemStack(stickyJar.getParentBlock(), 1, stickyJar.getBlockMetadata());
for(IWailaDataProvider provider : getParentProviders(ModuleRegistrar.instance().stackBlockProviders, stickyJar.getParentBlock().getClass(), stickyJar.getParent().getClass())) {
stack = provider.getWailaStack(data, config);
}
return stack;
}
}
return null;
}
private List<IWailaDataProvider> getParentProviders(LinkedHashMap<Class, ArrayList<IWailaDataProvider>> providerMap, Class... classes) {
List<IWailaDataProvider> providers = new ArrayList<IWailaDataProvider>();
for(Class parent : classes) {
ArrayList<IWailaDataProvider> providerList = providerMap.get(parent);
if(providerList != null)
providers.addAll(providerList);
}
return providers;
}
@Override
public List<String> getWailaHead(ItemStack stack, List<String> strings, IWailaDataAccessor data, IWailaConfigHandler config) {
return null;
}
@Override
public List<String> getWailaBody(ItemStack stack, List<String> strings, IWailaDataAccessor data, IWailaConfigHandler config) {
return null;
}
@Override
public List<String> getWailaTail(ItemStack stack, List<String> strings, IWailaDataAccessor data, IWailaConfigHandler config) {
if(data.getTileEntity() instanceof TileStickyJar) {
if(strings.size() > 0) {
String oldMod = strings.get(strings.size() - 1);
String mod = ColorHelper.extractColors(oldMod) + Gadomancy.NAME;
strings.remove(strings.size() - 1);
strings.add(mod);
}
}
return strings;
}
@Override
public NBTTagCompound getNBTData(EntityPlayerMP paramEntityPlayerMP, TileEntity paramTileEntity, NBTTagCompound paramNBTTagCompound, World paramWorld, int paramInt1, int paramInt2, int paramInt3) {
return null;
}
}
@@ -0,0 +1,114 @@
package makeo.gadomancy.common.items;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import makeo.gadomancy.common.blocks.tiles.TileRemoteJar;
import makeo.gadomancy.common.blocks.tiles.TileStickyJar;
import makeo.gadomancy.common.registration.RegisteredBlocks;
import makeo.gadomancy.common.utils.NBTHelper;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
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
*
* Created by makeo @ 14.10.2015 17:51
*/
public class ItemBlockRemoteJar extends ItemBlock {
public ItemBlockRemoteJar() {
super(RegisteredBlocks.blockRemoteJar);
}
public ItemBlockRemoteJar(Block block) {
super(block);
}
@Override
public ItemStack onItemRightClick(ItemStack p_77659_1_, World p_77659_2_, EntityPlayer p_77659_3_) {
return super.onItemRightClick(p_77659_1_, p_77659_2_, p_77659_3_);
}
@Override
public boolean onItemUse(ItemStack p_77648_1_, EntityPlayer p_77648_2_, World p_77648_3_, int p_77648_4_, int p_77648_5_, int p_77648_6_, int p_77648_7_, float p_77648_8_, float p_77648_9_, float p_77648_10_) {
return super.onItemUse(p_77648_1_, p_77648_2_, p_77648_3_, p_77648_4_, p_77648_5_, p_77648_6_, p_77648_7_, p_77648_8_, p_77648_9_, p_77648_10_);
}
@Override
public boolean onItemUseFirst(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) {
TileRemoteJar tile = getJarTile(world, x, y, z);
if (tile != null) {
if(!world.isRemote) {
NBTTagCompound compound = NBTHelper.getData(stack);
UUID networkId = tile.networkId;
if(networkId == null) {
networkId = UUID.randomUUID();
tile.networkId = networkId;
tile.markForUpdate();
}
NBTHelper.setUUID(compound, "networkId", networkId);
return true;
} else {
//TODO: message
return super.onItemUseFirst(stack, player, world, x, y, z, side, hitX, hitY, hitZ);
}
}
return false;
}
@Override
public boolean placeBlockAt(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ, int metadata) {
boolean placed = super.placeBlockAt(stack, player, world, x, y, z, side, hitX, hitY, hitZ, metadata);
if (!world.isRemote && placed && stack.hasTagCompound()) {
TileRemoteJar tile = (TileRemoteJar) world.getTileEntity(x, y, z);
tile.networkId = NBTHelper.getUUID(stack.getTagCompound(), "networkId");
tile.markForUpdate();
}
return placed;
}
private TileRemoteJar getJarTile(World world, int x, int y, int z) {
TileEntity tile = world.getTileEntity(x, y, z);
if (tile != null) {
if (tile instanceof TileRemoteJar) {
return (TileRemoteJar) tile;
}
if (tile instanceof TileStickyJar && ((TileStickyJar) tile).getParent() instanceof TileRemoteJar) {
return (TileRemoteJar) ((TileStickyJar) tile).getParent();
}
}
return null;
}
@Override
public EnumRarity getRarity(ItemStack stack) {
return EnumRarity.uncommon;
}
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack item, EntityPlayer par2EntityPlayer, List list, boolean advancedItemTooltips) {
if (item.hasTagCompound()) {
/*int lx = item.stackTagCompound.getInteger("linkX");
int ly = item.stackTagCompound.getInteger("linkY");
int lz = item.stackTagCompound.getInteger("linkZ");
int ldim = item.stackTagCompound.getInteger("linkDim");
String dimname = item.stackTagCompound.getString("dimname");
list.add("Linked to " + lx + "," + ly + "," + lz + " in " + dimname);*/
}
}
}
@@ -0,0 +1,74 @@
package makeo.gadomancy.common.items;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import makeo.gadomancy.api.GadomancyApi;
import makeo.gadomancy.api.golems.AdditionalGolemType;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import thaumcraft.common.entities.golems.EnumGolemType;
import thaumcraft.common.entities.golems.ItemGolemPlacer;
import java.util.List;
/**
* 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
*
* Created by makeo @ 03.08.2015 14:43
*/
public class ItemFakeGolemPlacer extends Item {
private static final ItemGolemPlacer PLACER = new ItemGolemPlacer();
@SideOnly(Side.CLIENT)
public int getRenderPasses(int metadata) {
return PLACER.getRenderPasses(metadata);
}
@SideOnly(Side.CLIENT)
public boolean requiresMultipleRenderPasses() {
return true;
}
@Override
public boolean getHasSubtypes() {
return true;
}
@Override
public void getSubItems(Item item, CreativeTabs tab, List list) {
for(EnumGolemType type : EnumGolemType.values()) {
list.add(new ItemStack(this, 1, type.ordinal()));
}
}
@Override
public void registerIcons(IIconRegister ir) {
PLACER.registerIcons(ir);
for(AdditionalGolemType type : GadomancyApi.getAdditionalGolemTypes()) {
type.registerIcons(ir);
}
}
@Override
public IIcon getIcon(ItemStack stack, int pass) {
AdditionalGolemType type = getAdditonalType(stack);
if(type != null) {
return type.getPlacerItem().getIcon(stack, pass);
}
return PLACER.getIcon(stack, pass);
}
private AdditionalGolemType getAdditonalType(ItemStack stack) {
EnumGolemType type = EnumGolemType.getType(stack.getItemDamage());
if(type != null) {
return GadomancyApi.getAdditionalGolemType(type);
}
return null;
}
}
@@ -0,0 +1,68 @@
package makeo.gadomancy.common.items;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import makeo.gadomancy.common.Gadomancy;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import java.util.List;
/**
* 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
*
* Created by makeo @ 25.06.2015 22:25
*/
public class ItemFakeGolemShield extends Item {
private final Item golemItem = new ItemFakeGolemPlacer();
private IIcon shieldIcon;
public ItemFakeGolemShield() {
setCreativeTab(null);
}
@SideOnly(Side.CLIENT)
public int getRenderPasses(int metadata) {
return golemItem.getRenderPasses(metadata) + 1;
}
@Override
public boolean getHasSubtypes() {
return golemItem.getHasSubtypes();
}
@Override
public void getSubItems(Item item, CreativeTabs tab, List list) {
golemItem.getSubItems(item, tab, list);
}
@SideOnly(Side.CLIENT)
public boolean requiresMultipleRenderPasses() {
return true;
}
@Override
public void registerIcons(IIconRegister ir) {
shieldIcon = ir.registerIcon(Gadomancy.MODID + ":r_runicupg");
golemItem.registerIcons(ir);
}
@Override
public IIcon getIcon(ItemStack stack, int pass) {
if(pass == getRenderPasses(stack.getItemDamage()) - 1) {
return shieldIcon;
} else {
//EnumGolemType type = EnumGolemType.getType(stack.getItemDamage());
//TODO: change dat
return golemItem.getIcon(stack, pass);
}
}
}
@@ -0,0 +1,50 @@
package makeo.gadomancy.common.items;
import makeo.gadomancy.common.Gadomancy;
import makeo.gadomancy.common.registration.RegisteredItems;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.StatCollector;
import java.util.List;
/**
* 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
*
* Created by makeo @ 02.10.2015 19:40
*/
public class ItemGolemCoreBreak extends Item {
public ItemGolemCoreBreak() {
setCreativeTab(RegisteredItems.creativeTab);
}
@Override
protected String getIconString() {
return Gadomancy.MODID + ":golem_core_break";
}
@Override
public String getUnlocalizedName() {
return "item.ItemGolemCore";
}
@Override
public String getUnlocalizedName(ItemStack stack) {
return getUnlocalizedName();
}
@Override
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean showAdvanced) {
list.add(StatCollector.translateToLocal("gadomancy.golem.breakcore"));
}
@Override
public EnumRarity getRarity(ItemStack stack) {
return EnumRarity.uncommon;
}
}
@@ -0,0 +1,107 @@
package makeo.gadomancy.common.items;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import makeo.gadomancy.common.Gadomancy;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.world.World;
import thaumcraft.api.aspects.Aspect;
import thaumcraft.api.aspects.AspectList;
import thaumcraft.api.wands.FocusUpgradeType;
import thaumcraft.api.wands.ItemFocusBasic;
/**
* 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
*
* Created by makeo @ 13.07.2015 02:14
*/
public class ItemTransformationFocus extends ItemFocusBasic {
private static final AspectList VIS_USAGE = new AspectList().add(Aspect.AIR, 15).add(Aspect.EARTH, 15).add(Aspect.ORDER, 15);
private IIcon iconOrnament;
private IIcon iconDepth;
public ItemTransformationFocus() {
//setCreativeTab(RegisteredItems.creativeTab);
setCreativeTab(null);
setUnlocalizedName("ItemTransformationFocus");
}
@Override
public ItemStack onFocusRightClick(ItemStack wandStack, World world, EntityPlayer player, MovingObjectPosition movingobjectposition) {
player.setItemInUse(wandStack, 2147483647);
//WandManager.setCooldown(player, -1);
return wandStack;
}
@Override
public void onUsingFocusTick(ItemStack wandstack, EntityPlayer player, int count) {
}
@Override
public EnumRarity getRarity(ItemStack focusstack) {
return EnumRarity.rare;
}
@Override
public boolean isVisCostPerTick(ItemStack item) {
return false;
}
@Override
public AspectList getVisCost(ItemStack item) {
return VIS_USAGE;
}
@Override
public IIcon getOrnament(ItemStack item) {
return iconOrnament;
}
@Override
public int getFocusColor(ItemStack item) {
return 0xffffff;
}
@Override
public WandFocusAnimation getAnimation(ItemStack item) {
return WandFocusAnimation.CHARGE;
}
@Override
public IIcon getFocusDepthLayerIcon(ItemStack item) {
return iconDepth;
}
@SideOnly(Side.CLIENT)
public IIcon getIconFromDamageForRenderPass(int par1, int renderPass) {
return renderPass == 1 ? this.icon : this.iconOrnament;
}
@SideOnly(Side.CLIENT)
public boolean requiresMultipleRenderPasses() {
return true;
}
@SideOnly(Side.CLIENT)
@Override
public void registerIcons(IIconRegister ir) {
iconOrnament = ir.registerIcon("thaumcraft:focus_whatever_orn");
iconDepth = ir.registerIcon(Gadomancy.MODID + ":focus_transformation_depth");
icon = ir.registerIcon(Gadomancy.MODID + ":focus_transformation");
}
@Override
public FocusUpgradeType[] getPossibleUpgradesByRank(ItemStack focusstack, int rank) {
return null;
}
}
@@ -0,0 +1,27 @@
package makeo.gadomancy.common.network;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper;
import cpw.mods.fml.relauncher.Side;
import makeo.gadomancy.common.Gadomancy;
import makeo.gadomancy.common.network.packets.PacketStartAnimation;
import makeo.gadomancy.common.network.packets.PacketUpdateGolemTypeOrder;
/**
* 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
*
* Created by makeo @ 03.07.2015 19:13
*/
public class PacketHandler {
public static final SimpleNetworkWrapper INSTANCE = NetworkRegistry.INSTANCE.newSimpleChannel(Gadomancy.MODID.toLowerCase());
public static void init() {
int id = 0;
INSTANCE.registerMessage(PacketUpdateGolemTypeOrder.class, PacketUpdateGolemTypeOrder.class, id++, Side.CLIENT);
INSTANCE.registerMessage(PacketStartAnimation.class, PacketStartAnimation.class, id++, Side.CLIENT);
}
}
@@ -0,0 +1,59 @@
package makeo.gadomancy.common.network.packets;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
import io.netty.buffer.ByteBuf;
import makeo.gadomancy.common.blocks.tiles.TileInfusionClaw;
import net.minecraft.client.Minecraft;
/**
* 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
*
* Created by makeo @ 11.10.2015 15:19
*/
public class PacketStartAnimation implements IMessage, IMessageHandler<PacketStartAnimation, IMessage> {
private byte annimationId;
private int x;
private int y;
private int z;
public PacketStartAnimation(byte annimationId, int x, int y, int z) {
this.annimationId = annimationId;
this.x = x;
this.y = y;
this.z = z;
}
public PacketStartAnimation() {}
@Override
public void fromBytes(ByteBuf buf) {
this.annimationId = buf.readByte();
this.x = buf.readInt();
this.y = buf.readInt();
this.z = buf.readInt();
}
@Override
public void toBytes(ByteBuf buf) {
buf.writeByte(annimationId);
buf.writeInt(x);
buf.writeInt(y);
buf.writeInt(z);
}
@Override
public IMessage onMessage(PacketStartAnimation message, MessageContext ctx) {
if(message.annimationId == 0) {
TileInfusionClaw tile = (TileInfusionClaw) Minecraft.getMinecraft().theWorld.getTileEntity(message.x, message.y, message.z);
if(tile != null) {
tile.animationStates[8] = 1;
}
}
return null;
}
}
@@ -0,0 +1,62 @@
package makeo.gadomancy.common.network.packets;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
import io.netty.buffer.ByteBuf;
import makeo.gadomancy.common.utils.GolemEnumHelper;
import java.io.*;
import java.util.Map;
/**
* 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
*
* Created by makeo @ 30.07.2015 18:07
*/
public class PacketUpdateGolemTypeOrder implements IMessage, IMessageHandler<PacketUpdateGolemTypeOrder, IMessage> {
private Map<String, Integer> mapping;
public PacketUpdateGolemTypeOrder() {}
public PacketUpdateGolemTypeOrder(Map<String, Integer> mapping) {
this.mapping = mapping;
}
@Override
public void fromBytes(ByteBuf buf) {
byte[] data = new byte[buf.readInt()];
buf.readBytes(data);
ByteArrayInputStream in = new ByteArrayInputStream(data);
try {
mapping = (Map<String, Integer>) new ObjectInputStream(in).readObject();
in.close();
} catch (Exception ignored) { }//IOException | ClassNotFoundException ignored
}
@Override
public void toBytes(ByteBuf buf) {
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
new ObjectOutputStream(out).writeObject(mapping);
} catch (IOException ignored) { }
byte[] data = out.toByteArray();
buf.writeInt(data.length);
buf.writeBytes(data);
try {
out.close();
} catch (IOException ignored) { }
}
@Override
public IMessage onMessage(PacketUpdateGolemTypeOrder message, MessageContext ctx) {
GolemEnumHelper.reorderEnum(message.mapping);
return null;
}
}
@@ -0,0 +1,175 @@
package makeo.gadomancy.common.registration;
import cpw.mods.fml.common.registry.GameRegistry;
import makeo.gadomancy.api.ClickBehavior;
import makeo.gadomancy.common.blocks.BlockArcaneDropper;
import makeo.gadomancy.common.blocks.BlockInfusionClaw;
import makeo.gadomancy.common.blocks.BlockRemoteJar;
import makeo.gadomancy.common.blocks.BlockStickyJar;
import makeo.gadomancy.common.blocks.tiles.TileArcaneDropper;
import makeo.gadomancy.common.blocks.tiles.TileInfusionClaw;
import makeo.gadomancy.common.blocks.tiles.TileRemoteJar;
import makeo.gadomancy.common.blocks.tiles.TileStickyJar;
import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemBlock;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import thaumcraft.common.config.ConfigBlocks;
import thaumcraft.common.tiles.TileInfusionMatrix;
import java.util.ArrayList;
import java.util.List;
/**
* 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
*
* Created by makeo @ 13.07.2015 18:38
*/
public class RegisteredBlocks {
private RegisteredBlocks() {}
public static int rendererTransparentBlock;
public static BlockStickyJar blockStickyJar;
public static BlockArcaneDropper blockArcaneDropper;
public static BlockInfusionClaw blockInfusionClaw;
public static BlockRemoteJar blockRemoteJar;
public static void init() {
registerBlocks();
registerTileEntities();
registerDefaultStickyJars();
registerDefaultClawBehaviors();
}
//Blocks
private static void registerBlocks() {
blockStickyJar = registerBlock(new BlockStickyJar());
blockArcaneDropper = registerBlock(new BlockArcaneDropper());
blockInfusionClaw = registerBlock(new BlockInfusionClaw());
blockRemoteJar = registerBlock(new BlockRemoteJar());
}
private static <T extends Block> T registerBlock(String name, T block) {
block.setBlockName(name);
GameRegistry.registerBlock(block, name);
return block;
}
private static <T extends Block> T registerBlock(String name, T block, Class<? extends ItemBlock> itemClass) {
block.setBlockName(name);
GameRegistry.registerBlock(block, itemClass, name);
return block;
}
private static <T extends Block> T registerBlock(T block, Class<? extends ItemBlock> itemClass) {
registerBlock(block.getClass().getSimpleName(), block, itemClass);
return block;
}
private static <T extends Block> T registerBlock(T block) {
registerBlock(block.getClass().getSimpleName(), block);
return block;
}
//Tiles
private static void registerTileEntities() {
registerTile(TileStickyJar.class);
registerTile(TileArcaneDropper.class);
registerTile(TileInfusionClaw.class);
registerTile(TileRemoteJar.class);
}
private static void registerTile(Class<? extends TileEntity> tile, String name) {
GameRegistry.registerTileEntity(tile, name);
}
private static void registerTile(Class<? extends TileEntity> tile) {
registerTile(tile, tile.getSimpleName());
}
//Sticky Jars
private static void registerDefaultStickyJars() {
registerStickyJar(ConfigBlocks.blockJar, 0, true, true);
registerStickyJar(ConfigBlocks.blockJar, 3, true, true);
}
private static List<StickyJarInfo> stickyJars = new ArrayList<StickyJarInfo>();
public static void registerStickyJar(Block block, int metadata, boolean isLabelable, boolean isPhialable) {
stickyJars.add(0, new StickyJarInfo(block, metadata, isLabelable, isPhialable));
}
public static StickyJarInfo getStickyJarInfo(Block block, int metadata) {
for(StickyJarInfo info : stickyJars) {
if(info.getBlock() == block && info.getMetadata() == metadata) {
return info;
}
}
return null;
}
//Infusion Claw
private static void registerDefaultClawBehaviors() {
registerClawClickBehavior(new ClickBehavior() {
@Override
public boolean isValidForBlock() {
return (block == Blocks.bookshelf && metadata == 0)
|| (block == Blocks.cauldron && metadata == 0);
}
});
registerClawClickBehavior(new ClickBehavior(true) {
private TileInfusionMatrix matrix;
@Override
public boolean isValidForBlock() {
if(block == ConfigBlocks.blockStoneDevice && metadata == 2) {
matrix = (TileInfusionMatrix) world.getTileEntity(x, y, z);
return true;
}
return false;
}
@Override
public void addInstability(int instability) {
matrix.instability += instability;
}
@Override
public int getComparatorOutput() {
return matrix.crafting ? 15 : 0;
}
});
}
private static List<ClickBehavior> clawBehaviors = new ArrayList<ClickBehavior>();
public static void registerClawClickBehavior(ClickBehavior behavior) {
clawBehaviors.add(behavior);
}
public static ClickBehavior getClawClickBehavior(World world, int x, int y, int z) {
Block block = world.getBlock(x, y, z);
int metadata = world.getBlockMetadata(x, y, z);
for(ClickBehavior behavior : clawBehaviors) {
behavior.init(world, block, x, y, z, metadata);
if(behavior.isValidForBlock()) {
return behavior;
}
}
return null;
}
public static List<ClickBehavior> getClawClickBehaviors() {
return clawBehaviors;
}
}
@@ -0,0 +1,55 @@
package makeo.gadomancy.common.registration;
import makeo.gadomancy.common.Gadomancy;
import makeo.gadomancy.api.GadomancyApi;
import makeo.gadomancy.api.golems.AdditionalGolemType;
import makeo.gadomancy.api.golems.cores.AdditionalGolemCore;
import makeo.gadomancy.common.entities.golems.cores.BreakGolemCore;
import makeo.gadomancy.common.entities.golems.types.SilverwoodGolemType;
import makeo.gadomancy.common.entities.golems.upgrades.GolemUpgrade;
import makeo.gadomancy.common.entities.golems.upgrades.GolemUpgradeRunicShield;
import java.util.ArrayList;
import java.util.List;
/**
* 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
*
* Created by makeo @ 22.06.2015 02:58
*/
public class RegisteredGolemStuff {
private RegisteredGolemStuff() {}
public static final List<GolemUpgrade> UPGRADES = new ArrayList<GolemUpgrade>();
public static GolemUpgradeRunicShield upgradeRunicShield;
public static SilverwoodGolemType typeSilverwood;
public static AdditionalGolemCore breakCore;
public static void init() {
typeSilverwood = registerGolemType("SILVERWOOD", new SilverwoodGolemType());
breakCore = registerGolemCore("breakCore", new BreakGolemCore());
upgradeRunicShield = registerGolemUpgrade(new GolemUpgradeRunicShield());
}
private static <T extends AdditionalGolemType> T registerGolemType(String name, T type) {
GadomancyApi.registerAdditionalGolemType(name, Gadomancy.MODID, type);
return type;
}
private static <T extends AdditionalGolemCore> T registerGolemCore(String name, T core) {
GadomancyApi.registerAdditionalGolemCore(name, core);
return core;
}
private static <T extends GolemUpgrade> T registerGolemUpgrade(T upgrade) {
UPGRADES.add(upgrade);
return upgrade;
}
}
@@ -0,0 +1,66 @@
package makeo.gadomancy.common.registration;
import cpw.mods.fml.common.FMLLog;
import cpw.mods.fml.common.Loader;
import makeo.gadomancy.common.integration.IntegrationAutomagy;
import makeo.gadomancy.common.integration.IntegrationMod;
import makeo.gadomancy.common.integration.IntegrationMorph;
import makeo.gadomancy.common.integration.IntegrationThaumicExploration;
import makeo.gadomancy.common.utils.Injector;
/**
* 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
*
* Created by makeo @ 09.07.2015 16:00
*/
public class RegisteredIntegrations {
public static IntegrationMorph morph;
public static IntegrationThaumicExploration thaumicExploration;
public static IntegrationAutomagy automagy;
private RegisteredIntegrations() {}
public static void init() {
morph = registerUndependent(IntegrationMorph.class);
thaumicExploration = registerUndependent(IntegrationThaumicExploration.class);
automagy = registerUndependent(IntegrationAutomagy.class);
registerDependent("ThaumicHorizons", "makeo.gadomancy.common.integration.thaumichorizions.IntegrationThaumicHorizions");
registerDependent("Waila", "makeo.gadomancy.common.integration.waila.IntegrationWaila");
}
private static void registerDependent(String modId, String clazz) {
if(!Loader.isModLoaded(modId)) {
return;
}
Object integration;
try {
integration = Injector.getClass(clazz).newInstance();
} catch (Exception e) {//InstantiationException | IllegalAccessException
return;
}
if(integration instanceof IntegrationMod) {
((IntegrationMod) integration).init();
}
}
private static <T extends IntegrationMod> T registerUndependent(Class<T> clazz) {
T integration;
try {
integration = clazz.newInstance();
} catch (Exception e) {//InstantiationException | IllegalAccessException
return null;
}
integration.init();
if(integration.isPresent()) {
FMLLog.severe("Initialized hook for mod \"" + integration.getModId() + "\"!");
}
return integration;
}
}
@@ -0,0 +1,126 @@
package makeo.gadomancy.common.registration;
import cpw.mods.fml.common.registry.GameRegistry;
import makeo.gadomancy.common.Gadomancy;
import makeo.gadomancy.common.items.ItemFakeGolemPlacer;
import makeo.gadomancy.common.items.ItemFakeGolemShield;
import makeo.gadomancy.common.items.ItemGolemCoreBreak;
import makeo.gadomancy.common.items.ItemTransformationFocus;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import thaumcraft.common.config.ConfigBlocks;
import thaumcraft.common.config.ConfigItems;
import java.util.ArrayList;
import java.util.List;
/**
* 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
*
* Created by makeo @ 03.06.2015 03:37
*/
public class RegisteredItems {
private RegisteredItems() {}
public static CreativeTabs creativeTab;
public static Item itemFakeGolemShield;
public static Item itemFakeGolemPlacer;
public static Item itemTransformationFocus;
public static Item itemGolemCoreBreak;
public static void preInit() {
creativeTab = new CreativeTabs(Gadomancy.MODID) {
@Override
public Item getTabIconItem() {
return Items.boat;
}
};
}
public static void init() {
registerItems();
registerDefaultStickyJars();
}
//Items
private static void registerItems() {
itemFakeGolemPlacer = registerItem(new ItemFakeGolemPlacer());
itemFakeGolemShield = registerItem(new ItemFakeGolemShield());
itemTransformationFocus = registerItem(new ItemTransformationFocus());
itemGolemCoreBreak = registerItem(new ItemGolemCoreBreak());
}
private static <T extends Item> T registerItem(T item, String name) {
GameRegistry.registerItem(item, name);
return item;
}
private static <T extends Item> T registerItem(T item) {
return registerItem(item, item.getClass().getSimpleName());
}
//Sticky jars
private static void registerDefaultStickyJars() {
registerStickyJar(ConfigItems.itemJarFilled, 0);
registerStickyJar(ConfigItems.itemJarFilled, 3);
Item itemBlockJar = Item.getItemFromBlock(ConfigBlocks.blockJar);
registerStickyJar(itemBlockJar, 0, new ItemStack(itemBlockJar, 1, 0));
registerStickyJar(itemBlockJar, 3, new ItemStack(itemBlockJar, 1, 3));
}
private static List<StickyJarItemInfo> stickyJarItems = new ArrayList<StickyJarItemInfo>();
public static void registerStickyJar(Item item, int damage, ItemStack recipeStack) {
StickyJarItemInfo info = new StickyJarItemInfo();
info.item = item;
info.damage = damage;
info.recipeStack = recipeStack;
stickyJarItems.add(info);
}
public static void registerStickyJar(Item item, int damage) {
registerStickyJar(item, damage, null);
}
public static void registerStickyJar(Item item) {
registerStickyJar(item, Short.MAX_VALUE);
}
public static boolean isStickyableJar(Item item, int damage) {
for(StickyJarItemInfo info : stickyJarItems) {
if(info.item == item && (info.damage == damage || info.damage == Short.MAX_VALUE)) {
return true;
}
}
return false;
}
public static boolean isStickyableJar(ItemStack stack) {
return stack != null && isStickyableJar(stack.getItem(), stack.getItemDamage());
}
public static List<ItemStack> getStickyJarStacks() {
List<ItemStack> stacks = new ArrayList<ItemStack>();
for(StickyJarItemInfo info : stickyJarItems) {
if(info.recipeStack != null) {
stacks.add(info.recipeStack);
}
}
return stacks;
}
private static class StickyJarItemInfo {
public Item item;
public int damage;
public ItemStack recipeStack;
}
}
@@ -0,0 +1,100 @@
package makeo.gadomancy.common.registration;
import makeo.gadomancy.api.golems.AdditionalGolemType;
import makeo.gadomancy.common.crafting.InfusionUpgradeRecipe;
import makeo.gadomancy.common.crafting.RecipeStickyJar;
import makeo.gadomancy.common.research.SimpleResearchItem;
import makeo.gadomancy.common.utils.NBTHelper;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import thaumcraft.api.ThaumcraftApi;
import thaumcraft.api.aspects.Aspect;
import thaumcraft.api.aspects.AspectList;
import thaumcraft.api.crafting.IArcaneRecipe;
import thaumcraft.api.crafting.InfusionRecipe;
import thaumcraft.api.crafting.ShapedArcaneRecipe;
import thaumcraft.common.config.ConfigBlocks;
import thaumcraft.common.config.ConfigItems;
import java.util.Arrays;
import java.util.List;
/**
* 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
*
* Created by makeo @ 16.06.2015 01:17
*/
public class RegisteredRecipes {
private RegisteredRecipes() {}
public static InfusionRecipe recipeGolemSilverwood;
public static InfusionRecipe[] recipesGolemRunicShield;
public static InfusionRecipe recipeGolemCoreBreak;
public static InfusionRecipe recipeInfusionClaw;
public static IArcaneRecipe recipeStickyJar;
public static IArcaneRecipe recipeArcaneDropper;
public static void init() {
AdditionalGolemType typeSilverwood = RegisteredGolemStuff.typeSilverwood;
recipeGolemSilverwood = ThaumcraftApi.addInfusionCraftingRecipe(SimpleResearchItem.getFullName("GOLEMSILVERWOOD"),
/*new ItemStack(Items.bread, 1, 0),*/new ItemStack(typeSilverwood.getPlacerItem(), 1, typeSilverwood.getEnumEntry().ordinal()),
7, new AspectList().add(Aspect.MOTION, 16).add(Aspect.MAGIC, 16).add(Aspect.MAN, 16).add(Aspect.SENSES, 16),
new ItemStack(ConfigBlocks.blockMagicalLog, 1, 1), new ItemStack[]{ new ItemStack(ConfigItems.itemResource, 1, 15), new ItemStack(ConfigItems.itemResource, 1, 14), new ItemStack(ConfigItems.itemResource, 1, 9), new ItemStack(ConfigItems.itemResource, 1, 3), new ItemStack(ConfigItems.itemResource, 1, 14), new ItemStack(ConfigItems.itemResource, 1, 9), new ItemStack(ConfigItems.itemResource, 1, 3)});
recipesGolemRunicShield = InfusionUpgradeRecipe.createRecipes(SimpleResearchItem.getFullName("GOLEMSILVERWOOD"), RegisteredGolemStuff.upgradeRunicShield, 5,
new AspectList().add(Aspect.MAGIC, 16).add(Aspect.ENERGY, 16).add(Aspect.ARMOR, 8).add(Aspect.AURA, 4),
new ItemStack[]{new ItemStack(ConfigItems.itemGirdleRunic, 1, 0), new ItemStack(ConfigItems.itemResource, 1, 14), new ItemStack(ConfigItems.itemResource, 1, 14)});
ThaumcraftApi.getCraftingRecipes().addAll(Arrays.asList(recipesGolemRunicShield));
recipeStickyJar = new RecipeStickyJar();
ThaumcraftApi.getCraftingRecipes().add(recipeStickyJar);
//GameRegistry.addRecipe(recipeStickyJar);
recipeArcaneDropper = ThaumcraftApi.addArcaneCraftingRecipe(SimpleResearchItem.getFullName("ARCANEDROPPER"), new ItemStack(RegisteredBlocks.blockArcaneDropper), new AspectList().add(Aspect.ORDER, 14).add(Aspect.AIR, 14).add(Aspect.EARTH, 10),
"SDS", "BAB", "SSS", 'S', new ItemStack(ConfigBlocks.blockCosmeticSolid, 1, 6), 'D', new ItemStack(Blocks.dropper), 'A', new ItemStack(ConfigBlocks.blockMetalDevice, 1, 9), 'B', new ItemStack(ConfigBlocks.blockWoodenDevice));
recipeGolemCoreBreak = ThaumcraftApi.addInfusionCraftingRecipe(SimpleResearchItem.getFullName("GOLEMCOREBREAK"),
new ItemStack(RegisteredItems.itemGolemCoreBreak),
3, new AspectList().add(Aspect.ENTROPY, 16).add(Aspect.TOOL, 24).add(Aspect.MECHANISM, 16),
new ItemStack(ConfigItems.itemGolemCore, 1, 3), new ItemStack[] {new ItemStack(ConfigItems.itemShovelElemental), new ItemStack(ConfigItems.itemPickElemental), new ItemStack(ConfigItems.itemAxeElemental)});
recipeInfusionClaw = ThaumcraftApi.addInfusionCraftingRecipe(SimpleResearchItem.getFullName("GOLEMCOREBREAK"),
new ItemStack(RegisteredBlocks.blockInfusionClaw),
10, new AspectList().add(Aspect.ELDRITCH, 25).add(Aspect.MECHANISM, 20).add(Aspect.MAGIC, 16).add(Aspect.ORDER, 20).add(Aspect.DARKNESS, 12),
new ItemStack(ConfigBlocks.blockStoneDevice, 1, 5), new ItemStack[]{new ItemStack(ConfigItems.itemFocusPrimal), /*new ItemStack(Items.redstone),*/ new ItemStack(ConfigBlocks.blockCosmeticSolid, 1, 6), new ItemStack(ConfigItems.itemGolemCore, 1, 8), new ItemStack(ConfigItems.itemResource, 1, 16), new ItemStack(ConfigBlocks.blockCosmeticSolid, 1, 6), new ItemStack(ConfigItems.itemResource, 1, 15), /*new ItemStack(Items.redstone),*/ new ItemStack(ConfigBlocks.blockCosmeticSolid, 1, 6), new ItemStack(ConfigItems.itemZombieBrain), new ItemStack(ConfigItems.itemResource, 1, 16), new ItemStack(ConfigBlocks.blockCosmeticSolid, 1, 6)});
}
private static IArcaneRecipe[] stickyJarRecipes = null;
public static IArcaneRecipe[] getVisualStickyJarRecipes() {
if(stickyJarRecipes == null) {
List<ItemStack> stacks = RegisteredItems.getStickyJarStacks();
stickyJarRecipes = new IArcaneRecipe[stacks.size()];
ItemStack slime = new ItemStack(Items.slime_ball, 1, 0);
for(int i = 0; i < stacks.size(); i++) {
ItemStack stack = stacks.get(i);
ItemStack output = stack.copy();
NBTHelper.getData(output).setBoolean("isStickyJar", true);
stickyJarRecipes[i] = new ShapedArcaneRecipe(SimpleResearchItem.getFullName("STICKYJAR"), output,
new AspectList().add(Aspect.WATER, 10).add(Aspect.EARTH, 10),
" ",
" A ",
" B ",
'A', stack, 'B', slime);
}
}
return stickyJarRecipes;
}
}
@@ -0,0 +1,83 @@
package makeo.gadomancy.common.registration;
import makeo.gadomancy.common.Gadomancy;
import makeo.gadomancy.common.research.AlternatingResearchItem;
import makeo.gadomancy.common.research.PseudoResearchItem;
import makeo.gadomancy.common.research.SimpleResearchItem;
import makeo.gadomancy.common.utils.SimpleResourceLocation;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import thaumcraft.api.aspects.Aspect;
import thaumcraft.api.aspects.AspectList;
import thaumcraft.api.research.ResearchCategories;
import thaumcraft.api.research.ResearchItem;
import thaumcraft.api.research.ResearchPage;
/**
* 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
*
* Created by makeo @ 14.06.2015 14:01
*/
public class RegisteredResearches {
private RegisteredResearches() {}
private static final ResourceLocation CATEGORY_BACKGROUND = new SimpleResourceLocation("/gui/gui_researchback.png");
private static final ResourceLocation CATEGORY_ICON = new SimpleResourceLocation("/misc/category_icon.png");
public static ResearchItem researchGolemSilverwood;
public static ResearchItem researchGolemRunicShield;
public static ResearchItem researchStickyJar;
public static ResearchItem researchArcaneDropper;
public static ResearchItem researchGolemCoreBreak;
public static ResearchItem researchInfusionClaw;
public static void init() {
ResearchCategories.registerCategory(Gadomancy.MODID, CATEGORY_ICON, CATEGORY_BACKGROUND);
ResearchItem researchAdvancedGolem = PseudoResearchItem.create("ADVANCEDGOLEM", 2, -2).registerResearchItem();
researchGolemSilverwood = new SimpleResearchItem("GOLEMSILVERWOOD", 4, -3, 3, (ItemStack) RegisteredRecipes.recipeGolemSilverwood.getRecipeOutput(),
new AspectList().add(Aspect.MOTION, 10).add(Aspect.TREE, 10).add(Aspect.MAGIC, 8).add(Aspect.ORDER, 8).add(Aspect.FLESH, 6).add(Aspect.EXCHANGE, 5))
.setParents(researchAdvancedGolem.key).setConcealed()
.setPages(new ResearchPage("gadomancy.research_page.GOLEMSILVERWOOD.1"), new ResearchPage(RegisteredRecipes.recipeGolemSilverwood)).registerResearchItem();
researchGolemRunicShield = new SimpleResearchItem("GOLEMRUNICSHIELD", 6, -4, 4, new ItemStack(RegisteredItems.itemFakeGolemShield, 1, 32767),
new AspectList().add(Aspect.AURA, 16))
.setParents(researchGolemSilverwood.key).setConcealed()
.setPages(new ResearchPage("gadomancy.research_page.GOLEMRUNICSHIELD.1"), new ResearchPage(RegisteredRecipes.recipesGolemRunicShield)).registerResearchItem();
ResearchItem researchDistill = PseudoResearchItem.create("DISTILESSENTIA", -2, -1).registerResearchItem();
researchArcaneDropper = new SimpleResearchItem("ARCANEDROPPER", -1, -1, 2, new ItemStack(RegisteredBlocks.blockArcaneDropper),
new AspectList().add(Aspect.ORDER, 4).add(Aspect.AIR, 6).add(Aspect.EARTH, 5).add(Aspect.SENSES, 5).add(Aspect.MECHANISM, 7))
.setParents(researchDistill.key).setConcealed()
.setPages(new ResearchPage("gadomancy.research_page.ARCANEDROPPER.1"), new ResearchPage(RegisteredRecipes.recipeArcaneDropper)).registerResearchItem();
ResearchItem researchCoreGather = PseudoResearchItem.create("COREGATHER", 3, 0).registerResearchItem();
researchGolemCoreBreak = new SimpleResearchItem("GOLEMCOREBREAK", 5, -1, 3, new ItemStack(RegisteredItems.itemGolemCoreBreak),
new AspectList().add(Aspect.TOOL, 8).add(Aspect.ENTROPY, 8).add(Aspect.MECHANISM, 8))
.setParents(researchCoreGather.key).setConcealed()
.setPages(new ResearchPage("gadomancy.research_page.GOLEMCOREBREAK.1"), new ResearchPage(RegisteredRecipes.recipeGolemCoreBreak)).registerResearchItem();
ResearchItem researchFocusPrimal = PseudoResearchItem.create("FOCUSPRIMAL", -2, -3).registerResearchItem();
researchInfusionClaw = new SimpleResearchItem("INFUSIONCLAW", -1, -3, 5, new ItemStack(RegisteredBlocks.blockInfusionClaw),
new AspectList().add(Aspect.ELDRITCH, 8).add(Aspect.MECHANISM, 8).add(Aspect.MAGIC, 8).add(Aspect.ORDER, 8).add(Aspect.DARKNESS, 4))
.setParents(researchFocusPrimal.key).setConcealed()
.setPages(new ResearchPage("gadomancy.research_page.INFUSIONCLAW.1"), new ResearchPage(RegisteredRecipes.recipeInfusionClaw)).registerResearchItem();
}
public static void postInit() {
ResearchItem researchVoidJar = PseudoResearchItem.create("JARVOID", -2, 1).registerResearchItem();
researchStickyJar = new AlternatingResearchItem("STICKYJAR", -1, 1, 2,
new AspectList().add(Aspect.SLIME, 8).add(Aspect.EARTH, 8),
RegisteredItems.getStickyJarStacks())
.setParents(researchVoidJar.key).setConcealed()
.setPages(new ResearchPage("gadomancy.research_page.STICKYJAR.1"), new ResearchPage(RegisteredRecipes.getVisualStickyJarRecipes())).registerResearchItem();
}
}
@@ -0,0 +1,41 @@
package makeo.gadomancy.common.registration;
import net.minecraft.block.Block;
/**
* 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
*
* Created by makeo @ 21.07.2015 02:31
*/
public class StickyJarInfo {
private Block block;
private int metadata;
private boolean needsLabelHandling;
private boolean needsPhialHandling;
public StickyJarInfo(Block block, int metadata, boolean needsLabelHandling, boolean needsPhialHandling) {
this.block = block;
this.metadata = metadata;
this.needsLabelHandling = needsLabelHandling;
this.needsPhialHandling = needsPhialHandling;
}
public Block getBlock() {
return block;
}
public int getMetadata() {
return metadata;
}
public boolean needsLabelHandling() {
return needsLabelHandling;
}
public boolean needsPhialHandling() {
return needsPhialHandling;
}
}
@@ -0,0 +1,48 @@
package makeo.gadomancy.common.research;
import makeo.gadomancy.common.utils.Injector;
import net.minecraft.item.ItemStack;
import thaumcraft.api.aspects.AspectList;
import thaumcraft.api.research.ResearchItem;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.List;
/**
* 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
*
* Created by makeo @ 25.07.2015 19:28
*/
public class AlternatingResearchItem extends SimpleResearchItem {
private static final Field ICON_FIELD = Injector.getField("icon_item", ResearchItem.class);
private final Injector injector = new Injector(this, ResearchItem.class);
private List<ItemStack> itemIcons = null;
public AlternatingResearchItem(String key, int col, int row, int complex, AspectList tags, List<ItemStack> icons) {
super(key, col, row, complex, icons.get(0), tags);
this.itemIcons = icons;
}
public AlternatingResearchItem(String key, int col, int row, int complex, AspectList tags, ItemStack... icons) {
this(key, col, row, complex, tags, Arrays.asList(icons));
}
private void updateIcon() {
injector.setField(ICON_FIELD, itemIcons.get(calcIndex(itemIcons.size())));
}
private int calcIndex(int max) {
return (int)(System.currentTimeMillis() / 1000L % max);
}
@Override
public boolean isSpecial() {
updateIcon();
return super.isSpecial();
}
}
@@ -0,0 +1,96 @@
package makeo.gadomancy.common.research;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import thaumcraft.api.ThaumcraftApiHelper;
import thaumcraft.api.aspects.AspectList;
import thaumcraft.api.research.ResearchCategories;
import thaumcraft.api.research.ResearchItem;
import thaumcraft.api.research.ResearchPage;
import java.util.Arrays;
/**
* 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
*
* Created by makeo @ 14.06.2015 14:57
*/
public class PseudoResearchItem extends SimpleResearchItem {
private static final String PSEUDO_PREFIX = "PSEUDO.";
private final ResearchItem original;
private PseudoResearchItem(ResearchItem original, String key, int col, int row, ResourceLocation icon) {
super(PSEUDO_PREFIX + key, col, row, original.getComplexity(), icon, new AspectList());
this.original = original;
setStub().setHidden();
}
private PseudoResearchItem(ResearchItem original, String key, int col, int row, ItemStack icon) {
super(PSEUDO_PREFIX + key, col, row, original.getComplexity(), icon, new AspectList());
this.original = original;
setStub().setHidden();
}
@Override
public ResearchPage[] getPages() {
return original.getPages();
}
@Override
public String getName() {
return original.getName();
}
@Override
public String getText() {
return original.getText();
}
@Override
public boolean isHidden() {
EntityPlayer p = Minecraft.getMinecraft().thePlayer;
if(p != null) {
if(!ThaumcraftApiHelper.isResearchComplete(p.getCommandSenderName(), this.key)) {
return false;
}
}
return super.isHidden();
}
public static ResearchItem create(String original, int col, int row) {
ResearchItem item = ResearchCategories.getResearch(original);
if(item != null) {
ResearchItem pseudo;
if(item.icon_resource == null) {
pseudo = new PseudoResearchItem(item, item.key, col, row, item.icon_item);
} else {
pseudo = new PseudoResearchItem(item, item.key, col, row, item.icon_resource);
}
String[] siblings = item.siblings;
if(siblings == null) {
siblings = new String[]{ pseudo.key };
} else {
siblings = Arrays.copyOf(siblings, siblings.length + 1);
siblings[siblings.length - 1] = pseudo.key;
}
item.setSiblings(siblings);
if(item.isSecondary()) {
pseudo.setSecondary();
}
return pseudo.setParentsHidden(original);
}
return null;
}
}
@@ -0,0 +1,31 @@
package makeo.gadomancy.common.research;
import makeo.gadomancy.common.Gadomancy;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import thaumcraft.api.aspects.AspectList;
import thaumcraft.api.research.ResearchItem;
/**
* 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
*
* Created by makeo @ 15.06.2015 19:05
*/
public class SimpleResearchItem extends ResearchItem {
private static final String PREFIX = Gadomancy.MODID.toUpperCase() + ".";
public SimpleResearchItem(String key, int col, int row, int complex, ResourceLocation icon, AspectList tags) {
super(PREFIX + key, Gadomancy.MODID, tags, col, row, complex, icon);
}
public SimpleResearchItem(String key, int col, int row, int complex, ItemStack icon, AspectList tags) {
super(PREFIX + key, Gadomancy.MODID, tags, col, row, complex, icon);
}
public static String getFullName(String name) {
return PREFIX + name;
}
}
@@ -0,0 +1,40 @@
package makeo.gadomancy.common.utils;
import java.awt.*;
/**
* 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
*
* Created by makeo @ 13.07.2015 03:50
*/
public class ColorHelper {
public static final char COLOR_CHAR = '\u00a7';
private ColorHelper() {}
public static int toHex(int red, int green, int blue) {
return (red << 16) | (green << 8) | (blue);
}
public static int toHex(Color color) {
return toHex(color.getRed(), color.getGreen(), color.getBlue());
}
public static String extractColors(String input) {
StringBuilder output = new StringBuilder();
boolean isColor = false;
for(char c : input.toCharArray()) {
if(c == COLOR_CHAR) {
isColor = true;
} else if(isColor) {
isColor = false;
output.append(COLOR_CHAR).append(c);
}
}
return output.toString();
}
}
@@ -0,0 +1,196 @@
package makeo.gadomancy.common.utils;
import makeo.gadomancy.common.Gadomancy;
import makeo.gadomancy.api.GadomancyApi;
import makeo.gadomancy.api.golems.AdditionalGolemType;
import makeo.gadomancy.common.entities.golems.types.RemovedGolemType;
import net.minecraftforge.common.util.EnumHelper;
import thaumcraft.common.entities.golems.EnumGolemType;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* 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
*
* Created by makeo @ 29.07.2015 01:07
*/
public class GolemEnumHelper {
private static final RemovedGolemType REMOVED_GOLEM_TYPE = new RemovedGolemType();
private static final Injector INJECTOR = new Injector(EnumGolemType.class);
private static final Injector ENUM_INJECTOR = new Injector(Enum.class);
private static final Injector HELPER_INJECTOR = new Injector(EnumHelper.class);
private static Field valuesField = null;
private static Field getValuesField() {
if(valuesField == null) {
for(Field field : EnumGolemType.class.getDeclaredFields()) {
String name = field.getName();
if (name.equals("$VALUES") || name.equals("ENUM$VALUES")) //Added 'ENUM$VALUES' because Eclipse's internal compiler doesn't follow standards
{
valuesField = field;
valuesField.setAccessible(true);
break;
}
}
}
return valuesField;
}
private static final Class[] ENUM_PARAMS = {int.class, int.class, float.class, boolean.class, int.class,
int.class, int.class, int.class};
private static Field ordinalField = null;
public static Field getOrdinalField() {
if(ordinalField == null) {
try {
ordinalField = Enum.class.getDeclaredField("ordinal");
} catch (NoSuchFieldException ignored) { }
}
return ordinalField;
}
private static final Class[] MAKE_ENUM_PARAMS = new Class[]{ Class.class, String.class, int.class, Class[].class, Object[].class };
private static EnumGolemType createEnum(String name, int ordinal, AdditionalGolemType type) {
return HELPER_INJECTOR.invokeMethod("makeEnum", MAKE_ENUM_PARAMS,
EnumGolemType.class, name, ordinal, ENUM_PARAMS, new Object[]{ type.maxHealth, type.armor, type.movementSpeed,
type.fireResist, type.upgradeAmount, type.carryLimit, type.regenDelay, type.strength });
}
private static void addEnum(int ordinal, EnumGolemType type) {
EnumGolemType[] values = resizeValues(ordinal + 1);;
values[ordinal] = type;
}
private static EnumGolemType addEnum(String name, int ordinal, AdditionalGolemType type) {
EnumGolemType enumEntry = createEnum(name, ordinal, type);
addEnum(ordinal, enumEntry);
type.setEnumEntry(enumEntry);
return enumEntry;
}
private static EnumGolemType[] resizeValues(int size) {
EnumGolemType[] values = INJECTOR.getField(getValuesField());
if(size > values.length) {
EnumGolemType[] newValues = new EnumGolemType[size];
System.arraycopy(values, 0, newValues, 0, values.length);
for(int i = values.length; i < newValues.length; i++) {
newValues[i] = createEnum("REMOVED", i, REMOVED_GOLEM_TYPE);
}
setValues(newValues);
return newValues;
}
return values;
}
private static void setValues(EnumGolemType[] values) {
try {
EnumHelper.setFailsafeFieldValue(getValuesField(), null, values);
} catch (Exception ignored) { }
}
public static EnumGolemType addGolemType(String name, AdditionalGolemType type) {
return addEnum(name, getOrdinal(name), type);
}
private static int getOrdinal(String name) {
Map<String, Integer> map = getCurrentMapping();
if(map.containsKey(name)) {
return map.get(name);
}
int returnVal = -1;
int i = EnumGolemType.values().length;
do {
boolean contains = false;
for(Map.Entry<String, Integer> entry : map.entrySet()) {
if(entry.getValue() == i) {
contains = true;
}
}
if(!contains) {
returnVal = i;
}
i++;
} while (returnVal < 0);
map.put(name, returnVal);
saveCurrentMapping(map);
return returnVal;
}
public static void reorderEnum() {
reorderEnum(getCurrentMapping());
}
public static void reorderEnum(Map<String, Integer> mapping) {
EnumGolemType[] oldValues = EnumGolemType.values();
resetEnum();
for(Map.Entry<String, Integer> entry : mapping.entrySet()) {
for(EnumGolemType type : oldValues) {
if(type.name().equals(entry.getKey())) {
ENUM_INJECTOR.setObject(type);
ENUM_INJECTOR.setField(getOrdinalField(), entry.getValue());
addEnum(entry.getValue(), type);
}
}
}
}
private static void resetEnum() {
EnumGolemType[] newValues = Arrays.copyOfRange(EnumGolemType.values(), 0, calcDefaultGolemCount());
setValues(newValues);
}
private static int calcDefaultGolemCount() {
EnumGolemType[] values = EnumGolemType.values();
for(int i = 0; i < values.length; i++) {
if(GadomancyApi.isAdditionalGolemType(values[i])) {
return i;
}
}
return values.length;
}
public static void validateSavedMapping() {
if(hasCurrentMapping()) {
Map<String, Integer> mapping = getCurrentMapping();
for(Map.Entry<String, Integer> entry : defaultMapping.entrySet()) {
if(!mapping.containsKey(entry.getKey())) {
mapping.put(entry.getKey(), getOrdinal(entry.getKey()));
}
}
}
}
private static Map<String, Integer> defaultMapping = new HashMap<String, Integer>();
public static Map<String, Integer> getCurrentMapping() {
if(hasCurrentMapping()) {
return Gadomancy.getModData().get("GolemTypeMapping", new HashMap<String, Integer>());
} else if(Gadomancy.getModData() != null) {
Gadomancy.getModData().set("GolemTypeMapping", defaultMapping);
}
return defaultMapping;
}
public static boolean hasCurrentMapping() {
return Gadomancy.getModData() != null && Gadomancy.getModData().contains("GolemTypeMapping");
}
private static void saveCurrentMapping(Map<String, Integer> map) {
if(Gadomancy.getModData() != null) {
Gadomancy.getModData().set("GolemTypeMapping", map);
}
}
}
@@ -0,0 +1,235 @@
package makeo.gadomancy.common.utils;
import cpw.mods.fml.relauncher.ReflectionHelper;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Arrays;
/**
* 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
*
* Created by makeo @ 02.12.13 18:45
*/
public class Injector {
Class clazz;
Object object;
public Injector(Object object, Class clazz) {
this.object = object;
this.clazz = clazz;
}
public Injector() {
this(null, null);
}
public Injector(Object object) {
this(object, object.getClass());
}
public Injector(Class clazz) {
object = null;
this.clazz = clazz;
}
public Injector(String clazz) throws IllegalArgumentException {
this.object = null;
try {
this.clazz = Class.forName(clazz);
} catch (ClassNotFoundException e) {
throw new IllegalArgumentException("Class does not exist!");
}
}
public void setObjectClass(Class clazz) {
this.clazz = clazz;
}
public Class getObjectClass() {
return clazz;
}
public void setObject(Object object) {
this.object = object;
}
public Object getObject() {
return object;
}
public <T> T invokeConstructor(Object... params) {
return invokeConstructor(extractClasses(params), params);
}
public <T> T invokeConstructor(Class clazz, Object param) {
return invokeConstructor(new Class[]{clazz}, param);
}
public <T> T invokeConstructor(Class[] classes, Object... params) {
try {
Constructor constructor = clazz.getDeclaredConstructor(classes);
object = constructor.newInstance(params);
return (T) object;
} catch (Exception e) {//NoSuchMethodException | InvocationTargetException | InstantiationException | IllegalAccessException
e.printStackTrace();
}
return null;
}
public <T> T invokeMethod(String name, Object... params) {
return invokeMethod(name, extractClasses(params), params);
}
public <T> T invokeMethod(String name, Class clazz, Object param) {
return invokeMethod(name, new Class[]{clazz}, param);
}
public <T> T invokeMethod(String name, Class[] classes, Object... params) {
try {
Method method = clazz.getDeclaredMethod(name, classes);
return invokeMethod(method, params);
} catch (Exception e) {//NoSuchMethodException | ClassCastException
e.printStackTrace();
}
return null;
}
public <T> T invokeMethod(Method method, Object... params) {
try {
method.setAccessible(true);
Object result = method.invoke(object, params);
if(result != null)
return (T) result;
} catch (Exception e) {//InvocationTargetException | IllegalAccessException | ClassCastException
e.printStackTrace();
}
return null;
}
private Class[] extractClasses(Object... objects) {
Class[] classes = new Class[objects.length];
for(int i = 0; i < objects.length; i++)
classes[i] = objects[i].getClass();
return classes;
}
public boolean setField(String name, Object value) {
try {
return setField(clazz.getDeclaredField(name), value);
} catch (NoSuchFieldException e) {
e.printStackTrace();
}
return false;
}
public boolean setField(Field field, Object value) {
try {
if(Modifier.isFinal(field.getModifiers())) {
Field modifiers = Field.class.getDeclaredField("modifiers");
modifiers.setAccessible(true);
modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
}
field.setAccessible(true);
field.set(object, value);
return true;
} catch (Exception e) {//IllegalAccessException | NoSuchFieldException
e.printStackTrace();
return false;
}
}
public <T> T getField(String name) {
try {
return getField(clazz.getDeclaredField(name));
} catch (NoSuchFieldException e) {
e.printStackTrace();
}
return null;
}
public <T> T getField(Field field) {
try {
field.setAccessible(true);
Object result = field.get(object);
if(result != null)
return (T) result;
} catch (Exception e) {//IllegalAccessException | ClassCastException
e.printStackTrace();
}
return null;
}
public Method findMethod(Class returnType, Class... paramTypes) {
return findMethod(clazz, returnType, paramTypes);
}
public Field findField(Class type) {
return findField(clazz, type);
}
public static Method findMethod(Class clazz, Class returnType, Class[] paramTypes) {
for(Method m : clazz.getDeclaredMethods()) {
if(Arrays.equals(m.getParameterTypes(), paramTypes) && m.getReturnType().equals(returnType)) {
return m;
}
}
return null;
}
public static <E> Method findMethod(Class<? super E> clazz, String[] methodNames, Class<?>... methodTypes) {
return ReflectionHelper.findMethod(clazz, null, methodNames, methodTypes);
}
public static Field findField(Class clazz, String... names) {
return ReflectionHelper.findField(clazz, names);
}
public static Field findField(Class clazz, Class type) {
for(Field f : clazz.getDeclaredFields()) {
if(f.getType().equals(type)) {
return f;
}
}
return null;
}
public static Class getClass(String name) {
try {
return Class.forName(name);
} catch (ClassNotFoundException e) {
e.printStackTrace();
return null;
}
}
public static Method getMethod(String name, Class clazz, Class... classes) {
if(clazz == null)
return null;
try {
return clazz.getDeclaredMethod(name, classes);
} catch (NoSuchMethodException e) {
e.printStackTrace();
return null;
}
}
public static Method getMethod(String name, String clazz, Class... classes) {
return getMethod(name, Injector.getClass(clazz), classes);
}
public static Field getField(String name, Class clazz) {
try {
return clazz.getDeclaredField(name);
} catch (NoSuchFieldException e) {
e.printStackTrace();
return null;
}
}
}
@@ -0,0 +1,133 @@
package makeo.gadomancy.common.utils;
import makeo.gadomancy.common.Gadomancy;
import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagCompound;
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
*
* Created by makeo @ 05.07.2015 12:45
*/
public class NBTHelper {
private NBTHelper() {}
public static NBTTagCompound getPersistentData(Entity entity) {
return getPersistentData(entity.getEntityData());
}
public static NBTTagCompound getPersistentData(ItemStack item) {
return getPersistentData(getData(item));
}
public static NBTTagCompound getPersistentData(NBTTagCompound base) {
NBTTagCompound compound;
if(hasPersistentData(base)) {
compound = base.getCompoundTag(Gadomancy.MODID);
} else {
compound = new NBTTagCompound();
base.setTag(Gadomancy.MODID, compound);
}
return compound;
}
public static boolean hasPersistentData(Entity entity) {
return hasPersistentData(entity.getEntityData());
}
public static boolean hasPersistentData(ItemStack item) {
return item.getTagCompound() != null && hasPersistentData(item.getTagCompound());
}
public static boolean hasPersistentData(NBTTagCompound base) {
NBTBase modData = base.getTag(Gadomancy.MODID);
return modData != null && modData instanceof NBTTagCompound;
}
public static NBTTagCompound getData(ItemStack stack) {
NBTTagCompound compound = stack.getTagCompound();
if(compound == null) {
compound = new NBTTagCompound();
stack.setTagCompound(compound);
}
return compound;
}
public static void setStack(NBTTagCompound compound, String tag, ItemStack stack) {
NBTTagCompound stackCompound = new NBTTagCompound();
stack.writeToNBT(stackCompound);
compound.setTag(tag, stackCompound);
}
public static void setUUID(NBTTagCompound compound, String tag, UUID uuid) {
NBTTagCompound uuidComp = new NBTTagCompound();
uuidComp.setLong("mostSigBits", uuid.getMostSignificantBits());
uuidComp.setLong("leastSigBits", uuid.getLeastSignificantBits());
compound.setTag(tag, uuidComp);
}
public static ItemStack getStack(NBTTagCompound compound, String tag) {
return getStack(compound, tag, null);
}
public static UUID getUUID(NBTTagCompound compound, String tag) {
return getUUID(compound, tag, null);
}
//Get tags with default value
public static ItemStack getStack(NBTTagCompound compound, String tag, ItemStack defaultValue) {
if(compound.hasKey(tag)) {
return ItemStack.loadItemStackFromNBT(compound.getCompoundTag(tag));
}
return defaultValue;
}
public static UUID getUUID(NBTTagCompound compound, String tag, UUID defaultValue) {
if(compound.hasKey(tag)) {
NBTTagCompound uuidComp = compound.getCompoundTag(tag);
return new UUID(uuidComp.getLong("mostSigBits"), uuidComp.getLong("leastSigBits"));
}
return defaultValue;
}
public static boolean getBoolean(NBTTagCompound compound, String tag, boolean defaultValue) {
return compound.hasKey(tag) ? compound.getBoolean(tag) : defaultValue;
}
public static String getString(NBTTagCompound compound, String tag, String defaultValue) {
return compound.hasKey(tag) ? compound.getString(tag) : defaultValue;
}
public static int getInteger(NBTTagCompound compound, String tag, int defaultValue) {
return compound.hasKey(tag) ? compound.getInteger(tag) : defaultValue;
}
public static double getDouble(NBTTagCompound compound, String tag, double defaultValue) {
return compound.hasKey(tag) ? compound.getDouble(tag) : defaultValue;
}
public static float getFloat(NBTTagCompound compound, String tag, float defaultValue) {
return compound.hasKey(tag) ? compound.getFloat(tag) : defaultValue;
}
public static byte getByte(NBTTagCompound compound, String tag, byte defaultValue) {
return compound.hasKey(tag) ? compound.getByte(tag) : defaultValue;
}
public static short getShort(NBTTagCompound compound, String tag, short defaultValue) {
return compound.hasKey(tag) ? compound.getShort(tag) : defaultValue;
}
public static long getLong(NBTTagCompound compound, String tag, long defaultValue) {
return compound.hasKey(tag) ? compound.getLong(tag) : defaultValue;
}
}
@@ -0,0 +1,18 @@
package makeo.gadomancy.common.utils;
import makeo.gadomancy.common.Gadomancy;
import net.minecraft.util.ResourceLocation;
/**
* 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
*
* Created by makeo @ 21.05.2015 15:13
*/
public class SimpleResourceLocation extends ResourceLocation {
public SimpleResourceLocation(String file) {
super(Gadomancy.MODID.toLowerCase(), "textures/" + (file.startsWith("/") ? file.substring(1) : file));
}
}
Loaded 100 of 125 files, more files were not shown because too many files have changed in this diff. Show more