Skip to content

Commit

Permalink
Merge branch 'master' into blackhole-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
serenibyss authored Nov 9, 2024
2 parents bc9e70f + 269ac07 commit d98cb20
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 9 deletions.
5 changes: 4 additions & 1 deletion src/main/java/gregtech/api/enums/OrePrefixes.java
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,10 @@ public enum OrePrefixes {
blockCasingAdvanced("An Advanced Casing block for a Multiblock-Machine", "Rebolted ", " Casing", true, true, true,
true, false, true, false, true, false, false, 0, M * 9, 64, -1),
capsuleMolten("Capsule of Molten stuff", "Molten ", " Capsule", true, true, true, true, false, false, false, true,
false, false, 0, M * 1, 64, -1);
false, false, 0, M * 1, 64, -1),
// subatomic particles
particle("A Subatomic Particle", "", "", false, false, true, false, false, false, false, false, false, false, 0, -1,
64, -1);

public static final ImmutableList<OrePrefixes> CELL_TYPES = ImmutableList.of(
cell,
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/gregtech/api/net/GTPacketInfiniteSpraycan.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,19 @@ boolean execute(final BehaviourSprayColorInfinite behavior, final ItemStack item
}
return false;
}
},
TOGGLE_SHAKE_LOCK {

@Override
boolean execute(final BehaviourSprayColorInfinite behavior, final ItemStack itemStack,
final EntityPlayerMP player, final int newColor) {
if (behavior.togglePreventShake(itemStack)) {
Action.playLockSound(player);
} else {
Action.playUnlockSound(player);
}
return true;
}
};

private static void playShakeSound(final EntityPlayerMP player) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import static gregtech.api.enums.GTValues.AuthorQuerns;
import static net.minecraft.util.MovingObjectPosition.MovingObjectType.BLOCK;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.function.Consumer;

import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
Expand All @@ -16,6 +18,8 @@
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;

import org.lwjgl.input.Keyboard;

