Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor MTECable to update MTE without block swap #3826

Open
wants to merge 45 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
23c6e04
Fix Typo from Babbit to Babbitt
mak8427 Jan 18, 2025
2cc6223
Refactor MTECable to update MTE without block swap
mak8427 Jan 19, 2025
9aff87b
./gradlew spotlessApply fixes
mak8427 Jan 19, 2025
76f2efb
Merge branch 'GTNewHorizons:master' into patch-1
mak8427 Jan 19, 2025
469acd1
Refactor MTECable to update MTE without block swap
mak8427 Jan 19, 2025
bbf26ab
./gradlew spotlessApply fixes
mak8427 Jan 19, 2025
f9a55e1
Merge branch 'master' into master
serenibyss Jan 19, 2025
7217e9d
Merge remote-tracking branch 'origin/master'
mak8427 Jan 19, 2025
0c77781
Merge branch 'master' into master
mak8427 Jan 19, 2025
a167eee
Merge branch 'master' into master
Dream-Master Jan 19, 2025
1142344
Fix: Correclty swap items in the inventory
mak8427 Jan 19, 2025
85d617f
Merge remote-tracking branch 'origin/master'
mak8427 Jan 19, 2025
d9181d2
Merge branch 'master' into master
Dream-Master Jan 20, 2025
66b133a
Fix: now the cable is correctly handled with the new tileID.
mak8427 Jan 20, 2025
2ccaade
Fix: correctly handle the item swap in the inventory
mak8427 Jan 20, 2025
f7c0114
Merge branch 'master' into master
mak8427 Jan 20, 2025
59b7ce1
Revert "Fix Typo from Babbit to Babbitt"
mak8427 Jan 20, 2025
9ac08f4
Merge branch 'master' into master
Dream-Master Jan 20, 2025
d2b6868
Feature: Chat feedback
mak8427 Jan 20, 2025
e3441e2
Merge remote-tracking branch 'origin/master'
mak8427 Jan 20, 2025
9a46fea
Fix: change cable with the same material voltage but different Amperage
mak8427 Jan 20, 2025
f7465ac
Merge branch 'master' into master
mak8427 Jan 20, 2025
b76bdde
Merge branch 'master' into master
Dream-Master Jan 21, 2025
7988b7c
SpotlessApply fix
mak8427 Jan 21, 2025
1f5983c
Merge branch 'master' into master
Dream-Master Jan 21, 2025
3ef9dc3
Merge branch 'master' into master
Dream-Master Jan 22, 2025
212d05b
Merge branch 'master' into master
Dream-Master Jan 22, 2025
69a84d9
Merge branch 'master' into master
Dream-Master Jan 23, 2025
e0143eb
changed CTRL click from Keyboard to KeyboardUtil
mak8427 Jan 23, 2025
f4b668d
Merge branch 'master' into master
serenibyss Jan 25, 2025
050842c
Update src/main/java/gregtech/api/metatileentity/implementations/MTEC…
mak8427 Jan 25, 2025
8891f16
Merge branch 'master' into master
Dream-Master Jan 25, 2025
267539e
Merge branch 'master' into master
Dream-Master Jan 25, 2025
48e51cb
Merge branch 'master' into master
Dream-Master Jan 26, 2025
e9e1df7
Merge branch 'master' into master
Dream-Master Jan 27, 2025
6c474ca
Merge branch 'master' into master
Dream-Master Jan 28, 2025
22b95a3
Merge branch 'master' into master
Dream-Master Jan 30, 2025
908e25e
Merge branch 'master' into master
Dream-Master Jan 30, 2025
3630afc
From ctrl right click to sneaking and left click
mak8427 Jan 30, 2025
ba38d6e
-fix for multiplayer sever compatibilitity from ctrl + right clicl t…
mak8427 Jan 30, 2025
da81219
Fix the connection problem
mak8427 Jan 30, 2025
2d9246b
spotless
mak8427 Jan 30, 2025
59cbcbf
Remove depreceted stuff
mak8427 Jan 30, 2025
1fe7d47
Merge branch 'master' into master
mak8427 Jan 31, 2025
cf09381
Merge branch 'master' into master
Dream-Master Jan 31, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import gregtech.api.util.GTUtility;
import gregtech.api.util.ISerializableObject;
import gregtech.common.GTClient;
import gregtech.common.blocks.ItemMachines;
import gregtech.common.covers.CoverInfo;
import gregtech.common.covers.CoverSolarPanel;
import ic2.api.energy.EnergyNet;
Expand Down Expand Up @@ -263,6 +264,151 @@ public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) {
}
}

@Override
public void onLeftclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) {
// Only perform the logic if the player is sneaking.
if (!aPlayer.isSneaking()) {
return;
}

ItemStack handItem = aPlayer.inventory.getCurrentItem();
if (handItem == null) {
return;
}

IMetaTileEntity meta = ItemMachines.getMetaTileEntity(handItem);
if (!(meta instanceof MTECable handCable)) {
return;
}

// 1) Record & disconnect old cable from all sides where it was connected
MTECable oldCable = this;
byte oldConnections = oldCable.mConnections;

// We'll remember which sides were connected, so we can reconnect the new cable
List<ForgeDirection> oldConnectedSides = new ArrayList<>();
for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) {
if (oldCable.isConnectedAtSide(side)) {
oldConnectedSides.add(side);
}
}

short newMetaID = (short) handItem.getItemDamage();
long oldVoltage = this.mVoltage;
long oldAmperage = this.mAmperage;

