Skip to content

Commit

Permalink
Merge pull request #33 from Mordenkainen/0.4_Dev
Browse files Browse the repository at this point in the history
0.4 dev
  • Loading branch information
Mordenkainen committed Aug 9, 2015
2 parents 33511b7 + 8438b55 commit 6c3582e
Show file tree
Hide file tree
Showing 13 changed files with 163 additions and 201 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ buildscript {

apply plugin: 'forge'

version = "0.3"
version = "0.4"
group= "com.mordenkainen.equivalentenergistics" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "EquivalentEnergistics"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import cpw.mods.fml.common.event.FMLInterModComms;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.event.FMLServerStartingEvent;
import cpw.mods.fml.common.registry.GameRegistry;

import com.mordenkainen.equivalentenergistics.blocks.BlockEMCCondenser;
Expand All @@ -38,7 +37,6 @@
import com.mordenkainen.equivalentenergistics.tiles.TileEMCCrafter;
import com.mordenkainen.equivalentenergistics.util.EMCUtils;
import com.mordenkainen.equivalentenergistics.util.EventHandlerModule;
import com.mordenkainen.equivalentenergistics.util.TransmutationNbt;

@Mod(modid = Ref.MOD_ID, name = Ref.MOD_NAME, version = Ref.MOD_VERSION, dependencies = Ref.MOD_DEPENDENCIES)
public class EquivalentEnergistics {
Expand All @@ -59,20 +57,6 @@ public class EquivalentEnergistics {

public static Block blockEMCCondenser;
public static Block blockEMCCrafter;

public static TransmutationNbt transmutations;

@EventHandler
public void onServerStarting(FMLServerStartingEvent event) {
MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
WorldServer worldServer = server.worldServers[0];

transmutations = (TransmutationNbt)worldServer.mapStorage.loadData(TransmutationNbt.class, "PETransmutations");
if (transmutations == null) {
transmutations = new TransmutationNbt("PETransmutations");
worldServer.mapStorage.setData("PETransmutations", transmutations);
}
}

@EventHandler
public void preInit(FMLPreInitializationEvent event) {
Expand All @@ -82,6 +66,10 @@ public void preInit(FMLPreInitializationEvent event) {

@EventHandler
public void init(FMLInitializationEvent event) {
//if(!Loader.isModLoaded("ProjectE") && !Loader.isModLoaded("EE3")) {
proxy.unmetDependency();
//}

itemEMCCrystal = new ItemEMCCrystal();
GameRegistry.registerItem(itemEMCCrystal, "EMCCrystal");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

import com.mordenkainen.equivalentenergistics.EquivalentEnergistics;
import com.mordenkainen.equivalentenergistics.lib.Ref;
import com.mordenkainen.equivalentenergistics.util.TransmutationNbt;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import moze_intel.projecte.api.ProjectEAPI;
import moze_intel.projecte.playerData.Transmutation;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.Entity;
Expand Down Expand Up @@ -65,55 +65,10 @@ public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer pla
}
stackNBT.setString("Owner", player.getCommandSenderName());
stackNBT.setString("OwnerUUID", playerUUID);
ArrayList<ItemStack> currentTransmutations = TransmutationNbt.getPlayerKnowledge(stackNBT.getString("OwnerUUID"));
ArrayList<ItemStack> newTransmutations = getPlayerKnowledge(player);
boolean result = new HashSet(currentTransmutations).equals(new HashSet(newTransmutations));
if(!result) {
TransmutationNbt.setPlayerKnowledge(playerUUID, newTransmutations);
EquivalentEnergistics.transmutations.markDirty();
}
player.addChatComponentMessage(new ChatComponentText(StatCollector.translateToLocal("message.book.link")));
}
return stack;
}

private ArrayList<ItemStack> getPlayerKnowledge(EntityPlayer player) {
int methodType = 2;
Method gkMethod = null;
List<ItemStack> tmpTransmutations = null;
ArrayList<ItemStack> transmutations = new ArrayList<ItemStack>();

try {
gkMethod = Transmutation.class.getDeclaredMethod("getKnowledge", new Class[] {String.class});
methodType = 0;
} catch (Exception e) {
try {
gkMethod = Transmutation.class.getDeclaredMethod("getKnowledge", new Class[] {EntityPlayer.class});
methodType = 1;
} catch (Exception e1) {}
}

try {
switch(methodType){
case 0:
tmpTransmutations = (List<ItemStack>) gkMethod.invoke(null, new Object[] {player.getCommandSenderName()});
break;
case 1:
tmpTransmutations = (List<ItemStack>) gkMethod.invoke(null, new Object[] {player});
break;
}
} catch (Exception e) {}

if(tmpTransmutations != null) {
for(ItemStack currentItem : tmpTransmutations) {
if(currentItem.getItem() != EquivalentEnergistics.itemEMCCrystal) {
transmutations.add(currentItem);
}
}
}

return transmutations;
}

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

public final class Ref {
public static final String MOD_ID = "equivalentenergistics";
public static final String MOD_VERSION = "0.3";
public static final String MOD_VERSION = "0.4";
public static final String MOD_NAME = "Equivalent Energistics";
public static final String MOD_DEPENDENCIES = "required-after:appliedenergistics2;after:EE3;after:ProjectE";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.mordenkainen.equivalentenergistics.render.BlockEMCCrafterRenderer;
import com.mordenkainen.equivalentenergistics.render.TileEMCCrafterRenderer;
import com.mordenkainen.equivalentenergistics.tiles.TileEMCCrafter;
import com.mordenkainen.equivalentenergistics.util.UnmetDependencyException;

import cpw.mods.fml.client.registry.ClientRegistry;
import cpw.mods.fml.client.registry.RenderingRegistry;
Expand All @@ -13,4 +14,8 @@ public void initRenderers() {
EMCCrafterRenderer = RenderingRegistry.getNextAvailableRenderId();
RenderingRegistry.registerBlockHandler(new BlockEMCCrafterRenderer());
}

public void unmetDependency() {
throw new UnmetDependencyException();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ public class CommonProxy {
public int EMCCrafterRenderer;

public void initRenderers() {}

public void unmetDependency() {
throw new RuntimeException("Equivalent Energistics requires either Equivalent Exchange 3 or ProjectE to be installed!");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ public void onTick() {
try {
for(int i = 0; i < SLOT_COUNT; i++) {
if(internalInventory.getStackInSlot(i) != null){
if(EMCUtils.getInstance().hasEMC(internalInventory.getStackInSlot(i))) {
ItemStack testItem = internalInventory.getStackInSlot(i).copy();
testItem.stackSize = 1;
ItemStack testItem = internalInventory.getStackInSlot(i).copy();
testItem.stackSize = 1;
if(EMCUtils.getInstance().hasEMC(testItem) && EMCUtils.getInstance().getEnergyValue(testItem) > 0) {
float itemEMC = EMCUtils.getInstance().getEnergyValue(testItem);
int itemAvail = Math.min(ConfigManager.itemsPerTick, Math.min(internalInventory.getStackInSlot(i).stackSize, (int)Math.floor((Float.MAX_VALUE - currentEMC) / itemEMC)));
internalInventory.decrStackSize(i, itemAvail);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,16 +173,7 @@ public void setCurrentTome(ItemStack heldItem) {

public void playerKnowledgeChange(UUID playerUUID) {
if(currentTome != null) {
UUID tomeUUID = ItemHelper.getOwnerUUID(currentTome);
if(tomeUUID.equals(playerUUID)) {
stalePatterns = true;
}
}
}

public void playerKnowledgeChange(String playerUUID) {
if(currentTome != null) {
String tomeUUID = currentTome.getTagCompound().getString("OwnerUUID");
UUID tomeUUID = EMCUtils.getInstance().getTomeUUID(currentTome);
if(tomeUUID.equals(playerUUID)) {
stalePatterns = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,56 +16,93 @@ public EMCCraftingPattern(final ItemStack craftingResult) {
}

private void calculateContent(ItemStack craftingResult) {
if(!EMCUtils.getInstance().hasEMC(craftingResult)) {
if(!EMCUtils.getInstance().hasEMC(craftingResult) || EMCUtils.getInstance().getEnergyValue(craftingResult) <= 0) {
valid = false;
} else {
float outputEMC = EMCUtils.getInstance().getEnergyValue(craftingResult);
float crystalEMC = EMCUtils.getInstance().getCrystalEMC();
int tier0CrystalCount, tier1CrystalCount, tier2CrystalCount, itemCount;
tier1CrystalCount = tier2CrystalCount = 0;
if(outputEMC <= crystalEMC) {
tier0CrystalCount = 1;
itemCount = (int)Math.min(crystalEMC/outputEMC, 64);
float inputEMC = 0;
int numItems = 1;
int[] crystals = new int[] {0, 0, 0};
if(outputEMC <= EMCUtils.getInstance().getCrystalEMC()) {
crystals[0] = 1;
numItems = (int)Math.min(EMCUtils.getInstance().getCrystalEMC()/outputEMC, 64);
outputEMC *= numItems;
inputEMC = EMCUtils.getInstance().getCrystalEMC();
} else {
itemCount = 1;
tier0CrystalCount = (int)Math.ceil(outputEMC/crystalEMC);
int maxTier = calcStartingTier(outputEMC);
float remainingEMC = outputEMC;
for(int i = maxTier; i >= 0; i--) {
crystals[i] = calcCrystals(remainingEMC, i);
remainingEMC = getOverflow(outputEMC, crystals);
if(remainingEMC <= 0) {
break;
}
if(i != 0 ) {
crystals[i]--;
remainingEMC = Math.abs(remainingEMC - EMCUtils.getInstance().getCrystalEMC(i));
}
}
int pass = 0;
while(getTotalStacks(crystals) > 9 && pass < 2) {
if(crystals[pass] > 0) {
crystals[pass] = 0;
crystals[pass + 1]++;
}
pass++;
}
if(getTotalStacks(crystals) > 9) {
valid = false;
return;
}
for(int i = 0; i <= 2; i++) {
inputEMC += EMCUtils.getInstance().getCrystalEMC(i) * crystals[i];
}
}
this.outputEMC = outputEMC * itemCount;

ItemStack outputStack = craftingResult.copy();
outputStack.stackSize = itemCount;
outputStack.stackSize = numItems;
result = AEApi.instance().storage().createItemStack(outputStack);

if(tier0CrystalCount >= Math.pow(576, 2)) {
int numCrystals = (int)Math.floor(tier0CrystalCount/Math.pow(576, 2));
tier2CrystalCount = numCrystals;
tier0CrystalCount -= numCrystals * Math.pow(576, 2);
}
if(tier0CrystalCount >= 576) {
int numCrystals = (int)Math.floor(tier0CrystalCount/576);
tier1CrystalCount = numCrystals;
tier0CrystalCount -= numCrystals * 576;
}
if(getStackCount(tier0CrystalCount) + getStackCount(tier1CrystalCount) + getStackCount(tier2CrystalCount) > 9) {
tier1CrystalCount++;
tier0CrystalCount=0;
}
inputEMC = crystalEMC * tier0CrystalCount + EMCUtils.getInstance().getCrystalEMC(1) * tier1CrystalCount + EMCUtils.getInstance().getCrystalEMC(2) * tier2CrystalCount;

int lastItem = 0;
while(tier0CrystalCount > 0) {
ingredients[lastItem++] = AEApi.instance().storage().createItemStack(new ItemStack(EquivalentEnergistics.itemEMCCrystal, Math.min(64, tier0CrystalCount), 0));
tier0CrystalCount -= Math.min(64, tier0CrystalCount);
}
while(tier1CrystalCount > 0) {
ingredients[lastItem++] = AEApi.instance().storage().createItemStack(new ItemStack(EquivalentEnergistics.itemEMCCrystal, Math.min(64, tier1CrystalCount), 1));
tier1CrystalCount -= Math.min(64, tier1CrystalCount);
}
while(tier2CrystalCount > 0) {
ingredients[lastItem++] = AEApi.instance().storage().createItemStack(new ItemStack(EquivalentEnergistics.itemEMCCrystal, Math.min(64, tier2CrystalCount), 2));
tier2CrystalCount -= Math.min(64, tier2CrystalCount);
int tier = 0;
for (int i = 0; i <= 8 && tier <= 2 && (crystals[0] > 0 || crystals[1] > 0 || crystals[2] > 0); i++) {
while (crystals[tier] <= 0) {
tier++;
}
ingredients[i] = AEApi.instance().storage().createItemStack(new ItemStack(EquivalentEnergistics.itemEMCCrystal, Math.min(64, crystals[tier]), tier));
crystals[tier] -= ingredients[i].getItemStack().stackSize;
}
}
}

private int calcStartingTier(float emcValue) {
if(emcValue > EMCUtils.getInstance().getCrystalEMC(2)) {
return 2;
}
if(emcValue > EMCUtils.getInstance().getCrystalEMC(1)) {
return 1;
}
return 0;
}

private int calcCrystals(float emcValue, int tier) {
return (int)Math.ceil(emcValue / EMCUtils.getInstance().getCrystalEMC(tier));
}

private float getOverflow(float targetEMC, int[]crystals) {
float crystalEMC = 0;
for(int i = 0; i <= 2; i++) {
crystalEMC += EMCUtils.getInstance().getCrystalEMC(i) * crystals[i];
}
return crystalEMC - targetEMC;
}

private int getTotalStacks(int[]crystals) {
int totalStacks = 0;
for(int i = 0; i <= 2; i++) {
totalStacks += getStackCount(crystals[i]);
}
return totalStacks;
}

private int getStackCount(int numCrystals) {
if(numCrystals > 0 && numCrystals < 64) {
Expand Down
Loading

0 comments on commit 6c3582e

Please sign in to comment.