Skip to content

Commit

Permalink
Fixed machines breaking when network contained a security terminal
Browse files Browse the repository at this point in the history
  • Loading branch information
solidDoWant committed Jan 30, 2021
1 parent e5b98d3 commit 98e418e
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
public class GregTechEnergisticsMod {
public static final String MODID = "gregtechenergistics";
public static final String NAME = "GregTech Energistics";
public static final String VERSION = "1.0.0.2";
public static final String VERSION = "1.0.0.3";

@SidedProxy(modId = GregTechEnergisticsMod.MODID, clientSide = "com.soliddowant.gregtechenergistics.ClientProxy",
serverSide = "com.soliddowant.gregtechenergistics.CommonProxy")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import gregtech.api.capability.GregtechTileCapabilities;
import gregtech.api.capability.IControllable;
import gregtech.api.capability.impl.FluidTankList;
import gregtech.api.cover.CoverBehavior;
import gregtech.api.cover.CoverWithUI;
import gregtech.api.cover.ICoverable;
import gregtech.api.gui.GuiTextures;
Expand Down Expand Up @@ -79,7 +78,7 @@
import java.util.stream.Stream;

@SuppressWarnings("BooleanMethodIsAlwaysInverted")
public class CoverAE2Stocker extends CoverBehavior
public class CoverAE2Stocker extends PlayerPlacedCoverBehavior
implements CoverWithUI, ITickable, IControllable, IGridBlock, IGridHost, IActionHost, ICraftingRequester {

public final int tier;
Expand Down Expand Up @@ -194,6 +193,12 @@ public boolean canAttach() {
}
}

@Override
public void setPlacingPlayer(EntityPlayer player) {
super.setPlacingPlayer(player);
node.setPlayerID(AEApi.instance().registries().players().getID(getPlacingPlayer()));
}

protected void updateMultiblockInformation() {
if (!isHolderMultiblock())
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package com.soliddowant.gregtechenergistics.covers;

import java.util.function.BiFunction;

import com.soliddowant.gregtechenergistics.GregTechEnergisticsMod;
import com.soliddowant.gregtechenergistics.items.MetaItems;
import com.soliddowant.gregtechenergistics.items.behaviors.PlayerCoverPlaceBehavior;
import gregtech.api.GTValues;
import gregtech.api.cover.CoverBehavior;
import gregtech.api.cover.CoverDefinition;
import gregtech.api.cover.ICoverable;
import gregtech.api.items.metaitem.MetaItem;
import gregtech.common.items.behaviors.CoverPlaceBehavior;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;

import java.util.function.BiFunction;

public class CoverBehaviors {
public static final int startingCoverId = 40;
public static void init() {
Expand Down Expand Up @@ -40,6 +40,6 @@ public static void registerBehavior(int idOffset, ResourceLocation coverId,
CoverDefinition coverDefinition = new CoverDefinition(coverId, behaviorCreator, placerItem.getStackForm());
CoverDefinition.registerCover(startingCoverId + idOffset, coverDefinition);
//noinspection deprecation // Using deprecation fields allows for compatibility with older GTCE versions
placerItem.addStats(new CoverPlaceBehavior(coverDefinition));
placerItem.addStats(new PlayerCoverPlaceBehavior(coverDefinition));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.soliddowant.gregtechenergistics.covers;

import gregtech.api.cover.CoverBehavior;
import gregtech.api.cover.ICoverable;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.EnumFacing;

public abstract class PlayerPlacedCoverBehavior extends CoverBehavior {
protected EntityPlayer placingPlayer;

public PlayerPlacedCoverBehavior(ICoverable coverHolder, EnumFacing attachedSide) {
super(coverHolder, attachedSide);
}

public EntityPlayer getPlacingPlayer() {
return placingPlayer;
}

public void setPlacingPlayer(EntityPlayer player) {
this.placingPlayer = player;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.soliddowant.gregtechenergistics.items.behaviors;

import com.soliddowant.gregtechenergistics.covers.PlayerPlacedCoverBehavior;
import gregtech.api.capability.GregtechTileCapabilities;
import gregtech.api.cover.CoverBehavior;
import gregtech.api.cover.CoverDefinition;
import gregtech.api.cover.ICoverable;
import gregtech.common.items.behaviors.CoverPlaceBehavior;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

public class PlayerCoverPlaceBehavior extends CoverPlaceBehavior {
public PlayerCoverPlaceBehavior(CoverDefinition coverDefinition) {
super(coverDefinition);
}

@Override
public EnumActionResult onItemUseFirst(EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) {
TileEntity tileEntity = world.getTileEntity(pos);
ICoverable coverable = tileEntity == null ? null : tileEntity.getCapability(GregtechTileCapabilities.CAPABILITY_COVERABLE, null);
if (coverable == null)
return EnumActionResult.PASS;

EnumFacing coverSide = ICoverable.rayTraceCoverableSide(coverable, player);
if (coverable.getCoverAtSide(coverSide) != null || !coverable.canPlaceCoverOnSide(coverSide))
return EnumActionResult.PASS;

if (!world.isRemote) {
ItemStack itemStack = player.getHeldItem(hand);
boolean successfullyPlaced = coverable.placeCoverOnSide(coverSide, itemStack, coverDefinition);
if (successfullyPlaced) {
if(!player.capabilities.isCreativeMode)
itemStack.shrink(1);

CoverBehavior placedCoverBehavior = coverable.getCoverAtSide(coverSide);
if(placedCoverBehavior instanceof PlayerPlacedCoverBehavior)
((PlayerPlacedCoverBehavior) placedCoverBehavior).setPlacingPlayer(player);
}

return successfullyPlaced ? EnumActionResult.SUCCESS : EnumActionResult.FAIL;
}

return EnumActionResult.SUCCESS;
}
}

0 comments on commit 98e418e

Please sign in to comment.