-
Notifications
You must be signed in to change notification settings - Fork 306
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
202 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
src/main/java/gregtech/common/covers/CoverEnergyWireless.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package gregtech.common.covers; | ||
|
||
import static gregtech.common.misc.WirelessNetworkManager.addEUToGlobalEnergyMap; | ||
import static java.lang.Long.min; | ||
|
||
import java.util.UUID; | ||
|
||
import net.minecraft.entity.player.EntityPlayer; | ||
import net.minecraftforge.common.util.ForgeDirection; | ||
|
||
import gregtech.api.interfaces.tileentity.ICoverable; | ||
import gregtech.api.interfaces.tileentity.IWirelessEnergyHatchInformation; | ||
import gregtech.api.metatileentity.BaseMetaTileEntity; | ||
import gregtech.api.util.CoverBehavior; | ||
import gregtech.api.util.ISerializableObject; | ||
|
||
public class CoverEnergyWireless extends CoverBehavior implements IWirelessEnergyHatchInformation { | ||
|
||
private final long transferred_energy_per_operation; | ||
|
||
public CoverEnergyWireless(int voltage) { | ||
this.transferred_energy_per_operation = 2 * voltage * ticks_between_energy_addition; | ||
} | ||
|
||
@Override | ||
public boolean isRedstoneSensitive(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity, | ||
long aTimer) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean allowsCopyPasteTool() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean allowsTickRateAddition() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean hasCoverGUI() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public int doCoverThings(ForgeDirection side, byte aInputRedstone, int aCoverID, int aCoverVariable, | ||
ICoverable aTileEntity, long aTimer) { | ||
if (aCoverVariable == 0 || aTimer % ticks_between_energy_addition == 0) { | ||
tryFetchingEnergy(aTileEntity); | ||
} | ||
return 1; | ||
} | ||
|
||
private static UUID getOwner(Object te) { | ||
if (te instanceof BaseMetaTileEntity igte) { | ||
return igte.getOwnerUuid(); | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
private void tryFetchingEnergy(ICoverable tileEntity) { | ||
if (tileEntity instanceof BaseMetaTileEntity bmte) { | ||
long currentEU = bmte.getStoredEUuncapped(); | ||
long euToTransfer = min(transferred_energy_per_operation - currentEU, transferred_energy_per_operation); | ||
if (euToTransfer <= 0) return; // nothing to transfer | ||
if (!addEUToGlobalEnergyMap(getOwner(tileEntity), -euToTransfer)) return; | ||
bmte.increaseStoredEnergyUnits(euToTransfer, true); | ||
} | ||
} | ||
|
||
@Override | ||
protected boolean onCoverRightClickImpl(ForgeDirection side, int aCoverID, | ||
ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity, EntityPlayer aPlayer, float aX, | ||
float aY, float aZ) { | ||
return false; | ||
} | ||
|
||
@Override | ||
protected boolean isGUIClickableImpl(ForgeDirection side, int aCoverID, | ||
ISerializableObject.LegacyCoverData aCoverVariable, ICoverable aTileEntity) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean alwaysLookConnected(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public int getTickRate(ForgeDirection side, int aCoverID, int aCoverVariable, ICoverable aTileEntity) { | ||
return 20; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.