Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import net.minecraftforge.fml.relauncher.SideOnly;
import pl.pabilo8.immersiveintelligence.common.IILogger;
import pl.pabilo8.immersiveintelligence.common.util.IIStringUtil;
import pl.pabilo8.immersiveintelligence.common.util.item.IIItemUtils;
import pl.pabilo8.immersiveintelligence.common.util.multiblock.production.TileEntityMultiblockProductionBase.IIIMultiblockRecipe;

import javax.annotation.Nonnull;
Expand Down Expand Up @@ -53,7 +54,7 @@ public static String generateRecipeName(Object nameSource, Object... nameSources
//IngredientStacks don't have a custom toString method, but NBT does
.map(o -> {
if(o instanceof ItemStack)
return o+"_"+((ItemStack)o).getCount();
return IIItemUtils.getUniqueStackString(((ItemStack)o));
if(o instanceof IngredientStack)
return createIngredientStackName(((IngredientStack)o));
if(o instanceof FluidStack)
Expand Down Expand Up @@ -83,12 +84,12 @@ else if(stack.stackList!=null)
{
if(!first)
sb.append("_");
sb.append(contained);
sb.append(IIItemUtils.getUniqueStackString(contained));
first = false;
}
}
else
sb.append(stack.stack);
sb.append(IIItemUtils.getUniqueStackString(stack.stack));
sb.append("_").append(stack.inputSize);

return sb.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import pl.pabilo8.immersiveintelligence.api.data.types.generic.DataType;
import pl.pabilo8.immersiveintelligence.common.util.item.IIItemUtils;

import javax.annotation.Nonnull;

Expand Down Expand Up @@ -57,10 +58,6 @@ public boolean equals(Object obj)
@Override
public String toString()
{
return String.format("%d*%s@%d%s",
value.getCount(),
value.getItem().getRegistryName(),
value.getMetadata(),
value.hasTagCompound()?value.getTagCompound().toString(): "");
return IIItemUtils.getUniqueStackString(value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ public NBTTagCompound valueToNBT()
NBTTagCompound nbt = getHeaderTag();

nbt.setFloat("X", x);
nbt.setFloat("Y", x);
nbt.setFloat("Z", x);
nbt.setFloat("Y", y);
nbt.setFloat("Z", z);
nbt.setBoolean("IntegerVector", integerVector);

return nbt;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void onParticleRender(AbstractParticle particle, float partialTicks)
public void onParticleRender(AbstractParticle particle, float partialTicks)
{
int textures = (int)particle.getProperty(ParticleProperties.TEXTURES_COUNT);
particle.setProperty(ParticleProperties.TEXTURE_SHIFT, (int)(particle.getProgress(partialTicks)*textures));
particle.setProperty(ParticleProperties.TEXTURE_SHIFT, (int)MathHelper.clamp(particle.getProgress(partialTicks)*textures, 0, textures));
}
});
ParticleRegistry.registerProgram(() -> new ParticleProgram("retexture")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,6 @@ public void onInit()
new DecoBar(176-8-8-2, -2)
.withTemplate(DecoTemplates.BAR_ELECTRIC_ENERGY.apply(tile.energyStorage)),

imageProgress1 = new DecoImage(20-4, 5+18-4+24+2+2)
.withSize(19, 12)
.withImageLocation(TEXTURE, true)
.withUV(128, 0, 80, 19, 80+12),
imageProgress2 = new DecoImage(120-4+18-2-1, 5+18-4+24+2+2)
.withSize(21, 12)
.withImageLocation(TEXTURE, true)
.withUV(128, 19, 80, 19+21, 80+12),
new DecoImage(20-4, 5+18-4+24+2+2)
.withSize(19, 12)
.withImageLocation(TEXTURE, true)
Expand All @@ -76,6 +68,16 @@ public void onInit()
.withSize(106, 36)
.withImageLocation(TEXTURE, true)
.withUV(128, 0, 32, 106, 32+36)
.withDisabled(true),

imageProgress1 = new DecoImage(20-4, 5+18-4+24+2+2)
.withSize(19, 12)
.withImageLocation(TEXTURE, true)
.withUV(128, 0, 80, 19, 80+12),
imageProgress2 = new DecoImage(120-4+18-2-1, 5+18-4+24+2+2)
.withSize(21, 12)
.withImageLocation(TEXTURE, true)
.withUV(128, 19, 80, 19+21, 80+12)

);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.NonNullList;
import net.minecraft.util.text.TextFormatting;
import pl.pabilo8.immersiveintelligence.api.data.DataPacket;
import pl.pabilo8.immersiveintelligence.api.data.DataVariable;
import pl.pabilo8.immersiveintelligence.api.data.IDataMachineGui;
import pl.pabilo8.immersiveintelligence.api.data.types.DataTypeInteger;
import pl.pabilo8.immersiveintelligence.api.data.types.DataTypeExpression;
import pl.pabilo8.immersiveintelligence.api.data.types.DataTypeNull;
import pl.pabilo8.immersiveintelligence.api.data.types.generic.DataType;
import pl.pabilo8.immersiveintelligence.api.data.types.generic.DataType.TypeMetaInfo;
Expand All @@ -34,9 +35,9 @@
import pl.pabilo8.immersiveintelligence.common.network.messages.MessageIITileSync;
import pl.pabilo8.immersiveintelligence.common.util.IIColor;
import pl.pabilo8.immersiveintelligence.common.util.IIReference;
import pl.pabilo8.immersiveintelligence.common.util.easynbt.EasyNBT;
import pl.pabilo8.immersiveintelligence.common.util.easynbt.SyncNBT;

import javax.annotation.Nullable;
import pl.pabilo8.immersiveintelligence.common.util.easynbt.SyncNBT.SyncEvents;

/**
* @author Pabilo8 (pabilo@iiteam.net)
Expand All @@ -47,16 +48,15 @@
@DecoTemplate(name = "arithmetic_logic_machine", category = DecoGuiCategory.DATA_TILE)
public class GuiArithmeticLogicMachine extends DecoTileGui<TileEntityArithmeticLogicMachine, ContainerArithmeticLogicMachine> implements IDataMachineGui
{
@SyncNBT
@SyncNBT(name = "page", events = SyncEvents.TILE_CLIENT_MESSAGE)
public int editedCircuit = 0;
@SyncNBT
public int scroll = 0;
public DataPacket expressions = new DataPacket();
@SyncNBT
public DataVariable variableToEdit = new DataVariable('a', new DataTypeNull());

@Nullable
protected DecoList<DataVariable> list;
boolean isStorage;
private boolean isStorage;
private int displayedCircuit = 0;

private GuiArithmeticLogicMachine(EntityPlayer player, TileEntityArithmeticLogicMachine tile, IIGUI gui)
{
Expand All @@ -78,8 +78,8 @@ public static GuiArithmeticLogicMachine getVariablesGui(EntityPlayer player, Til
@Override
public void onInit()
{
syncAnimatedParts(tile.door, true);
syncAnimatedParts(tile.drawer, true);
syncAnimatedParts(tile.door, !isStorage);
syncAnimatedParts(tile.drawer, isStorage);
syncAnimatedParts(tile.keyboard, false);

//Refresh page when circuit slots change
Expand Down Expand Up @@ -123,8 +123,9 @@ public void onInit()
}
else if(tile.inventory.size() > editedCircuit)
{
ItemStack stack = tile.inventory.get(editedCircuit);
DataPacket storedData = IIContent.itemCircuit.getStoredData(stack);
displayedCircuit = editedCircuit;
ItemStack stack = tile.inventory.get(displayedCircuit);
this.expressions = IIContent.itemCircuit.getStoredData(stack);

addLabel(stack.getDisplayName(), 4+2+16, 8)
.withTextColor(DecoColors.H2)
Expand All @@ -139,10 +140,10 @@ else if(tile.inventory.size() > editedCircuit)
.withSize(16, 16)
);

list = addComponent(
addComponent(
new DecoList<DataVariable>(4+1, 8+16+2)
.withSize(136+32-3, 120-16)
.withEntries(storedData.getAllVariables())
.withEntries(expressions.getAllVariables())
.withCreateLaterAction(this::addVariable)
.withGuiSaveAction(gui -> this.scroll = gui.getScroll())
//Display
Expand All @@ -158,19 +159,22 @@ else if(tile.inventory.size() > editedCircuit)
char name = findNextFreeVariableName();
if(name=='\0')
return;
editVariable(name, current.getValue());
editVariable(name, current.getValue().clone());
})
)
.withComponent(p -> new DecoButton(p.width-17-16+3, 2)
.withTemplate(DecoTemplates.ACTION_BUTTON_EDIT)
.withOnLMBPressed(() -> {
editVariable(p.getCurrentElement());
expressions.remove(p.getCurrentElement().getName());
})
)
.withComponent(p -> new DecoButton(p.width-17+1, 2)
.withTemplate(DecoTemplates.ACTION_BUTTON_REMOVE)
.withOnLMBPressed(() -> {
p.getCurrentList().removeEntry(p.getCurrentElement());
DataVariable current = p.getCurrentElement();
p.getCurrentList().removeEntry(current);
expressions.remove(current.getName());
IIPacketHandler.sendToServer(new MessageIITileSync(tile, onSaveTileData()));
})
)
Expand Down Expand Up @@ -208,18 +212,10 @@ else if(tile.inventory.size() > editedCircuit)
}

//Storage page tab
addComponent(new DecoTab()
.withLink(IIGUI.ARITHMETIC_LOGIC_MACHINE_STORAGE)
.withIcon(DecoTextures.ICON_STORAGE)
.withTranslatedTooltip(IIReference.DESCRIPTION_KEY+"storage_module")
);
addLinkTab(IIGUI.ARITHMETIC_LOGIC_MACHINE_STORAGE, DecoTextures.ICON_STORAGE, "storage_module");

if(tile.isUpgradeInstalled(IIContent.UPGRADE_MEMORY))
addComponent(new DecoTab()
.withLink(IIGUI.ARITHMETIC_LOGIC_MACHINE_STORAGE)
.withIcon(DecoTextures.ICON_MEMORY)
.withTranslatedTooltip(IIReference.DESCRIPTION_KEY+"memory_in_module")
);
addLinkTab(IIGUI.ARITHMETIC_LOGIC_MACHINE_MEMORY_IN, DecoTextures.ICON_MEMORY, "memory_in_module");

//Circuit tabs
NonNullList<ItemStack> inventory = tile.inventory;
Expand All @@ -242,11 +238,7 @@ else if(tile.inventory.size() > editedCircuit)
}

if(tile.isUpgradeInstalled(IIContent.UPGRADE_MEMORY))
addComponent(new DecoTab()
.withLink(IIGUI.ARITHMETIC_LOGIC_MACHINE_STORAGE)
.withIcon(DecoTextures.ICON_MEMORY)
.withTranslatedTooltip(IIReference.DESCRIPTION_KEY+"memory_out_module")
);
addLinkTab(IIGUI.ARITHMETIC_LOGIC_MACHINE_MEMORY_OUT, DecoTextures.ICON_MEMORY, "memory_out_module");
}

@Override
Expand All @@ -263,40 +255,72 @@ public void onGuiClosed()

private DataPacket getCircuitPacket()
{
if(tile.inventory.size() <= editedCircuit)
if(tile.inventory.size() <= displayedCircuit)
return new DataPacket();

ItemStack stack = tile.inventory.get(editedCircuit);
ItemStack stack = tile.inventory.get(displayedCircuit);
return IIContent.itemCircuit.getStoredData(stack);
}

private void updateLocalCircuitStack(int circuit, DataPacket packet)
{
if(tile.getInventory().size() <= circuit)
return;
ItemStack stack = tile.getInventory().get(circuit);
if(stack.isEmpty()||!(stack.getItem() instanceof ItemIIFunctionalCircuit))
return;
((ItemIIFunctionalCircuit)stack.getItem()).writeDataToItem(stack, packet);
tile.getInventory().set(circuit, stack);
}

private NBTTagCompound getExpressionsTag(int circuit, DataPacket packet)
{
return EasyNBT.newNBT()
.withInt("page", circuit)
.withSerializable("list", packet)
.unwrap();
}

private char findNextFreeVariableName()
{
if(list==null)
return '\0';
DataPacket currentPacket = new DataPacket(list.getEntries());
if(currentPacket.size() >= DataPacket.VARIABLE_NAMES.length)
if(expressions.size() >= DataPacket.VARIABLE_NAMES.length)
return '\0';
return IIUtils.cycleDataPacketCharsAvoiding('a', true, false, currentPacket);
return IIUtils.cycleDataPacketCharsAvoiding('0', true, false, expressions);
}

private void addVariable()
{
char name = findNextFreeVariableName();
if(name=='\0')
return;
editVariable(name, new DataTypeInteger());
editVariable(name, new DataTypeExpression());
}

private void editExistingVariable(DataVariable variable)
{
expressions.remove(variable.getName());
this.variableToEdit = variable;
changeGUI(IIGUI.ARITHMETIC_LOGIC_MACHINE_EDIT);
}

@Override
public void editVariable(char name, DataType initialValue)
protected EasyNBT onSaveTileData()
{
DataPacket currentPacket = list==null?getCircuitPacket(): new DataPacket(list.getEntries());
EasyNBT nbt = super.onSaveTileData();
if(isStorage||tile.inventory.size() <= displayedCircuit)
return nbt;

updateLocalCircuitStack(displayedCircuit, expressions);
return nbt.withTag("expressions", getExpressionsTag(displayedCircuit, expressions));
}

if(!currentPacket.has(name)||currentPacket.get(name).getClass()!=initialValue.getClass())
currentPacket.set(name, initialValue);
@Override
public void editVariable(char name, DataType initialValue)
{
if(!expressions.has(name)||expressions.get(name).getClass()!=initialValue.getClass())
expressions.set(name, initialValue);

this.variableToEdit = new DataVariable(name, initialValue);
this.variableToEdit = new DataVariable(name, initialValue.clone());
changeGUI(IIGUI.ARITHMETIC_LOGIC_MACHINE_EDIT);
}
}
Loading
Loading