Skip to content

Commit

Permalink
1.3.9 Upgrade
Browse files Browse the repository at this point in the history
Added blocking mode to Crafting Manager Pipe
Fixed crash with Bridge Pipe #33
Fixed crash with Crafting Manager Gui
Improved tooltips
Fixes #32
Fixes #31
  • Loading branch information
tom5454 committed Aug 2, 2020
1 parent 8d2c34f commit 3dc8449
Show file tree
Hide file tree
Showing 9 changed files with 312 additions and 76 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ dependencies {
compileOnly group: 'cofh', name: 'ThermalDynamics', version: '1.12.2-2.5.5.21', classifier: 'deobf', transitive: false
compileOnly group: 'refinedstorage', name: 'refinedstorage', version: '1.6.16-386', transitive: false
compileOnly group: 'codechicken', name: 'NotEnoughItems', version: '1.12.2-2.4.3.245', classifier: 'deobf', transitive: false
compileOnly group: 'appeng', name: 'appliedenergistics2', version: 'rv6-stable-7', classifier: 'deobf', transitive: false
compileOnly group: 'appeng', name: 'appliedenergistics2', version: 'rv6-stable-7', transitive: false
}

tasks.withType(Wrapper) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/tom/logisticsbridge/LogisticsBridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
public class LogisticsBridge {
public static final String ID = "logisticsbridge";
public static final String NAME = "Logistics Bridge";
public static final String VERSION = "1.3.8";
public static final String VERSION = "1.3.9";
public static final String DEPS = "after:appliedenergistics2;after:refinedstorage@[1.6.15,);required-after:logisticspipes@[0.10.3.39,)";
public static final String UPDATE = "https://github.com/tom5454/LogisticsBridge/blob/master/version-check.json";
public static final Logger log = LogManager.getLogger(NAME);
Expand Down
42 changes: 40 additions & 2 deletions src/main/java/com/tom/logisticsbridge/gui/GuiCraftingManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import net.minecraft.client.renderer.RenderItem;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.inventory.ClickType;
import net.minecraft.inventory.InventoryBasic;
import net.minecraft.inventory.Slot;
Expand All @@ -27,6 +28,7 @@
import com.tom.logisticsbridge.inventory.ContainerCraftingManager;
import com.tom.logisticsbridge.inventory.ContainerCraftingManager.SlotCraftingCard;
import com.tom.logisticsbridge.pipe.CraftingManager;
import com.tom.logisticsbridge.pipe.CraftingManager.BlockingMode;

import logisticspipes.LPItems;
import logisticspipes.modules.LogisticsModule;
Expand Down Expand Up @@ -192,6 +194,28 @@ public void initGui() {
ce = new ConfigExtention(StringUtils.translate("gui.craftingManager.result"), new ItemStack(LogisticsBridge.pipeResult), 1);
ce.registerButton(extentionControllerLeft.registerControlledButton(addButton(new SmallGuiButton(2, guiLeft - 45, guiTop + 25, 40, 10, select))));
extentionControllerLeft.addExtention(ce);

if(pipe.getBlockingMode() != BlockingMode.NULL) {
ce = new ConfigExtention(StringUtils.translate("gui.craftingManager.blocking"), new ItemStack(Blocks.BARRIER), 2) {

@Override
public String getString() {
return StringUtils.translate("gui.craftingManager.blocking." + pipe.getBlockingMode().name().toLowerCase());
}

@Override
public int textOff() {
return 70;
}

@Override
public int getFinalWidth() {
return 140;
}
};
ce.registerButton(extentionControllerLeft.registerControlledButton(addButton(new SmallGuiButton(4, guiLeft - 45, guiTop + 11, 40, 10, StringUtils.translate("gui.craftingManager.blocking.change")))));
extentionControllerLeft.addExtention(ce);
}
}
@Override
protected void actionPerformed(GuiButton button) throws IOException {
Expand All @@ -202,6 +226,12 @@ protected void actionPerformed(GuiButton button) throws IOException {
case 2:
openSubGuiForSatelliteSelection(1);
return;

case 4:
BlockingMode m = BlockingMode.VALUES[(pipe.getBlockingMode().ordinal() + 1) % BlockingMode.VALUES.length];
if(m == BlockingMode.NULL)m = BlockingMode.OFF;
pipe.setPipeID(2, Integer.toString(m.ordinal()), null);
return;
}
}
public RenderItem renderItem() {
Expand Down Expand Up @@ -231,7 +261,7 @@ public int getFinalHeight() {

@Override
public void renderForground(int left, int top) {
String pid = pipe.getPipeID(id);
String pid = getString();
if (!isFullyExtended()) {
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240 / 1.0F, 240 / 1.0F);
Expand All @@ -248,10 +278,18 @@ public void renderForground(int left, int top) {
if (pid == null || pid.isEmpty()) {
mc.fontRenderer.drawString(StringUtils.translate("gui.craftingManager.noConnection"), left + 40, top + 22, 0x404040);
} else {
mc.fontRenderer.drawString(pid, left + 40 - mc.fontRenderer.getStringWidth(pid)/2, top + 22, 0x404040);
mc.fontRenderer.drawString(pid, left + textOff() - mc.fontRenderer.getStringWidth(pid)/2, top + 22, 0x404040);
}
}
}

public String getString() {
return pipe.getPipeID(id);
}

public int textOff() {
return 40;
}
}
private void openSubGuiForSatelliteSelection(int id) {
this.setSubGui(new GuiSelectIDPopup(new BlockPos(this.pipe.getX(), this.pipe.getY(), this.pipe.getZ()), id, 0,
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/com/tom/logisticsbridge/module/ModuleCrafterExt.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
import logisticspipes.interfaces.routing.IFilter;
import logisticspipes.interfaces.routing.IRequestFluid;
import logisticspipes.interfaces.routing.IRequestItems;
import logisticspipes.modules.ChassiModule;
import logisticspipes.modules.ModuleCrafter;
import logisticspipes.pipes.basic.CoreRoutedPipe;
import logisticspipes.proxy.MainProxy;
import logisticspipes.proxy.SimpleServiceLocator;
import logisticspipes.request.DictCraftingTemplate;
import logisticspipes.request.ICraftingTemplate;
Expand Down Expand Up @@ -326,6 +328,22 @@ public void enabledUpdateEntity() {
return;
}
}

@Override
public void guiClosedByPlayer(EntityPlayer player) {
super.guiClosedByPlayer(player);
if(MainProxy.isClient(_world.getWorld()))return;
if(!(_service instanceof CraftingManager))return;
CraftingManager mngr = (CraftingManager) _service;
ChassiModule m = mngr.getModules();
for(int i = 0;i<27;i++) {
if(m.getModule(i) == this) {
mngr.save(i);
break;
}
}
}

public static class BufferInformation extends CraftingChassieInformation {

public BufferInformation(int craftingSlot, int moduleSlot) {
Expand Down
114 changes: 65 additions & 49 deletions src/main/java/com/tom/logisticsbridge/pipe/BridgePipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumFacing.Axis;
import net.minecraft.util.text.TextComponentTranslation;

import com.tom.logisticsbridge.LogisticsBridge;
Expand Down Expand Up @@ -485,14 +486,14 @@ public List<ItemIdentifierStack> getCraftedItems() {
collect(Collectors.toList());
}
public class Req {
private boolean gettingProvItems;
private boolean alreadyProcessing;
public List<ItemStack> getProvidedItems() {
if(gettingProvItems || !isEnabled())return Collections.emptyList();
if(alreadyProcessing || !isEnabled())return Collections.emptyList();
if (stillNeedReplace()) {
return new ArrayList<>();
}
try {
gettingProvItems = true;
alreadyProcessing = true;
IRouter myRouter = getRouter();
List<ExitRoute> exits = new ArrayList<>(myRouter.getIRoutersByCost());
exits.removeIf(e -> e.destination == myRouter);
Expand All @@ -504,72 +505,82 @@ public List<ItemStack> getProvidedItems() {
}
return list;
} finally {
gettingProvItems = false;
alreadyProcessing = false;
}
}

public List<ItemStack> getCraftedItems() {
if(!isEnabled())return Collections.emptyList();
if(alreadyProcessing || !isEnabled())return Collections.emptyList();
if (stillNeedReplace()) {
return new ArrayList<>();
}
IRouter myRouter = getRouter();
List<ExitRoute> exits = new ArrayList<>(myRouter.getIRoutersByCost());
exits.removeIf(e -> e.destination == myRouter);
LinkedList<ItemIdentifier> items = SimpleServiceLocator.logisticsManager.getCraftableItems(exits);
List<ItemStack> list = new ArrayList<>(items.size());
for (ItemIdentifier item : items) {
ItemStack is = item.unsafeMakeNormalStack(1);
list.add(is);
try {
alreadyProcessing = true;
IRouter myRouter = getRouter();
List<ExitRoute> exits = new ArrayList<>(myRouter.getIRoutersByCost());
exits.removeIf(e -> e.destination == myRouter);
LinkedList<ItemIdentifier> items = SimpleServiceLocator.logisticsManager.getCraftableItems(exits);
List<ItemStack> list = new ArrayList<>(items.size());
for (ItemIdentifier item : items) {
ItemStack is = item.unsafeMakeNormalStack(1);
list.add(is);
}
return list;
} finally {
alreadyProcessing = false;
}
return list;
}
/**
* @param craft bits: processExtra,onlyCraft,enableCraft
* */
public OpResult simulateRequest(ItemStack wanted, int craft, boolean allowPartial) {
if(!isEnabled()){
if(!isEnabled() || alreadyProcessing){
OpResult r = new OpResult();
r.used = Collections.emptyList();
r.missing = Collections.singletonList(wanted);
return r;
}
IRouter myRouter = getRouter();
List<ExitRoute> exits = new ArrayList<>(myRouter.getIRoutersByCost());
exits.removeIf(e -> e.destination == myRouter);
Map<ItemIdentifier, Integer> items = SimpleServiceLocator.logisticsManager.getAvailableItems(exits);
ItemIdentifier req = ItemIdentifier.get(wanted);
int count = items.getOrDefault(req, 0);
if(count == 0 && craft == 0){
OpResult r = new OpResult();
r.used = Collections.emptyList();
r.missing = Collections.singletonList(wanted);
return r;
}
ListLog ll = new ListLog();
/*System.out.println("BridgePipe.Req.simulateRequest()");
alreadyProcessing = true;
try {
IRouter myRouter = getRouter();
List<ExitRoute> exits = new ArrayList<>(myRouter.getIRoutersByCost());
exits.removeIf(e -> e.destination == myRouter);
Map<ItemIdentifier, Integer> items = SimpleServiceLocator.logisticsManager.getAvailableItems(exits);
ItemIdentifier req = ItemIdentifier.get(wanted);
int count = items.getOrDefault(req, 0);
if(count == 0 && craft == 0){
OpResult r = new OpResult();
r.used = Collections.emptyList();
r.missing = Collections.singletonList(wanted);
return r;
}
ListLog ll = new ListLog();
/*System.out.println("BridgePipe.Req.simulateRequest()");
System.out.println(wanted);*/
ItemIdentifierStack item = ItemIdentifier.get(wanted).makeStack(craft != 0 ? wanted.getCount() : Math.min(count, wanted.getCount()));
ItemResource reqRes = new ItemResource(item, BridgePipe.this);
RequestTree tree = new RequestTree(reqRes, null, (craft & 0b0010) != 0 ? EnumSet.of(ActiveRequestType.Craft) : RequestTree.defaultRequestFlags, null);
if (!tree.isDone()) {
recurseFailedRequestTree.accept(tree);
}
tree.sendUsedMessage(ll);
OpResult res = ll.asResult();
if((craft & 0b0100) != 0 && isDefaultRoute){
List<IExtraPromise> extrasPromises = new ArrayList<>();
listExras(tree, extrasPromises);
res.extra = extrasPromises.stream().map(e -> e.getItemType().makeNormalStack(e.getAmount())).collect(Collectors.toList());
}
if(craft == 0 && !allowPartial && wanted.getCount() > count){
int missingCount = wanted.getCount() - count;
ItemStack missingStack = wanted.copy();
missingStack.setCount(missingCount);
res.missing.add(missingStack);
}
ItemIdentifierStack item = ItemIdentifier.get(wanted).makeStack(craft != 0 ? wanted.getCount() : Math.min(count, wanted.getCount()));
ItemResource reqRes = new ItemResource(item, BridgePipe.this);
RequestTree tree = new RequestTree(reqRes, null, (craft & 0b0010) != 0 ? EnumSet.of(ActiveRequestType.Craft) : RequestTree.defaultRequestFlags, null);
if (!tree.isDone()) {
recurseFailedRequestTree.accept(tree);
}
tree.sendUsedMessage(ll);
OpResult res = ll.asResult();
if((craft & 0b0100) != 0 && isDefaultRoute){
List<IExtraPromise> extrasPromises = new ArrayList<>();
listExras(tree, extrasPromises);
res.extra = extrasPromises.stream().map(e -> e.getItemType().makeNormalStack(e.getAmount())).collect(Collectors.toList());
}
if(craft == 0 && !allowPartial && wanted.getCount() > count){
int missingCount = wanted.getCount() - count;
ItemStack missingStack = wanted.copy();
missingStack.setCount(missingCount);
res.missing.add(missingStack);
}

return res;
return res;
} finally {
alreadyProcessing = false;
}
}

public OpResult performRequest(ItemStack wanted, boolean craft) {
Expand Down Expand Up @@ -739,4 +750,9 @@ public void onWrenchClicked(EntityPlayer entityplayer) {
new TextComponentTranslation("gui.itemsink." + (isDefaultRoute ? "Yes" : "No"))));
}
}

@Override
public boolean disconnectPipe(TileEntity tile, EnumFacing dir) {
return dir.getAxis() == Axis.Y && tile instanceof IBridge ? true : false;
}
}
Loading

0 comments on commit 3dc8449

Please sign in to comment.