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

Add Pipe Swapping functionality #3836

Merged
merged 35 commits into from
Feb 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
116b341
Add Pipe Swapping functionality
mak8427 Jan 20, 2025
46cad99
Merge branch 'master' into pipe-switch
mak8427 Jan 20, 2025
30578f8
Merge branch 'master' into pipe-switch
Dream-Master Jan 21, 2025
0a28bf7
Merge branch 'master' into pipe-switch
mak8427 Jan 21, 2025
4f425b3
Merge branch 'master' into pipe-switch
Dream-Master Jan 22, 2025
4cc7714
Merge branch 'master' into pipe-switch
Dream-Master Jan 22, 2025
eded734
Merge branch 'master' into pipe-switch
Dream-Master Jan 23, 2025
b9c4804
changed CTRL click from Keyboard to KeyboardUtil
mak8427 Jan 23, 2025
f054d1a
StatCollector instead of GTUtility.trans
mak8427 Jan 23, 2025
93e0972
Packet implementation first try
mak8427 Jan 24, 2025
aa2ff70
Merge branch 'master' into pipe-switch
Dream-Master Jan 25, 2025
49e336a
Merge branch 'master' into pipe-switch
Dream-Master Jan 25, 2025
24d91db
Merge branch 'master' into pipe-switch
Dream-Master Jan 25, 2025
cc57e4f
Merge branch 'master' into pipe-switch
mak8427 Jan 25, 2025
5bd80cb
Merge branch 'master' into pipe-switch
Dream-Master Jan 26, 2025
32f79a7
Merge branch 'master' into pipe-switch
Dream-Master Jan 27, 2025
8b07aec
Merge remote-tracking branch 'origin/pipe-switch' into pipe-switch
mak8427 Jan 28, 2025
c40941f
Spotless apply
mak8427 Jan 28, 2025
c8a3de3
Fix conditions
mak8427 Jan 28, 2025
ea171ba
Merge branch 'master' into pipe-switch
Dream-Master Jan 28, 2025
bb8f5f0
Merge branch 'master' into pipe-switch
Dream-Master Jan 30, 2025
26b9cc7
Merge branch 'master' into pipe-switch
Dream-Master Jan 30, 2025
def330a
star import fix
Dream-Master Jan 30, 2025
187205f
Update src/main/java/gregtech/api/metatileentity/implementations/MTEF…
mak8427 Jan 30, 2025
88f956e
Merge remote-tracking branch 'origin/pipe-switch' into pipe-switch
mak8427 Jan 30, 2025
65fcfd0
-fix for multiplayer sever compatibilitity from ctrl + right click t…
mak8427 Jan 30, 2025
c1df479
keep diseble input
mak8427 Jan 30, 2025
ca95f94
Keep fluid inside the pipe
mak8427 Jan 30, 2025
968e4ca
fix fluid handling
mak8427 Jan 30, 2025
85b5c03
Spotless
mak8427 Jan 30, 2025
7c229fa
Merge branch 'master' into pipe-switch
mak8427 Jan 31, 2025
567ca28
Merge branch 'master' into pipe-switch
Dream-Master Jan 31, 2025
ec91878
Remove CTRL var as unused
mak8427 Feb 1, 2025
975f2dc
Merge remote-tracking branch 'origin/pipe-switch' into pipe-switch
mak8427 Feb 1, 2025
1d6980e
Merge branch 'master' into pipe-switch
serenibyss Feb 1, 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 @@ -64,6 +64,7 @@
import gregtech.api.util.ISerializableObject;
import gregtech.api.util.WorldSpawnedEventBuilder.ParticleEventBuilder;
import gregtech.common.GTClient;
import gregtech.common.blocks.ItemMachines;
import gregtech.common.config.Other;
import gregtech.common.covers.CoverDrain;
import gregtech.common.covers.CoverFluidRegulator;
Expand Down Expand Up @@ -473,6 +474,138 @@ public void blockPipeOnSide(ForgeDirection side, EntityPlayer entityPlayer, byte
}
}

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

// Retrieve the item's MetaTileEntity
final ItemStack handItem = aPlayer.inventory.getCurrentItem();
if (handItem == null) return;

IMetaTileEntity meta = ItemMachines.getMetaTileEntity(handItem);
if (!(meta instanceof MTEFluid handFluid)) return;

// Preserve old connections and meta ID
byte oldConnections = this.mConnections;
short oldMetaID = (short) aBaseMetaTileEntity.getMetaTileID();

// Create the new fluid pipe
MTEFluid newPipe = (MTEFluid) handFluid.newMetaEntity(aBaseMetaTileEntity);
if (newPipe == null) return;

