Skip to content

Commit

Permalink
Bunch of fixes / additions:
Browse files Browse the repository at this point in the history
- added configurable search ranges for ZPM's and handheld tools
- optimized the gate lookup method in GateUtil.
- forced gate to disconnect if a zpm is required for an active gate connection and is removed.
- fixed client doing lookup locally for gate TE for GUI's when its location is already known in the incoming packet.
- fixed Stargate not being able to use or see a ZPMHub.

Signed-off-by: Dockter <dockter@almuramc.com>
  • Loading branch information
Dockter committed Jul 22, 2020
1 parent c055195 commit 4b2f701
Show file tree
Hide file tree
Showing 17 changed files with 167 additions and 94 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = 2.0.5-beta-1
version = 2.0.5
mcversion = [1.12.2,1.12.2]
group = gcewing.sg
jarName = SGCraft
8 changes: 8 additions & 0 deletions src/mod/gcewing/sg/SGCraft.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ public class SGCraft extends BaseMod<SGCraftClient> {
// Unbreakable Block Option
public static boolean wormholeCanDestroyUnbreakableBlocks = false;

// Search Ranges for ZPM & Tools
public static int zpmSearchRange = 6;
public static int toolSearchRange = 6;

public static PermissionsUtil permissionsUtil;

public SGCraft() {
Expand Down Expand Up @@ -630,6 +634,10 @@ private void setOptions() {
ZPMEnergyPerSGEnergyUnit = config.getDouble("zpm-power", "zpmEnergyPerSGEnergyUnit", FPPerSGEnergyUnit);
forceZPMCfgUpdate = config.getBoolean("zpm-power", "force-update", forceZPMCfgUpdate);

// Range lookups for various things...
zpmSearchRange = config.getInteger("stargate", "zpmSearchRange", zpmSearchRange);
toolSearchRange = config.getInteger("stargate", "toolSearchRange", toolSearchRange);

// World Update / Fixes
forceSGBaseTEUpdate = config.getBoolean("stargate", "force-default-configs", forceSGBaseTEUpdate);
forceDHDCfgUpdate = config.getBoolean("dhd", "force-update", forceDHDCfgUpdate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer player, EnumHand handIn) {
if (!worldIn.isRemote && !player.isSneaking()) {
TileEntity localGateTE = GateUtil.locateLocalGate(worldIn, new BlockPos(player.posX, player.posY, player.posZ), 6, false);
TileEntity localGateTE = GateUtil.locateLocalGate(worldIn, new BlockPos(player.posX, player.posY, player.posZ), SGCraft.toolSearchRange, false);

if (localGateTE instanceof SGBaseTE) {
SGBaseTE localGate = (SGBaseTE) localGateTE;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package gcewing.sg.features.configurator.client.gui;

import com.google.common.eventbus.Subscribe;
import gcewing.sg.SGCraft;
import gcewing.sg.features.configurator.network.ConfiguratorNetworkHandler;
import gcewing.sg.tileentity.SGBaseTE;
import gcewing.sg.util.GateUtil;
Expand Down Expand Up @@ -43,6 +44,7 @@ public class ConfiguratorScreen extends BasicScreen {
private UITextField secondsToStayOpen, gateRotationSpeed, energyBufferSize, energyPerNaquadah, gateOpeningsPerNaquadah, distanceMultiplier, dimensionalMultiplier;
private UIButton gateAddressAccessListButton, playerAccessListButton;
private BlockPos location;
private BlockPos gatePos;
private World world;
private EntityPlayer player;
private boolean secondsToStayOpenPerm, gateRotationSpeedPerm, energyBufferSizePerm, energyPerNaquadahPerm, openingsPerNaquadahPerm, distanceFactorMultiplierPerm, interDimensionalMultiplierPerm;
Expand All @@ -57,14 +59,15 @@ public class ConfiguratorScreen extends BasicScreen {
// this.location = new BlockPos(player.posX, player.posY, player.posZ);
//}

public ConfiguratorScreen(EntityPlayer player, World worldIn, boolean isAdmin, boolean secondsToStayOpenPerm, boolean gateRotationSpeedPerm, boolean energyBufferSizePerm, boolean energyPerNaquadahPerm, boolean openingsPerNaquadahPerm,
public ConfiguratorScreen(EntityPlayer player, World worldIn, BlockPos gatePos, boolean isAdmin, boolean secondsToStayOpenPerm, boolean gateRotationSpeedPerm, boolean energyBufferSizePerm, boolean energyPerNaquadahPerm, boolean openingsPerNaquadahPerm,
boolean distanceFactorMultiplierPerm, boolean interDimensionalMultiplierPerm, boolean oneWayTravelOnlyPerm, boolean irisUpgradePerm, boolean chevronUpgradePerm, boolean pegasusGateTypePerm, boolean reverseWormholeKillsPerm,
boolean closeFromEitherEndPerm, boolean preserveInventoryOnIrisDeathPerm, boolean noInputPowerRequiredPerm, boolean chevronsLockOnDialPerm, boolean returnToPreviousIrisStatePerm, boolean transientDamagePerm, boolean transparencyPerm,
boolean dhdAsFuelSourcePerm, boolean allowRedstoneOutputPerm, boolean allowRedstoneInputPerm, boolean playerCanDestroyGatePerm, boolean displayGateAddressPerm, boolean gateAccessPerm, boolean playerAccessPerm) {

this.player = player;
this.isAdmin = isAdmin;
this.world = worldIn;
this.gatePos = gatePos;
this.isAdmin = isAdmin;
this.secondsToStayOpenPerm = secondsToStayOpenPerm;
this.gateRotationSpeedPerm = gateRotationSpeedPerm;
this.energyBufferSizePerm = energyBufferSizePerm;
Expand Down Expand Up @@ -100,7 +103,7 @@ public void construct() {
this.guiscreenBackground = false;
Keyboard.enableRepeatEvents(true);

TileEntity localGateTE = GateUtil.locateLocalGate(this.world, this.location, 6, false);
TileEntity localGateTE = world.getTileEntity(gatePos);

if (!(localGateTE instanceof SGBaseTE)) {
// Desync between server and client. Client doesn't have TE data yet.
Expand Down Expand Up @@ -603,7 +606,7 @@ public void onValueChange(ComponentEvent.ValueChange event) {

@Subscribe
public void onFocusStateChange(StateChangeEvent.FocusStateChange<UITextField> event) {
TileEntity localGateTE = GateUtil.locateLocalGate(this.world, this.location, 6, false);
TileEntity localGateTE = GateUtil.locateLocalGate(this.world, this.location, SGCraft.toolSearchRange, false);
if (localGateTE instanceof SGBaseTE) {
SGBaseTE localGate = (SGBaseTE) localGateTE;

Expand Down Expand Up @@ -632,7 +635,7 @@ public void onFocusStateChange(StateChangeEvent.FocusStateChange<UITextField> ev
}

private void refresh() {
TileEntity localGateTE = GateUtil.locateLocalGate(this.world, this.location, 6, false);
TileEntity localGateTE = GateUtil.locateLocalGate(this.world, this.location, SGCraft.toolSearchRange, false);
if (localGateTE instanceof SGBaseTE) {
SGBaseTE localGate = (SGBaseTE) localGateTE;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static gcewing.sg.tileentity.SGBaseTE.sendBasicMsg;

import com.google.common.eventbus.Subscribe;
import gcewing.sg.SGCraft;
import gcewing.sg.features.configurator.network.ConfiguratorNetworkHandler;
import gcewing.sg.features.pdd.client.gui.PddEntryScreen;
import gcewing.sg.features.pdd.network.PddNetworkHandler;
Expand Down Expand Up @@ -69,7 +70,7 @@ public GateAddressAccessScreen(BasicScreen parent, EntityPlayer player, World wo
public void construct() {
this.guiscreenBackground = false;
Keyboard.enableRepeatEvents(true);
final TileEntity localGateTE = GateUtil.locateLocalGate(this.world, this.location, 6, false);
final TileEntity localGateTE = GateUtil.locateLocalGate(this.world, this.location, SGCraft.toolSearchRange, false);
if (localGateTE instanceof SGBaseTE) {
localGate = (SGBaseTE) localGateTE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static gcewing.sg.tileentity.SGBaseTE.sendErrorMsg;

import com.google.common.eventbus.Subscribe;
import gcewing.sg.SGCraft;
import gcewing.sg.features.configurator.network.ConfiguratorNetworkHandler;
import gcewing.sg.tileentity.SGBaseTE;
import gcewing.sg.tileentity.data.PlayerAccessData;
Expand Down Expand Up @@ -67,7 +68,7 @@ public PlayerAccessScreen(BasicScreen parent, EntityPlayer player, World worldIn
public void construct() {
this.guiscreenBackground = false;
Keyboard.enableRepeatEvents(true);
final TileEntity localGateTE = GateUtil.locateLocalGate(this.world, this.location, 6, false);
final TileEntity localGateTE = GateUtil.locateLocalGate(this.world, this.location, SGCraft.toolSearchRange, false);
if (localGateTE instanceof SGBaseTE) {
localGate = (SGBaseTE) localGateTE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ public void handleGuiOpenRequest(EntityPlayer player, ChannelInput data) {
if (guiType == 1) {
new ConfiguratorScreen(player,
player.world,
pos,
isAdmin,
secondsToStayOpenPerm,
gateRotationSpeedPerm,
Expand Down
10 changes: 0 additions & 10 deletions src/mod/gcewing/sg/features/gdo/GdoItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,6 @@ public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer play
if (!worldIn.isRemote) {
TileEntity localGateTE = GateUtil.locateLocalGate(worldIn, new BlockPos(player.posX, player.posY, player.posZ), 6, false);

if (!(localGateTE instanceof SGBaseTE)) {
TileEntity dhdBaseTE = GateUtil.locateDHD(worldIn,new BlockPos(player.posX, player.posY, player.posZ), 6, false);
if (dhdBaseTE instanceof DHDTE) {
DHDTE dhd = (DHDTE) dhdBaseTE;
if (dhd.isLinkedToStargate) {
localGateTE = dhd.getLinkedStargateTE();
}
}
}

if (localGateTE instanceof SGBaseTE) {
SGBaseTE localGate = (SGBaseTE) localGateTE;

Expand Down
18 changes: 5 additions & 13 deletions src/mod/gcewing/sg/features/gdo/client/gui/GdoScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,20 @@ public class GdoScreen extends BasicScreen {
private UIImage localGateImage, remoteGateImage;
private UILabel localGateAddressLabel, remoteGateAddressLabel;
private BlockPos location;
private BlockPos gatePos;
private World world;
private EntityPlayer player;
public boolean isRemoteConnected, r_hasIrisUpgrade, r_hasChevronUpgrade, r_isIrisClosed, canAccessLocal, canAccessRemote;
public String r_address;
public int r_gateType;
public SGBaseTE localGate;

public GdoScreen(EntityPlayer player, World worldIn, boolean isAdmin, boolean isRemoteConnected, boolean r_hasIrisUpgrade, boolean r_hasChevronUpgrade,
public GdoScreen(EntityPlayer player, World worldIn, BlockPos gatePos, boolean isAdmin, boolean isRemoteConnected, boolean r_hasIrisUpgrade, boolean r_hasChevronUpgrade,
boolean r_isIrisClosed, int r_gateType, String r_address, boolean canAccessLocal, boolean canAccessRemote) {
this.player = player;
this.isAdmin = isAdmin;
this.world = worldIn;
this.gatePos = gatePos;
this.isAdmin = isAdmin;
this.location = new BlockPos(player.posX, player.posY, player.posZ);
this.isRemoteConnected = isRemoteConnected;
this.r_hasIrisUpgrade = r_hasIrisUpgrade;
Expand All @@ -71,17 +73,7 @@ public void construct() {
this.guiscreenBackground = false;
Keyboard.enableRepeatEvents(true);

TileEntity localGateTE = GateUtil.locateLocalGate(this.world, this.location, 6, false);

if (!(localGateTE instanceof SGBaseTE)) {
TileEntity dhdBaseTE = GateUtil.locateDHD(world,new BlockPos(player.posX, player.posY, player.posZ), 6, false);
if (dhdBaseTE instanceof DHDTE) {
DHDTE dhd = (DHDTE) dhdBaseTE;
if (dhd.isLinkedToStargate) {
localGateTE = dhd.getLinkedStargateTE();
}
}
}
TileEntity localGateTE = world.getTileEntity(gatePos);

if (localGateTE instanceof SGBaseTE) {
localGate = (SGBaseTE) localGateTE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
import gcewing.sg.features.zpm.ZPMItem;
import gcewing.sg.interfaces.ISGEnergySource;
import gcewing.sg.SGCraft;
import gcewing.sg.tileentity.DHDTE;
import gcewing.sg.tileentity.SGBaseTE;
import gcewing.sg.util.GateUtil;
import ic2.api.energy.prefab.BasicSource;
import ic2.api.energy.tile.IEnergyAcceptor;
import ic2.api.energy.tile.IEnergySource;
Expand Down Expand Up @@ -212,6 +215,10 @@ public ItemStack removeStackFromSlot(final int index) {
markChanged();
}

if (this.isEmpty()) {
pingSGBaseTE();
}

return ItemStackHelper.getAndRemove(this.items, 0);
}

Expand All @@ -238,9 +245,24 @@ public ItemStack decrStackSize(final int index, final int quantity) {
markChanged();
}

if (this.isEmpty()) {
pingSGBaseTE();
}

return item;
}

private void pingSGBaseTE() {
if (!world.isRemote) {
TileEntity localGateTE = GateUtil.locateLocalGate(this.world, this.pos, SGCraft.zpmSearchRange, false);

if (localGateTE instanceof SGBaseTE) {
SGBaseTE localGate = (SGBaseTE) localGateTE;
localGate.validateZPM();
}
}
}

@Override
public void setInventorySlotContents(final int index, final ItemStack item) {
this.items.set(0, item);
Expand Down
12 changes: 1 addition & 11 deletions src/mod/gcewing/sg/features/pdd/PddItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,7 @@ public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer play
player.inventoryContainer.detectAndSendChanges();
}

TileEntity localGateTE = GateUtil.locateLocalGate(worldIn, new BlockPos(player.posX, player.posY, player.posZ), 6, false);

if (!(localGateTE instanceof SGBaseTE)) {
TileEntity dhdBaseTE = GateUtil.locateDHD(worldIn,new BlockPos(player.posX, player.posY, player.posZ), 6, false);
if (dhdBaseTE instanceof DHDTE) {
DHDTE dhd = (DHDTE) dhdBaseTE;
if (dhd.isLinkedToStargate) {
localGateTE = dhd.getLinkedStargateTE();
}
}
}
TileEntity localGateTE = GateUtil.locateLocalGate(worldIn, new BlockPos(player.posX, player.posY, player.posZ), SGCraft.toolSearchRange, true);

if (localGateTE instanceof SGBaseTE) {
SGBaseTE localGate = (SGBaseTE) localGateTE;
Expand Down
26 changes: 9 additions & 17 deletions src/mod/gcewing/sg/features/pdd/client/gui/PddScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public class PddScreen extends BasicScreen {
private UILabel localGateAddressLabel, gateStatusLabel, availableAddressesLabel, addressTextureLabel, userFeedbackLabel;
private UISeparator valuesSeparator;
private BlockPos location;
private BlockPos gatePos;
private World world;
private EntityPlayer player;
private boolean delayedUpdate = true;
Expand All @@ -76,11 +77,12 @@ public class PddScreen extends BasicScreen {
private BasicList<AddressData> addressList;
private long timer;

public PddScreen(EntityPlayer player, World worldIn, boolean isAdmin) {
public PddScreen(EntityPlayer player, World worldIn, BlockPos gatePos, boolean isAdmin) {
this.player = player;
this.isAdmin = false;
this.world = worldIn;
this.location = new BlockPos(player.posX, player.posY, player.posZ);
this.gatePos = gatePos;
}

@Override
Expand All @@ -89,17 +91,7 @@ public void construct() {

this.guiscreenBackground = false;
Keyboard.enableRepeatEvents(true);
TileEntity localGateTE = GateUtil.locateLocalGate(this.world, this.location, 6, false);

if (!(localGateTE instanceof SGBaseTE)) {
TileEntity dhdBaseTE = GateUtil.locateDHD(world,new BlockPos(player.posX, player.posY, player.posZ), 6, false);
if (dhdBaseTE instanceof DHDTE) {
DHDTE dhd = (DHDTE) dhdBaseTE;
if (dhd.isLinkedToStargate) {
localGateTE = dhd.getLinkedStargateTE();
}
}
}
TileEntity localGateTE = world.getTileEntity(gatePos);

if (localGateTE instanceof SGBaseTE) {
localGate = (SGBaseTE) localGateTE;
Expand Down Expand Up @@ -208,7 +200,7 @@ public void construct() {
.text(TextFormatting.WHITE + I18n.format("sgcraft.gui.button.disconnect"))
.visible(false)
.onClick(() -> {
TileEntity localGate = GateUtil.locateLocalGate(this.world, this.location, 6, false);
TileEntity localGate = GateUtil.locateLocalGate(this.world, this.location, SGCraft.toolSearchRange, false);
if (!(localGate instanceof SGBaseTE)) {
return;
} else if (localGate != null) {
Expand Down Expand Up @@ -449,7 +441,7 @@ private void detectChange() {

private void dialRandom() {
// Todo: figure out how to properly use this.
final TileEntity localGateTE = GateUtil.locateLocalGate(this.world, this.location, 6, false);
final TileEntity localGateTE = GateUtil.locateLocalGate(this.world, this.location, SGCraft.toolSearchRange, false);
if (localGateTE instanceof SGBaseTE) {
localGate = (SGBaseTE) localGateTE;
}
Expand All @@ -459,7 +451,7 @@ private void dialRandom() {
}

private void dialSelectedAddress() {
TileEntity localGateTE = GateUtil.locateLocalGate(this.world, this.location, 6, false);
TileEntity localGateTE = GateUtil.locateLocalGate(this.world, this.location, SGCraft.toolSearchRange, false);
if (localGateTE instanceof SGBaseTE) {
localGate = (SGBaseTE) localGateTE;
}
Expand All @@ -479,7 +471,7 @@ private void dialSelectedAddress() {
}

private void dialSelectedAddressLockEachChevronIndividually() {
final TileEntity localGateTE = GateUtil.locateLocalGate(this.world, this.location, 6, false);
final TileEntity localGateTE = GateUtil.locateLocalGate(this.world, this.location, SGCraft.toolSearchRange, false);
if (localGateTE instanceof SGBaseTE) {
localGate = (SGBaseTE) localGateTE;
}
Expand Down Expand Up @@ -518,7 +510,7 @@ private void checkDiallingStatus() { // Method is checked every 100 frames.
}

this.addressList.setVisible(false);
TileEntity localGateTE = GateUtil.locateLocalGate(this.world, this.location, 6, false);
TileEntity localGateTE = GateUtil.locateLocalGate(this.world, this.location, SGCraft.toolSearchRange, false);

if (localGateTE instanceof SGBaseTE) {
SGBaseTE localGate = (SGBaseTE) localGateTE;
Expand Down

0 comments on commit 4b2f701

Please sign in to comment.