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

Hot Swapping Cables & Wires #3336

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
import java.util.HashSet;
import java.util.List;

import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
Expand All @@ -24,6 +26,8 @@
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;

import org.lwjgl.input.Keyboard;

import cofh.api.energy.IEnergyReceiver;
import gregtech.GTMod;
import gregtech.api.GregTechAPI;
Expand Down Expand Up @@ -56,6 +60,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 @@ -264,6 +269,50 @@ public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) {
}
}

@Override
public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer, ForgeDirection side,
float aX, float aY, float aZ) {
if (Keyboard.isKeyDown(Keyboard.KEY_LCONTROL)) {
final ItemStack handItem = aPlayer.inventory.getCurrentItem();
IMetaTileEntity meta = ItemMachines.getMetaTileEntity(handItem);

if (!(meta instanceof MTECable handCable)) return false;

// Coordinates of block being replaced
int x = aBaseMetaTileEntity.getXCoord();
int y = aBaseMetaTileEntity.getYCoord();
int z = aBaseMetaTileEntity.getZCoord();

MTECable newCable;
World world = aBaseMetaTileEntity.getWorld();
Block block = world.getBlock(x, y, z);

aPlayer.inventory.addItemStackToInventory(
new ItemStack(ItemMachines.getItemFromBlock(block), 1, block.getDamageValue(world, x, y, z)));

getBaseMetaTileEntity().setMetaTileEntity(
newCable = new MTECable(
handCable.mName,
handCable.mThickNess,
handCable.mMaterial,
handCable.mCableLossPerMeter,
handCable.mAmperage,
handCable.mVoltage,
handCable.mInsulated,
handCable.mCanShock));

world.setBlock(x, y, z, Blocks.air);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you really need to swap the entire block? You already are setting the MTE at this position, and the blocks for the different cables should be exactly the same (possibly meta is different, but you can just change the meta value).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if i dont then it functions as one cable and looks like another

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That means you're not sending an update to the renderer most likely, forcing a block update is just a roundabout way of doing so and not really ideal.


handItem.tryPlaceItemIntoWorld(aPlayer, world, x, y, z, ForgeDirection.UNKNOWN.ordinal(), aX, aY, aZ);

newCable.mCheckConnections = true;
newCable.onPostTick(aBaseMetaTileEntity, 20);

return true;
}
return super.onRightclick(aBaseMetaTileEntity, aPlayer, side, aX, aY, aZ);
}

@Override
public boolean onWireCutterRightClick(ForgeDirection side, ForgeDirection wrenchingSide, EntityPlayer aPlayer,
float aX, float aY, float aZ) {
Expand Down
Loading