// Preserve old connections
newPipe.mConnections = oldConnections;
newPipe.mDisableInput = this.mDisableInput;

// Record old pipe parameters
long oldCapacity = this.mCapacity;
boolean oldGasProof = this.mGasProof;
int oldHeatResistance = this.mHeatResistance;

// Add fluid to the new pipe
if (this.mPipeAmount <= newPipe.mPipeAmount) {
for (int i = 0; i < mPipeAmount; i++) {
if (this.mFluids[i] != null) {
newPipe.mFluids[i] = this.mFluids[i].copy();
newPipe.mFluids[i].amount = Math.min(this.mFluids[i].amount, newPipe.mCapacity);
}
}
}

// Update to the new pipe
aBaseMetaTileEntity.setMetaTileID((short) handItem.getItemDamage());
aBaseMetaTileEntity.setMetaTileEntity(newPipe);

// Construct a change message if needed
StringBuilder message = new StringBuilder();

// Compare capacity changes
if (oldCapacity != newPipe.mCapacity) {
message.append(oldCapacity * 20)
.append("L/seconds → ");
message.append(newPipe.mCapacity > oldCapacity ? EnumChatFormatting.GREEN : EnumChatFormatting.RED)
.append(newPipe.mCapacity * 20)
.append("L/secs")
.append(EnumChatFormatting.RESET);
}

// Compare heat resistance
if (oldHeatResistance != newPipe.mHeatResistance) {
if (message.length() > 0) message.append(" | ");
message.append(oldHeatResistance)
.append("K → ");
message
.append(newPipe.mHeatResistance > oldHeatResistance ? EnumChatFormatting.GREEN : EnumChatFormatting.RED)
.append(newPipe.mHeatResistance)
.append("K")
.append(EnumChatFormatting.RESET);
}

// Compare gas handling
if (oldGasProof != newPipe.mGasProof) {
if (message.length() > 0) message.append(" | ");
if (newPipe.mGasProof) {
message.append(EnumChatFormatting.GREEN)
.append("Now Gas-Proof");
} else {
message.append(EnumChatFormatting.RED)
.append("No Longer Gas-Proof");
}
message.append(EnumChatFormatting.RESET);
}

// Send a chat message if anything changed
if (message.length() > 0) {
GTUtility.sendChatToPlayer(
aPlayer,
StatCollector.translateToLocal("GT5U.item.pipe.swap") + " " + message.toString());
}

// Force updates to sync changes
aBaseMetaTileEntity.markDirty();
aBaseMetaTileEntity.issueTextureUpdate();
aBaseMetaTileEntity.issueBlockUpdate();
aBaseMetaTileEntity.issueClientUpdate();

// Handle inventory operations unless in creative mode
if (!aPlayer.capabilities.isCreativeMode) {
ItemStack oldPipe = new ItemStack(handItem.getItem(), 1, oldMetaID);
boolean addedToInventory = false;

// Attempt to stack with existing items
if (oldPipe != null) {
for (int i = 0; i < aPlayer.inventory.mainInventory.length; i++) {
ItemStack slot = aPlayer.inventory.mainInventory[i];
if (slot != null && slot.getItem() == oldPipe.getItem()
&& slot.getItemDamage() == oldPipe.getItemDamage()
&& slot.stackSize < slot.getMaxStackSize()) {
slot.stackSize++;
addedToInventory = true;
break;
}
}
// Add new stack if stacking failed
if (!addedToInventory) {
addedToInventory = aPlayer.inventory.addItemStackToInventory(oldPipe);
}
// If still unsuccessful, drop the item
if (!addedToInventory) {
aPlayer.dropPlayerItemWithRandomChoice(oldPipe, false);
}
}

// Decrement the placed pipe from the player's hand
handItem.stackSize--;
if (handItem.stackSize <= 0) {
aPlayer.inventory.setInventorySlotContents(aPlayer.inventory.currentItem, null);
}
}
return;
}

@Override
public boolean onWrenchRightClick(ForgeDirection side, ForgeDirection wrenchingSide, EntityPlayer entityPlayer,
float aX, float aY, float aZ, ItemStack aTool) {
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 @@ -688,6 +688,7 @@ GT5U.item.pipe.gas_proof.yes=Yes
GT5U.item.pipe.gas_proof.no=No
GT5U.item.pipe.amount=Pipe Amount
GT5U.item.pipe.empty=Empty
GT5U.item.pipe.swap=Pipe Swapped:

gt.behaviour.paintspray.infinite.gui.header=Select a Color
gt.behaviour.paintspray.infinite.gui.lock_error=§eSpray can is §clocked§e! §bSneak middle-click to unlock.
Expand Down