Skip to content

Commit

Permalink
1.3.11 Update
Browse files Browse the repository at this point in the history
Fixed crash with dedicated servers #35
Added blocking mode to AE and RS Crafting Managers
  • Loading branch information
tom5454 committed Aug 20, 2020
1 parent 4f281f7 commit c69deec
Show file tree
Hide file tree
Showing 12 changed files with 187 additions and 22 deletions.
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 @@ -82,7 +82,7 @@
public class LogisticsBridge {
public static final String ID = "logisticsbridge";
public static final String NAME = "Logistics Bridge";
public static final String VERSION = "1.3.10";
public static final String VERSION = "1.3.11";
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
40 changes: 37 additions & 3 deletions src/main/java/com/tom/logisticsbridge/gui/GuiCraftingManagerU.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
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.item.ItemStack;
import net.minecraft.util.ResourceLocation;

import com.tom.logisticsbridge.LogisticsBridge;
import com.tom.logisticsbridge.inventory.ContainerCraftingManagerU;
import com.tom.logisticsbridge.pipe.CraftingManager.BlockingMode;
import com.tom.logisticsbridge.tileentity.ICraftingManager;

import logisticspipes.utils.gui.LogisticsBaseGuiScreen;
Expand Down Expand Up @@ -62,13 +64,38 @@ public void initGui() {
ConfigExtention ce = new ConfigExtention(StringUtils.translate("gui.craftingManager.satellite"), pipe.satelliteDisplayStack(), 0);
ce.registerButton(extentionControllerLeft.registerControlledButton(addButton(new SmallGuiButton(0, guiLeft - 45, guiTop + 25, 40, 10, StringUtils.translate("gui.crafting.Select")))));
extentionControllerLeft.addExtention(ce);
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(1, guiLeft - 45, guiTop + 11, 40, 10, StringUtils.translate("gui.craftingManager.blocking.change")))));
extentionControllerLeft.addExtention(ce);
}
@Override
protected void actionPerformed(GuiButton button) throws IOException {
switch (button.id) {
case 0:
openSubGuiForSatelliteSelection(0);
break;
return;

case 1:
BlockingMode m = BlockingMode.VALUES[(pipe.getBlockingMode().ordinal() + 1) % BlockingMode.VALUES.length];
if(m == BlockingMode.NULL)m = BlockingMode.OFF;
pipe.setPipeID(1, Integer.toString(m.ordinal()), null);
return;
}
}
private void openSubGuiForSatelliteSelection(int id) {
Expand Down Expand Up @@ -101,7 +128,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 @@ -118,10 +145,17 @@ 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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -284,10 +284,6 @@ public VirtualPatternHandler(ItemStack is) {

@Override
public ItemStack getPattern() {
if(patternItem == null) {

}

return patternItem;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.tom.logisticsbridge.item.VirtualPatternRS;
import com.tom.logisticsbridge.network.SetIDPacket;
import com.tom.logisticsbridge.network.SetIDPacket.IIdPipe;
import com.tom.logisticsbridge.pipe.CraftingManager.BlockingMode;

import logisticspipes.network.PacketHandler;
import logisticspipes.network.abstractpackets.ModernPacket;
Expand All @@ -50,6 +51,7 @@ public class NetworkNodeCraftingManager extends NetworkNode implements IIdPipe,
@Override
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) {
if(supplyID.isEmpty())return stack;
if(!checkBlocking())return stack;
NetworkNodeSatellite sat = find(supplyID);
if(sat == null)return stack;
if(stack.getItem() == LogisticsBridge.packageItem && stack.hasTagCompound() && stack.getTagCompound().getBoolean("__actStack")) {
Expand Down Expand Up @@ -113,6 +115,8 @@ public int getSlotLimit(int slot) {
return 1;
}
};
private BlockingMode blockingMode = BlockingMode.OFF;

public NetworkNodeCraftingManager(World world, BlockPos pos) {
super(world, pos);
}
Expand All @@ -133,7 +137,7 @@ public String getName(int id) {
}
@Override
public String getPipeID(int id) {
return supplyID;
return id == 0 ? supplyID : Integer.toString(blockingMode.ordinal());
}

@Override
Expand All @@ -146,7 +150,8 @@ public void setPipeID(int id, String pipeID, EntityPlayer player) {
final ModernPacket packet = PacketHandler.getPacket(SetIDPacket.class).setName(pipeID).setId(id).setBlockPos(getPos()).setDimension(getWorld());
MainProxy.sendPacketToPlayer(packet, player);
}
supplyID = pipeID;
if(id == 0)supplyID = pipeID;
else if(id == 1)blockingMode = BlockingMode.VALUES[Math.abs(pipeID.charAt(0) - '0') % BlockingMode.VALUES.length];
}

@Override
Expand All @@ -156,6 +161,7 @@ public NBTTagCompound write(NBTTagCompound compound) {
compound.setUniqueId(NBT_UUID, uuid);
}
StackUtils.writeItems(patternsInventory, 0, compound);
compound.setByte("blockingMode", (byte) blockingMode.ordinal());
return super.write(compound);
}

Expand All @@ -169,6 +175,7 @@ public void read(NBTTagCompound compound) {
if (compound.hasUniqueId(NBT_UUID)) {
uuid = compound.getUniqueId(NBT_UUID);
}
blockingMode = BlockingMode.VALUES[Math.abs(compound.getByte("blockingMode")) % BlockingMode.VALUES.length];
super.read(compound);
}

Expand Down Expand Up @@ -273,4 +280,49 @@ public void onDisconnected(INetwork network) {
.filter(task -> task.getPattern().getContainer().getPosition().equals(pos))
.forEach(task -> network.getCraftingManager().cancel(task.getId()));
}

private boolean checkBlocking() {
switch (blockingMode) {
case EMPTY_MAIN_SATELLITE:
{
if(supplyID.isEmpty())return false;
NetworkNodeSatellite bus = find(supplyID);
if(bus == null)return false;
IItemHandler inv = bus.getHandler();
if (inv != null) {
for (int i = 0; i < inv.getSlots(); i++) {
ItemStack stackInSlot = inv.getStackInSlot(i);
if (!stackInSlot.isEmpty()) {
return false;
}
}
}
return true;
}

case REDSTONE_HIGH:
if(!getWorld().isBlockPowered(getPos()))return false;
return true;

case REDSTONE_LOW:
if(getWorld().isBlockPowered(getPos()))return false;
return true;

/*case WAIT_FOR_RESULT://TODO
{
IRouter resultR = getResultRouterByID(getResultUUID());
if(resultR == null)return false;
if(!(resultR.getPipe() instanceof ResultPipe))return false;
if(((ResultPipe) resultR.getPipe()).hasRequests())return false;
return true;
}*/

default:
return true;
}
}

public BlockingMode getBlockingMode() {
return blockingMode;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ public void update() {
}
}

public IItemHandler getHandler() {
TileEntity te = getFacingTile();
if(te != null && te.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, getDirection())){
IItemHandler h = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, getDirection());
return h;
}
return null;
}

