Skip to content

Commit 90e2c41

Browse files
authored
Merge branch 'master' into fix/databank-working-fix
2 parents df16598 + 3fc7f42 commit 90e2c41

40 files changed

+2508
-233
lines changed

dependencies.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ dependencies {
5252
compileOnly("curse.maven:journeymap-32274:5172461") // Journeymap 5.7.1p3
5353
compileOnly("curse.maven:voxelmap-225179:3029445") // VoxelMap 1.9.28
5454
compileOnly("curse.maven:xaeros-263420:5394758") // Xaero's Minimap 24.2.0
55+
devOnlyNonPublishable rfg.deobf("curse.maven:ftb-library-legacy-forge-237167:2985811") // FTB Library 5.4.7.2
56+
devOnlyNonPublishable rfg.deobf("curse.maven:ftb-utilities-forge-237102:3157548") // FTB Utilities 5.4.1.131
5557
compileOnly rfg.deobf("curse.maven:opencomputers-223008:5274236") // OpenComputers 1.8.5+179e1c3
5658
compileOnly rfg.deobf("curse.maven:hwyla-253449:2568751") // HWYLA 1.8.26-B41
5759
compileOnly rfg.deobf("curse.maven:baubles-227083:2518667") // Baubles 1.5.2
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package gregtech.api.block;
2+
3+
import net.minecraft.block.SoundType;
4+
import net.minecraft.block.state.IBlockState;
5+
6+
import org.jetbrains.annotations.NotNull;
7+
8+
public interface IStateSoundType {
9+
10+
@NotNull
11+
SoundType getSoundType(@NotNull IBlockState state);
12+
}

src/main/java/gregtech/api/block/VariantBlock.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,19 @@
44
import gregtech.common.creativetab.GTCreativeTabs;
55

66
import net.minecraft.block.Block;
7+
import net.minecraft.block.SoundType;
78
import net.minecraft.block.material.Material;
89
import net.minecraft.block.properties.PropertyEnum;
910
import net.minecraft.block.state.BlockStateContainer;
1011
import net.minecraft.block.state.IBlockState;
1112
import net.minecraft.client.resources.I18n;
1213
import net.minecraft.client.util.ITooltipFlag;
1314
import net.minecraft.creativetab.CreativeTabs;
15+
import net.minecraft.entity.Entity;
1416
import net.minecraft.item.ItemStack;
1517
import net.minecraft.util.IStringSerializable;
1618
import net.minecraft.util.NonNullList;
19+
import net.minecraft.util.math.BlockPos;
1720
import net.minecraft.world.World;
1821
import net.minecraftforge.fml.relauncher.Side;
1922
import net.minecraftforge.fml.relauncher.SideOnly;
@@ -112,6 +115,16 @@ public int getMetaFromState(IBlockState state) {
112115
return state.getValue(VARIANT).ordinal();
113116
}
114117

118+
@NotNull
119+
@Override
120+
public SoundType getSoundType(@NotNull IBlockState state, @NotNull World world, @NotNull BlockPos pos,
121+
@Nullable Entity entity) {
122+
if (getState(state) instanceof IStateSoundType stateSoundType) {
123+
return stateSoundType.getSoundType(state);
124+
}
125+
return super.getSoundType(state, world, pos, entity);
126+
}
127+
115128
// magic is here
116129
@SuppressWarnings("unchecked")
117130
protected static <T, R> Class<T> getActualTypeParameter(Class<? extends R> thisClass, Class<R> declaringClass) {

src/main/java/gregtech/api/block/machines/BlockMachine.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,4 +590,13 @@ public void randomDisplayTick(@NotNull IBlockState stateIn, @NotNull World world
590590
MetaTileEntity metaTileEntity = getMetaTileEntity(worldIn, pos);
591591
if (metaTileEntity != null) metaTileEntity.randomDisplayTick();
592592
}
593+
594+
@NotNull
595+
@Override
596+
public SoundType getSoundType(@NotNull IBlockState state, @NotNull World world, @NotNull BlockPos pos,
597+
@Nullable Entity entity) {
598+
MetaTileEntity metaTileEntity = getMetaTileEntity(world, pos);
599+
if (metaTileEntity == null) return getSoundType();
600+
return metaTileEntity.getSoundType();
601+
}
593602
}

src/main/java/gregtech/api/metatileentity/MetaTileEntity.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import gregtech.common.items.MetaItems;
4242

4343
import net.minecraft.block.Block;
44+
import net.minecraft.block.SoundType;
4445
import net.minecraft.block.state.BlockFaceShape;
4546
import net.minecraft.block.state.IBlockState;
4647
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
@@ -908,6 +909,14 @@ private void updateSound() {
908909
}
909910
}
910911

