Skip to content

Commit

Permalink
Merge branch 'GTNewHorizons:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
jude123412 authored Feb 13, 2025
2 parents ff79439 + 5e12d61 commit 8253949
Show file tree
Hide file tree
Showing 40 changed files with 562 additions and 794 deletions.
4 changes: 2 additions & 2 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ dependencies {
api("com.github.GTNewHorizons:ModularUI:1.2.17:dev")
api("com.github.GTNewHorizons:ModularUI2:2.2.4-1.7.10:dev")
api("com.github.GTNewHorizons:waila:1.8.2:dev")
api("com.github.GTNewHorizons:Applied-Energistics-2-Unofficial:rv3-beta-538-GTNH:dev")
api("com.github.GTNewHorizons:Applied-Energistics-2-Unofficial:rv3-beta-542-GTNH:dev")
api("com.github.GTNewHorizons:AE2FluidCraft-Rework:1.4.28-gtnh:dev")
api('com.github.GTNewHorizons:Yamcl:0.6.0:dev')
api("com.github.GTNewHorizons:Postea:1.0.13:dev")
Expand Down Expand Up @@ -80,7 +80,7 @@ dependencies {
compileOnly rfg.deobf("curse.maven:cofh-core-69162:2388751")
compileOnly("com.github.GTNewHorizons:Nuclear-Control:2.6.7:dev") { transitive = false }
compileOnly("thaumcraft:Thaumcraft:1.7.10-4.2.3.5:dev") { transitive = false }
implementation("com.github.GTNewHorizons:Hodgepodge:2.6.24:dev")
implementation("com.github.GTNewHorizons:Hodgepodge:2.6.26:dev")
compileOnly('com.github.GTNewHorizons:Botania:1.12.5-GTNH:dev') { transitive = false }
compileOnly('com.github.GTNewHorizons:HoloInventory:2.5.0-GTNH:dev') { transitive = false }
compileOnly rfg.deobf("curse.maven:extra-utilities-225561:2264384")
Expand Down
65 changes: 0 additions & 65 deletions src/main/java/gregtech/api/GregTechAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,13 @@

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.IntFunction;
import java.util.stream.Collectors;

import javax.annotation.Nonnull;

Expand All @@ -26,8 +22,6 @@
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;

import com.google.common.collect.Multimap;
import com.google.common.collect.Multimaps;
import com.google.common.collect.SetMultimap;

import cpw.mods.fml.relauncher.Side;
Expand All @@ -53,7 +47,6 @@
import gregtech.api.util.GTUtility;
import gregtech.api.world.GTWorldgen;
import gregtech.common.GTDummyWorld;
import gregtech.common.items.ItemIntegratedCircuit;

/**
* Please do not include this File in your Mod-download as it ruins compatibility, like with the IC2-API You may just
Expand Down Expand Up @@ -143,10 +136,6 @@ public class GregTechAPI {
sFrostHazmatList = new GTHashSet(), sHeatHazmatList = new GTHashSet(), sRadioHazmatList = new GTHashSet(),
sElectroHazmatList = new GTHashSet();

private static final Multimap<Integer, ItemStack> sRealConfigurationList = Multimaps
.newListMultimap(new TreeMap<>(), ArrayList::new);
private static final Map<Integer, List<ItemStack>> sConfigurationLists = new ConcurrentHashMap<>();

/**
* The List of Dimensions, which are Whitelisted for the Teleporter. This list should not contain other Planets.
* Mystcraft Dimensions and other Dimensional Things should be allowed. Mystcraft and Twilight Forest are
Expand Down Expand Up @@ -370,60 +359,6 @@ public static BaseMetaTileEntity constructBaseMetaTileEntity() {
}
}

/**
* Register a new ItemStack as configuration circuits. Duplicates or invalid stacks will be silently ignored.
*/
public static void registerConfigurationCircuit(ItemStack aStack) {
registerConfigurationCircuit(aStack, 0);
}

/**
* Register a new ItemStack as configuration circuits. Duplicates or invalid stacks will be silently ignored.
*
* @param minTier the minimal tier this circuit can be offered for free, e.g. normal configuration circuit is
* available in LV+ single blocks, GT++ breakthrough circuit is offered in HV+ single blocks
*/
public static void registerConfigurationCircuit(ItemStack aStack, int minTier) {
if (GTUtility.isStackInvalid(aStack)) return;
for (ItemStack tRegistered : sRealConfigurationList.values())
if (GTUtility.areStacksEqual(tRegistered, aStack)) return;
ItemStack stack = GTUtility.copyAmount(0, aStack);
sRealConfigurationList.put(minTier, stack);
for (Map.Entry<Integer, List<ItemStack>> e : sConfigurationLists.entrySet()) {
if (e.getKey() >= minTier) {
e.getValue()
.add(stack);
e.getValue()
.sort(getConfigurationCircuitsComparator());
}
}
}

/**
* Get a list of Configuration circuits. These stacks will have a stack size of 0. Use
* {@link #registerConfigurationCircuit(ItemStack, int)} or its overload to add to this list.
*
* @param machineTier The voltage tier where this list will be used. use Integer.MAX_VALUE to get all circuits
* @return An unmodifiable view of actual list. DO NOT MODIFY THE ItemStacks!
*/
public static List<ItemStack> getConfigurationCircuitList(int machineTier) {
return Collections.unmodifiableList(
sConfigurationLists.computeIfAbsent(
machineTier,
(t) -> sRealConfigurationList.entries()
.stream()
.filter(e -> e.getKey() <= machineTier)
.map(Map.Entry::getValue)
.sorted(getConfigurationCircuitsComparator())
.collect(Collectors.toList())));
}

public static Comparator<ItemStack> getConfigurationCircuitsComparator() {
return Comparator.comparingInt((ItemStack is) -> is.getItem() instanceof ItemIntegratedCircuit ? 0 : 1)
.thenComparing(ItemStack::getUnlocalizedName)
.thenComparing(ItemStack::getItemDamage);
}

/**
* Register a Wrench to be usable on GregTech Machines. The Wrench MUST have some kind of Durability unlike certain
* Buildcraft Wrenches.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import net.minecraft.item.ItemStack;

import gregtech.api.GregTechAPI;
import gregtech.api.util.GTUtility;

/**
* Implement this interface if your tileentity (or metatileentity) supports configuration circuits to resolve recipe
Expand All @@ -24,7 +24,7 @@ public interface IConfigurationCircuitSupport {
* This list is unmodifiable. Its elements are not supposed to be modified in any way!
*/
default List<ItemStack> getConfigurationCircuits() {
return GregTechAPI.getConfigurationCircuitList(100);
return GTUtility.getAllIntegratedCircuits();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
import com.gtnewhorizons.modularui.common.widget.SlotWidget;

import gregtech.GTMod;
import gregtech.api.GregTechAPI;
import gregtech.api.enums.SoundResource;
import gregtech.api.enums.SteamVariant;
import gregtech.api.gui.modularui.GTUIInfos;
Expand Down Expand Up @@ -1017,11 +1016,6 @@ public int getCircuitGUISlot() {
return 3;
}

@Override
public List<ItemStack> getConfigurationCircuits() {
return GregTechAPI.getConfigurationCircuitList(mTier);
}

@Override
public RecipeMap<?> getRecipeMap() {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,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 @@ -262,6 +263,154 @@ 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.issueBlockUpdate();

// 7) Reconnect the *new* cable to the old sides (modified for both cables and machines)
if (newCable.getBaseMetaTileEntity() != null) {
// For each side that was previously connected
for (ForgeDirection side : oldConnectedSides) {
IGregTechTileEntity neighborTile = newCable.getBaseMetaTileEntity()
.getIGregTechTileEntityAtSide(side);
int result = newCable.connect(side);
// If there is a neighbor tile, then:
if (neighborTile != null) {
// If the neighbor is a cable (implements IConnectable), then require a successful connection
if (neighborTile.getMetaTileEntity() instanceof IConnectable) {
if (result > 0) {
((IConnectable) neighborTile.getMetaTileEntity()).connect(side.getOpposite());
} else {
newCable.disconnect(side);
}
}
// Otherwise, if the neighbor is a machine (or any non-cable tile), don't connect.
} else {
// No neighbor exists at this side, so disconnect
newCable.disconnect(side);
}
}
}
aBaseMetaTileEntity.issueTextureUpdate();

// 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 Expand Up @@ -453,6 +602,8 @@ public String[] getInfoData() {
final BaseMetaPipeEntity base = (BaseMetaPipeEntity) getBaseMetaTileEntity();
final PowerNodePath path = (PowerNodePath) base.getNodePath();

path.reloadLocks();

if (path == null)
return new String[] { EnumChatFormatting.RED + "Failed to get Power Node info" + EnumChatFormatting.RESET };

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/gregtech/api/recipe/RecipeMaps.java
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ public final class RecipeMaps {
.progressBar(GTUITextures.PROGRESSBAR_ARROW_MULTIPLE)
.build();
public static final RecipeMap<RecipeMapBackend> fluidHeaterRecipes = RecipeMapBuilder.of("gt.recipe.fluidheater")
.maxIO(1, 0, 1, 1)
.maxIO(1, 1, 1, 1)
.slotOverlays((index, isFluid, isOutput, isSpecial) -> {
if (!isFluid) {
return null;
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
8 changes: 8 additions & 0 deletions src/main/java/gregtech/api/util/GTUtility.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@
import gregtech.api.threads.RunnableSound;
import gregtech.api.util.extensions.ArrayExt;
import gregtech.common.blocks.BlockOresAbstract;
import gregtech.common.items.ItemIntegratedCircuit;
import gregtech.common.pollution.Pollution;
import ic2.api.recipe.IRecipeInput;
import ic2.api.recipe.RecipeInputItemStack;
Expand Down Expand Up @@ -3920,6 +3921,13 @@ public static ItemStack getIntegratedCircuit(int config) {
return ItemList.Circuit_Integrated.getWithDamage(0, config);
}

/**
* @return A list of every integrated circuit, excluding zero. Do not modify the ItemStacks!
*/
public static List<ItemStack> getAllIntegratedCircuits() {
return ItemIntegratedCircuit.NON_ZERO_VARIANTS;
}

public static float getBlockHardnessAt(World aWorld, int aX, int aY, int aZ) {
return aWorld.getBlock(aX, aY, aZ)
.getBlockHardness(aWorld, aX, aY, aZ);
Expand Down
Loading

0 comments on commit 8253949

Please sign in to comment.