private ItemStack injectCraftedItems(ItemStack stack, IItemHandler h) {
for (int i = 0; i < h.getSlots(); i++) {
stack = h.insertItem(i, stack, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,4 +240,9 @@ public boolean push(ItemStack is) {
itemsToInsert.add(ITEMS.createStack(is));
return true;
}

@Override
public InventoryAdaptor getHandler() {
return super.getHandler();
}
}
25 changes: 17 additions & 8 deletions src/main/java/com/tom/logisticsbridge/pipe/CraftingManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ public class CraftingManager extends PipeLogisticsChassi implements IIdPipe {
private int sendCooldown = 0;

@SideOnly(Side.CLIENT)
private IInventory clientInv = new InventoryBasic(null, false, 27);
private IInventory clientInv;

private boolean readingNBT;

public CraftingManager(Item item) {
super(item);
Expand Down Expand Up @@ -135,6 +137,7 @@ public void InventoryChanged(IInventory inventory) {
}

private void sendSignData() {
if(readingNBT)return;
for (int i = 0; i < 6; i++) {
if (signItem[i] != null) {
ModernPacket packet = signItem[i].getPacket();
Expand Down Expand Up @@ -275,14 +278,19 @@ public void writeToNBT(NBTTagCompound nbttagcompound) {
}
@Override
public void readFromNBT(NBTTagCompound nbttagcompound) {
super.readFromNBT(nbttagcompound);
resultId = nbttagcompound.getString("resultname");
satelliteId = nbttagcompound.getString("satellitename");
if(nbttagcompound.hasKey("resultid")){
resultId = Integer.toString(nbttagcompound.getInteger("resultid"));
satelliteId = Integer.toString(nbttagcompound.getInteger("satelliteid"));
try {
readingNBT = true;
super.readFromNBT(nbttagcompound);
resultId = nbttagcompound.getString("resultname");
satelliteId = nbttagcompound.getString("satellitename");
if(nbttagcompound.hasKey("resultid")){
resultId = Integer.toString(nbttagcompound.getInteger("resultid"));
satelliteId = Integer.toString(nbttagcompound.getInteger("satelliteid"));
}
blockingMode = BlockingMode.VALUES[Math.abs(nbttagcompound.getByte("blockingMode")) % BlockingMode.VALUES.length];
} finally {
readingNBT = false;
}
blockingMode = BlockingMode.VALUES[Math.abs(nbttagcompound.getByte("blockingMode")) % BlockingMode.VALUES.length];
}
@Override
public void collectSpecificInterests(Collection<ItemIdentifier> itemidCollection) {
Expand Down Expand Up @@ -543,6 +551,7 @@ public BlockingMode getBlockingMode() {

@SideOnly(Side.CLIENT)
public IInventory getClientModuleInventory() {
if(clientInv == null)clientInv = new InventoryBasic(null, false, 27);
return clientInv;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
import net.minecraft.util.math.BlockPos;

import com.tom.logisticsbridge.network.SetIDPacket.IIdPipe;
import com.tom.logisticsbridge.pipe.CraftingManager.BlockingMode;

public interface ICraftingManager extends IIdPipe {
ItemStack satelliteDisplayStack();
Slot createGuiSlot(int i, int x, int y);
BlockPos getPosition();
BlockingMode getBlockingMode();
}
Loading

0 comments on commit c69deec

Please sign in to comment.