912+
/**
913+
* @return The sound type used when this block is broken, placed, stepped on, hit, or fallen on.
914+
*/
915+
@NotNull
916+
public SoundType getSoundType() {
917+
return SoundType.METAL;
918+
}
919+
911920
public final @NotNull ItemStack getStackForm(int amount) {
912921
int metaTileEntityIntId = registry.getIdByObjectName(metaTileEntityId);
913922
return new ItemStack(registry.getBlock(), amount, metaTileEntityIntId);

src/main/java/gregtech/api/mui/sync/GTFluidSyncHandler.java

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public class GTFluidSyncHandler extends SyncHandler {
4141
private final IFluidTank tank;
4242
private Consumer<FluidStack> jeiHandler;
4343
private BooleanConsumer lockHandler;
44+
private BooleanSupplier isLocked;
4445
private Supplier<FluidStack> lockedFluid;
4546
private FluidStack lastFluid;
4647
private FluidStack phantomFluid;
@@ -50,15 +51,17 @@ public class GTFluidSyncHandler extends SyncHandler {
5051
private BooleanSupplier showAmountInTooltip = () -> true;
5152
private BooleanSupplier showAmountOnSlot = () -> true;
5253
private BooleanSupplier drawAlwaysFull = () -> true;
54+
@Nullable
55+
private Consumer<@Nullable FluidStack> changeConsumer;
5356

5457
public GTFluidSyncHandler(IFluidTank tank) {
5558
this.tank = tank;
5659
}
5760

5861
@Override
5962
public void detectAndSendChanges(boolean init) {
60-
var current = getFluid();
61-
if (init || current == null || lastFluid == null || current.isFluidEqual(lastFluid)) {
63+
FluidStack current = getFluid();
64+
if (init || !GTUtility.areFluidStacksEqual(current, lastFluid)) {
6265
lastFluid = current == null ? null : current.copy();
6366
syncToClient(UPDATE_TANK, buffer -> NetworkUtils.writeFluidStack(buffer, current));
6467
} else if (lastFluid != null && current.amount != lastFluid.amount) {
@@ -84,11 +87,13 @@ public void lockFluid(boolean locked, boolean sync) {
8487
});
8588
}
8689

87-
public GTFluidSyncHandler handleLocking(Supplier<FluidStack> lockedFluid, Consumer<FluidStack> jeiHandler,
88-
BooleanConsumer lockHandler) {
90+
public GTFluidSyncHandler handleLocking(@NotNull Supplier<FluidStack> lockedFluid,
91+
@NotNull Consumer<FluidStack> jeiHandler,
92+
@NotNull BooleanConsumer lockHandler, @NotNull BooleanSupplier isLocked) {
8993
this.lockedFluid = lockedFluid;
9094
this.jeiHandler = jeiHandler;
9195
this.lockHandler = lockHandler;
96+
this.isLocked = isLocked;
9297
return this;
9398
}
9499

@@ -194,6 +199,16 @@ public boolean drawAlwaysFull() {
194199
return this.drawAlwaysFull.getAsBoolean();
195200
}
196201

202+
public void setChangeConsumer(@Nullable Consumer<@Nullable FluidStack> changeConsumer) {
203+
this.changeConsumer = changeConsumer;
204+
}
205+
206+
protected void onChange(@Nullable FluidStack fluidStack) {
207+
if (changeConsumer != null) {
208+
changeConsumer.accept(fluidStack);
209+
}
210+
}
211+
197212
public @NotNull String getFormattedFluidAmount() {
198213
var tankFluid = this.tank.getFluid();
199214
return String.format("%,d", tankFluid == null ? 0 : tankFluid.amount);
@@ -206,22 +221,25 @@ public int getFluidAmount() {
206221

207222
public @Nullable String getFluidLocalizedName() {
208223
var tankFluid = this.tank.getFluid();
209-
if (tankFluid == null && canLockFluid())
210-
tankFluid = this.lockedFluid.get();
224+
if (tankFluid == null)
225+
tankFluid = getLockedFluid();
211226

212227
return tankFluid == null ? null : tankFluid.getLocalizedName();
213228
}
214229

215230
public @NotNull IKey getFluidNameKey() {
216231
FluidStack tankFluid = tank.getFluid();
217-
if (tankFluid == null && canLockFluid()) {
218-
tankFluid = lockedFluid.get();
232+
if (tankFluid == null) {
233+
tankFluid = getLockedFluid();
219234
}
220235
return tankFluid == null ? IKey.EMPTY : KeyUtil.fluid(tankFluid);
221236
}
222237

223238
public void handleTooltip(@NotNull RichTooltip tooltip) {
224-
tooltip.addLine(getFluidNameKey());
239+
IKey nameKey = getFluidNameKey();
240+
if (nameKey != IKey.EMPTY) {
241+
tooltip.addLine(nameKey);
242+
}
225243

226244
if (showAmountInTooltip()) {
227245
tooltip.addLine(IKey.lang("gregtech.fluid.amount", getFluidAmount(), getCapacity()));
@@ -249,9 +267,20 @@ public void handleTooltip(@NotNull RichTooltip tooltip) {
249267
public void readOnClient(int id, PacketBuffer buf) {
250268
switch (id) {
251269
case TRY_CLICK_CONTAINER -> replaceCursorItemStack(NetworkUtils.readItemStack(buf));
252-
case UPDATE_TANK -> setFluid(NetworkUtils.readFluidStack(buf));
253-
case UPDATE_AMOUNT -> setAmount(buf.readInt());
254-
case LOCK_FLUID -> lockFluid(NetworkUtils.readFluidStack(buf), false);
270+
case UPDATE_TANK -> {
271+
FluidStack stack = NetworkUtils.readFluidStack(buf);
272+
setFluid(stack);
273+
onChange(stack);
274+
}
275+
case UPDATE_AMOUNT -> {
276+
setAmount(buf.readInt());
277+
onChange(getFluid());
278+
}
279+
case LOCK_FLUID -> {
280+
lockFluid(NetworkUtils.readFluidStack(buf), false);
281+
FluidStack stack = getFluid();
282+
onChange(stack == null ? getLockedFluid() : stack);
283+
}
255284
}
256285
}
257286

@@ -545,7 +574,7 @@ public FluidStack getLockedFluid() {
545574
}
546575

547576
public boolean canLockFluid() {
548-
return jeiHandler != null && lockHandler != null && lockedFluid != null;
577+
return jeiHandler != null && lockHandler != null && lockedFluid != null && isLocked != null;
549578
}
550579

551580
public void toggleLockFluid() {

src/main/java/gregtech/api/pipenet/block/BlockPipe.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,15 @@ public static Cuboid6 getCoverSideBox(EnumFacing side, float thickness) {
134134

135135
public abstract ItemStack getDropItem(IPipeTile<PipeType, NodeDataType> pipeTile);
136136

137+
@NotNull
138+
@Override
139+
@SuppressWarnings({ "deprecation", "unchecked" })
140+
public ItemStack getItem(@NotNull World world, @NotNull BlockPos pos, @NotNull IBlockState state) {
141+
var te = world.getTileEntity(pos);
142+
if (!(te instanceof IPipeTile<?, ?>pipeTile)) return ItemStack.EMPTY;
143+
return getDropItem((IPipeTile<PipeType, NodeDataType>) pipeTile);
144+
}
145+
137146
protected abstract NodeDataType getFallbackType();
138147

139148
// TODO this has no reason to need an ItemStack parameter

src/main/java/gregtech/api/util/GTUtility.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,4 +1023,10 @@ public static int combineRGB(@Range(from = 0, to = 255) int r, @Range(from = 0,
10231023
}
10241024
return map.get(key.toWildcard());
10251025
}
1026+
1027+
public static boolean areFluidStacksEqual(@Nullable FluidStack a, @Nullable FluidStack b) {
1028+
if (a == b) return true;
1029+
if (a == null) return false;
1030+
return a.isFluidEqual(b);
1031+
}
10261032
}

src/main/java/gregtech/api/util/GregFakePlayer.java

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,32 +11,51 @@
1111
import net.minecraft.world.World;
1212
import net.minecraft.world.WorldServer;
1313
import net.minecraftforge.common.util.FakePlayer;
14-
import net.minecraftforge.common.util.FakePlayerFactory;
1514
import net.minecraftforge.common.util.ITeleporter;
1615
import net.minecraftforge.fml.common.FMLCommonHandler;
1716

1817
import com.mojang.authlib.GameProfile;
18+
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
19+
import org.jetbrains.annotations.NotNull;
20+
import org.jetbrains.annotations.Nullable;
1921

2022
import java.lang.ref.WeakReference;
23+
import java.util.Map;
2124
import java.util.UUID;
2225

2326
public class GregFakePlayer extends EntityPlayer {
2427

25-
private static final GameProfile GREGTECH = new GameProfile(UUID.fromString("518FDF18-EC2A-4322-832A-58ED1721309B"),
26-
"[GregTech]");
27-
private static WeakReference<FakePlayer> GREGTECH_PLAYER = null;
28+
private static final String FAKE_NAME = "[GregTech]";
29+
private static final UUID FAKE_UUID = UUID.fromString("518FDF18-EC2A-4322-832A-58ED1721309B");
30+
private static final GameProfile FAKE_PROFILE = new GameProfile(FAKE_UUID, FAKE_NAME);
31+
private static final Map<UUID, GameProfile> PROFILE_CACHE = new Object2ObjectOpenHashMap<>();
32+
private static final Map<UUID, WeakReference<FakePlayer>> GREGTECH_PLAYERS = new Object2ObjectOpenHashMap<>();
2833

29-
public static FakePlayer get(WorldServer world) {
30-
FakePlayer ret = GREGTECH_PLAYER != null ? GREGTECH_PLAYER.get() : null;
31-
if (ret == null) {
32-
ret = FakePlayerFactory.get(world, GREGTECH);
33-
GREGTECH_PLAYER = new WeakReference<>(ret);
34+
public static @NotNull FakePlayer get(@NotNull WorldServer world) {
35+
return get(world, FAKE_PROFILE);
36+
}
37+
38+
public static @NotNull FakePlayer get(@NotNull WorldServer world, @Nullable UUID fakePlayerUUID) {
39+
return get(world, fakePlayerUUID == null ? FAKE_PROFILE :
40+
PROFILE_CACHE.computeIfAbsent(fakePlayerUUID, id -> new GameProfile(id, FAKE_NAME)));
41+
}
42+
43+
public static @NotNull FakePlayer get(@NotNull WorldServer world, @NotNull GameProfile fakePlayerProfile) {
44+
UUID id = fakePlayerProfile.getId();
45+
if (GREGTECH_PLAYERS.containsKey(id)) {
46+
FakePlayer fakePlayer = GREGTECH_PLAYERS.get(id).get();
47+
if (fakePlayer != null) {
48+
return fakePlayer;
49+
}
3450
}
35-
return ret;
51+
52+
FakePlayer fakePlayer = new FakePlayer(world, fakePlayerProfile);
53+
GREGTECH_PLAYERS.put(id, new WeakReference<>(fakePlayer));
54+
return fakePlayer;
3655
}
3756

38-
public GregFakePlayer(World worldIn) {
39-
super(worldIn, GREGTECH);
57+
public GregFakePlayer(@NotNull World worldIn) {
58+
super(worldIn, FAKE_PROFILE);
4059
}
4160

4261
@Override
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package gregtech.api.util;
2+
3+
import net.minecraft.enchantment.EnchantmentData;
4+
5+
import com.cleanroommc.modularui.integration.jei.JeiGhostIngredientSlot;
6+
import com.cleanroommc.modularui.integration.jei.ModularUIJeiPlugin;
7+
import mezz.jei.Internal;
8+
9+
public class JEIUtil {
10+
11+
/**
12+
* Check if the player is currently hovering over a valid ingredient for this slot. <br/>
13+
* Will always return false is JEI is not installed.
14+
*/
15+
public static boolean hoveringOverIngredient(JeiGhostIngredientSlot<?> jeiGhostIngredientSlot) {
16+
if (!Mods.JustEnoughItems.isModLoaded()) return false;
17+
return ModularUIJeiPlugin.hoveringOverIngredient(jeiGhostIngredientSlot);
18+
}
19+
20+
public static Object getBookStackIfEnchantment(Object ingredient) {
21+
if (ingredient instanceof EnchantmentData enchantmentData) {
22+
return Internal.getIngredientRegistry()
23+
.getIngredientHelper(enchantmentData)
24+
.getCheatItemStack(enchantmentData);
25+
}
26+
27+
return ingredient;
28+
}
29+
}

0 commit comments

Comments
 (0)