import com.google.common.collect.ImmutableList;
import com.gtnewhorizon.gtnhlib.GTNHLib;
import com.gtnewhorizons.modularui.api.UIInfos;
Expand All @@ -38,6 +42,7 @@ public class BehaviourSprayColorInfinite extends BehaviourSprayColor {
private static final List<ItemStack> COLOR_SELECTIONS;
public static final String COLOR_NBT_TAG = "current_color";
public static final String LOCK_NBT_TAG = "is_locked";
public static final String PREVENT_SHAKE_TAG = "prevent_shake";

private byte mCurrentColor;

Expand Down Expand Up @@ -106,9 +111,21 @@ protected boolean colorize(World aWorld, int aX, int aY, int aZ, ForgeDirection
@Override
public List<String> getAdditionalToolTips(final MetaBaseItem aItem, final List<String> aList,
final ItemStack itemStack) {
final List<String> statuses = new ArrayList<>();
if (isLocked(itemStack)) {
statuses.add(StatCollector.translateToLocal("gt.behaviour.paintspray.infinite.tooltip.locked"));
}
if (isPreventingShake(itemStack)) {
statuses.add(StatCollector.translateToLocal("gt.behaviour.paintspray.infinite.tooltip.preventing_shake"));
}

aList.add(StatCollector.translateToLocal("gt.behaviour.paintspray.infinite.tooltip.infinite"));
aList.add(mTooltipChain);
aList.add(" ");

if (!statuses.isEmpty()) {
aList.add(String.join(" :: ", statuses));
}
aList.add(StatCollector.translateToLocal("gt.behaviour.paintspray.infinite.tooltip.more_info"));
aList.add(AuthorQuerns);
return aList;
Expand All @@ -117,23 +134,32 @@ public List<String> getAdditionalToolTips(final MetaBaseItem aItem, final List<S
@Override
public Optional<List<String>> getAdditionalToolTipsWhileSneaking(final MetaBaseItem aItem, final List<String> aList,
final ItemStack aStack) {
final String ctrlKey = Minecraft.isRunningOnMac
? StatCollector.translateToLocal("gt.behaviour.paintspray.infinite.tooltip.ctrl_mac")
: StatCollector.translateToLocal("gt.behaviour.paintspray.infinite.tooltip.ctrl_pc");
aList.add(StatCollector.translateToLocal("gt.behaviour.paintspray.infinite.tooltip.infinite"));
aList.add(mTooltipChain);
aList.add(" ");
aList.add(StatCollector.translateToLocal("gt.behaviour.paintspray.infinite.tooltip.switch"));
aList.add(StatCollector.translateToLocal("gt.behaviour.paintspray.infinite.tooltip.gui"));
aList.add(StatCollector.translateToLocal("gt.behaviour.paintspray.infinite.tooltip.pick"));
aList.add(StatCollector.translateToLocal("gt.behaviour.paintspray.infinite.tooltip.lock"));
aList.add(
StatCollector.translateToLocalFormatted("gt.behaviour.paintspray.infinite.tooltip.prevent_shake", ctrlKey));
aList.add(" ");
aList.add(AuthorQuerns);

return Optional.of(aList);
}
// endregion

// region Raw Mouse Event Handlers
// region Raw Event Handlers
@Override
public boolean onLeftClick(MetaBaseItem item, ItemStack itemStack, EntityPlayer aPlayer) {
if (isPreventingShake(itemStack)) {
return false;
}

if (isLocked(itemStack)) {
displayLockedMessage();
} else {
Expand All @@ -146,6 +172,8 @@ public boolean onLeftClick(MetaBaseItem item, ItemStack itemStack, EntityPlayer
public boolean onMiddleClick(final MetaBaseItem item, final ItemStack itemStack, final EntityPlayer player) {
if (player.isSneaking()) {
sendPacket(GTPacketInfiniteSpraycan.Action.LOCK_CAN);
} else if (isCtrlDown()) {
sendPacket(GTPacketInfiniteSpraycan.Action.TOGGLE_SHAKE_LOCK);
} else if (isLocked(itemStack)) {
displayLockedMessage();
} else {
Expand All @@ -168,6 +196,26 @@ public boolean onMiddleClick(final MetaBaseItem item, final ItemStack itemStack,

return true;
}

private boolean isCtrlDown() {
// Yes, there's a duplicate method in GT++, but I didn't feel right including GT++ code here. We can extract
// this later if it is useful elsewhere.
try {
// noinspection DuplicatedCode
if (!Keyboard.isCreated()) {
return false;
}

boolean isCtrlKeyDown = Keyboard.isKeyDown(Keyboard.KEY_LCONTROL)
|| Keyboard.isKeyDown(Keyboard.KEY_RCONTROL);
if (!isCtrlKeyDown && Minecraft.isRunningOnMac)
isCtrlKeyDown = Keyboard.isKeyDown(Keyboard.KEY_LMETA) || Keyboard.isKeyDown(Keyboard.KEY_RMETA);

return isCtrlKeyDown;
} catch (IllegalStateException ignored) {
return false;
}
}
// endregion

// region GUI
Expand Down Expand Up @@ -255,14 +303,11 @@ public void setColor(final ItemStack itemStack, final byte color) {
}

public boolean toggleLock(final ItemStack itemStack) {
final NBTTagCompound tag = itemStack.hasTagCompound() ? itemStack.getTagCompound() : new NBTTagCompound();
final boolean newLockStatus = !tag.getBoolean(LOCK_NBT_TAG);

tag.setBoolean(LOCK_NBT_TAG, newLockStatus);
itemStack.setTagCompound(tag);
setItemStackName(itemStack);
return toggleBooleanTag(itemStack, LOCK_NBT_TAG);
}

return newLockStatus;
public boolean togglePreventShake(final ItemStack itemStack) {
return toggleBooleanTag(itemStack, PREVENT_SHAKE_TAG);
}

private void setItemStackName(final ItemStack itemStack) {
Expand All @@ -277,6 +322,17 @@ private void setItemStackName(final ItemStack itemStack) {
String.format("Infinite Spray Can %c" + Dyes.get(mCurrentColor).mName + "%c", lBracket, rBracket));
}
}

private boolean toggleBooleanTag(final ItemStack itemStack, final String tagName) {
final NBTTagCompound tag = itemStack.hasTagCompound() ? itemStack.getTagCompound() : new NBTTagCompound();
final boolean newValue = !tag.getBoolean(tagName);

tag.setBoolean(tagName, newValue);
itemStack.setTagCompound(tag);
setItemStackName(itemStack);

return newValue;
}
// endregion

public static Dyes getDye(ItemStack itemStack) {
Expand All @@ -296,6 +352,11 @@ public boolean isLocked(final ItemStack itemStack) {
.getBoolean(LOCK_NBT_TAG);
}

private boolean isPreventingShake(final ItemStack itemStack) {
return itemStack.hasTagCompound() && itemStack.getTagCompound()
.getBoolean(PREVENT_SHAKE_TAG);
}

private static class DyeSelectGUI extends SelectItemUIFactory {

public DyeSelectGUI(final String header, final ItemStack headerItem, final Consumer<ItemStack> selectedCallback,
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/gtPlusPlus/core/handler/CompatHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import cpw.mods.fml.common.event.FMLLoadCompleteEvent;
import gregtech.api.enums.GTValues;
import gregtech.api.enums.OrePrefixes;
import gregtech.api.util.GTOreDictUnificator;
import gtPlusPlus.api.interfaces.RunnableWithInfo;
import gtPlusPlus.api.objects.Logger;
Expand All @@ -25,8 +26,10 @@
import gtPlusPlus.core.common.compat.CompatWitchery;
import gtPlusPlus.core.handler.Recipes.LateRegistrationHandler;
import gtPlusPlus.core.handler.Recipes.RegistrationHandler;
import gtPlusPlus.core.item.chemistry.IonParticles;
import gtPlusPlus.core.material.Material;
import gtPlusPlus.core.material.MaterialGenerator;
import gtPlusPlus.core.material.Particle;
import gtPlusPlus.core.recipe.RecipesGregTech;
import gtPlusPlus.core.recipe.RecipesLaserEngraver;
import gtPlusPlus.core.recipe.ShapedRecipeObject;
Expand Down Expand Up @@ -118,6 +121,14 @@ public static void registerMyModsOreDictEntries() {
"bufferCore_" + GTValues.VN[i - 1],
new ItemStack(ItemUtils.getItemFromFQRN("miscutils:item.itemBufferCore" + i)));
}
for (Particle i : Particle.aMap) {
GTOreDictUnificator
.registerOre(OrePrefixes.particle + i.mParticleName.replace(" ", ""), Particle.getBaseParticle(i));
}

for (String i : IonParticles.ions) {
GTOreDictUnificator.registerOre(OrePrefixes.particle + i, Particle.getIon(i, 0));
}
}

public static void registerGregtechMachines() {
Expand Down
7 changes: 7 additions & 0 deletions src/main/resources/assets/gregtech/lang/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -631,13 +631,20 @@ GT5U.item.tank.locked_to=Content locked to %s
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.
gt.behaviour.paintspray.infinite.gui.solvent=Solvent
gt.behaviour.paintspray.infinite.gui.shake_toggle=Allow/disallow color iteration

gt.behaviour.paintspray.infinite.tooltip.infinite=Infinite uses
gt.behaviour.paintspray.infinite.tooltip.more_info=Hold SHIFT for more information
gt.behaviour.paintspray.infinite.tooltip.locked=Locked
gt.behaviour.paintspray.infinite.tooltip.preventing_shake=Left click action disabled

gt.behaviour.paintspray.infinite.tooltip.switch=Left Click: Change color (sneak to reverse direction)
gt.behaviour.paintspray.infinite.tooltip.pick=Middle Click block: Copy color to spray can
gt.behaviour.paintspray.infinite.tooltip.lock=Sneak Middle Click: Lock or unlock spray can
gt.behaviour.paintspray.infinite.tooltip.gui=Middle Click: Open color choice GUI
gt.behaviour.paintspray.infinite.tooltip.prevent_shake=%s-Middle Click: Allow/prevent left click action
gt.behaviour.paintspray.infinite.tooltip.ctrl_pc=Ctrl
gt.behaviour.paintspray.infinite.tooltip.ctrl_mac=Command

GT5U.hatch.disableFilter.true=Input Filter §cOff§r
GT5U.hatch.disableFilter.false=Input Filter §aOn§r
Expand Down

0 comments on commit d98cb20

Please sign in to comment.