// If the existing cable has the same specs as what we're holding, skip.
if (this.getClass() == handCable.getClass() && this.mMaterial == handCable.mMaterial
&& this.mVoltage == handCable.mVoltage
&& this.mAmperage == handCable.mAmperage) {
return;
}

short oldMetaID = (short) aBaseMetaTileEntity.getMetaTileID();

// Construct the new cable
MTECable newCable = new MTECable(
handCable.mName,
handCable.mThickNess,
handCable.mMaterial,
handCable.mCableLossPerMeter,
handCable.mAmperage,
handCable.mVoltage,
handCable.mInsulated,
handCable.mCanShock);

// Swap in the new cable
aBaseMetaTileEntity.setMetaTileID(newMetaID);
aBaseMetaTileEntity.setMetaTileEntity(newCable);

aBaseMetaTileEntity.markDirty();
aBaseMetaTileEntity.issueTextureUpdate();
aBaseMetaTileEntity.issueBlockUpdate();
aBaseMetaTileEntity.outputsEnergyTo(ForgeDirection.UNKNOWN, false);

// 7) Reconnect the *new* cable to the old sides
if (newCable.getBaseMetaTileEntity() != null) {
// For each side that was previously connected
for (ForgeDirection side : oldConnectedSides) {
int result = newCable.connect(side);
if (result > 0) {
// Also force the neighbor to connect back if it is a cable
IGregTechTileEntity neighborTile = newCable.getBaseMetaTileEntity()
.getIGregTechTileEntityAtSide(side);
if (neighborTile != null
&& neighborTile.getMetaTileEntity() instanceof IConnectable neighborCable) {
neighborCable.connect(side.getOpposite());
}
} else {
newCable.disconnect(side);
}
}
} else {
GTUtility.sendChatToPlayer(aPlayer, "Warning: new cable's tile is null! No reconnect done.");
}

// Handle inventory changes (old <-> new cable) if not creative
if (!aPlayer.capabilities.isCreativeMode) {
ItemStack oldCableStack = new ItemStack(handItem.getItem(), 1, oldMetaID);
boolean addedToInventory = false;

if (oldCableStack != null) {
// Try stacking with existing inventory
for (int i = 0; i < aPlayer.inventory.mainInventory.length; i++) {
ItemStack slot = aPlayer.inventory.mainInventory[i];
if (slot != null && slot.getItem() == oldCableStack.getItem()
&& slot.getItemDamage() == oldCableStack.getItemDamage()
&& slot.stackSize < slot.getMaxStackSize()) {
slot.stackSize++;
addedToInventory = true;
break;
}
}

// If not stacked, add new item
if (!addedToInventory) {
addedToInventory = aPlayer.inventory.addItemStackToInventory(oldCableStack);
}
// If still unsuccessful, drop it
if (!addedToInventory) {
aPlayer.dropPlayerItemWithRandomChoice(oldCableStack, false);
}
}

// Decrease the held cable quantity
handItem.stackSize--;
if (handItem.stackSize <= 0) {
aPlayer.inventory.setInventorySlotContents(aPlayer.inventory.currentItem, null);
}
}

// Optionally, notify the player if voltage or amperage changed
if (oldAmperage != handCable.mAmperage || oldVoltage != handCable.mVoltage) {
StringBuilder message = new StringBuilder();
if (oldAmperage != handCable.mAmperage) {
message.append(oldAmperage)
.append("A → ")
.append(handCable.mAmperage > oldAmperage ? EnumChatFormatting.GREEN : EnumChatFormatting.RED)
.append(handCable.mAmperage)
.append("A")
.append(EnumChatFormatting.RESET);
}
if (oldAmperage != handCable.mAmperage && oldVoltage != handCable.mVoltage) {
message.append(" | ");
}
if (oldVoltage != handCable.mVoltage) {
message.append(oldVoltage)
.append("V → ")
.append(handCable.mVoltage > oldVoltage ? EnumChatFormatting.GREEN : EnumChatFormatting.RED)
.append(handCable.mVoltage)
.append("V")
.append(EnumChatFormatting.RESET);
}
GTUtility
.sendChatToPlayer(aPlayer, StatCollector.translateToLocal("GT5U.item.cable.swapped") + " " + message);
}
}

@Override
public boolean onWireCutterRightClick(ForgeDirection side, ForgeDirection wrenchingSide, EntityPlayer aPlayer,
float aX, float aY, float aZ) {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/gregtech/api/util/GTLanguageManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@ public static void writePlaceholderStrings() {
addStringLocalization("Interaction_DESCRIPTION_Index_221", "Item threshold");
addStringLocalization("Interaction_DESCRIPTION_Index_222", "Fluid threshold");
addStringLocalization("Interaction_DESCRIPTION_Index_222.1", "Energy threshold");

addStringLocalization(
"Interaction_DESCRIPTION_Index_223",
"Single recipe locking enabled. Will lock to next recipe.");
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/gregtech/lang/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,7 @@ GT5U.item.cable.max_voltage=Max Voltage
GT5U.item.cable.max_amperage=Max Amperage
GT5U.item.cable.loss=Loss/Meter/Ampere
GT5U.item.cable.eu_volt=EU-Volt
GT5U.item.cable.swapped=Cable swapped:
GT5U.item.tank.locked_to=Content locked to %s

GT5U.item.pipe.capacity=Capacity
Expand Down