Skip to content

Commit 4f3deb7

Browse files
authored
Merge branch 'GregTechCEu:master' into exnihilo
2 parents 15ec8a3 + c622751 commit 4f3deb7

36 files changed

+1098
-757
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package net.optifine.shaders;
2+
3+
/// Adapted and minimized from OptiFine
4+
public class Shaders {
5+
public static boolean shaderPackLoaded;
6+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package gregtech.api.block;
2+
3+
import net.minecraft.block.state.IBlockState;
4+
import net.minecraft.entity.EntityLiving;
5+
import net.minecraft.util.math.BlockPos;
6+
import net.minecraft.world.IBlockAccess;
7+
8+
import org.jetbrains.annotations.NotNull;
9+
10+
public interface IStateSpawnControl {
11+
12+
boolean canCreatureSpawn(@NotNull IBlockState state, @NotNull IBlockAccess world, @NotNull BlockPos pos,
13+
@NotNull EntityLiving.SpawnPlacementType type);
14+
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@
1313
import net.minecraft.client.util.ITooltipFlag;
1414
import net.minecraft.creativetab.CreativeTabs;
1515
import net.minecraft.entity.Entity;
16+
import net.minecraft.entity.EntityLiving;
1617
import net.minecraft.item.ItemStack;
1718
import net.minecraft.util.IStringSerializable;
1819
import net.minecraft.util.NonNullList;
1920
import net.minecraft.util.math.BlockPos;
21+
import net.minecraft.world.IBlockAccess;
2022
import net.minecraft.world.World;
2123
import net.minecraftforge.fml.relauncher.Side;
2224
import net.minecraftforge.fml.relauncher.SideOnly;
@@ -125,6 +127,15 @@ public SoundType getSoundType(@NotNull IBlockState state, @NotNull World world,
125127
return super.getSoundType(state, world, pos, entity);
126128
}
127129

130+
@Override
131+
public boolean canCreatureSpawn(@NotNull IBlockState state, @NotNull IBlockAccess world, @NotNull BlockPos pos,
132+
@NotNull EntityLiving.SpawnPlacementType type) {
133+
if (getState(state) instanceof IStateSpawnControl stateSpawnControl) {
134+
return stateSpawnControl.canCreatureSpawn(state, world, pos, type);
135+
}
136+
return super.canCreatureSpawn(state, world, pos, type);
137+
}
138+
128139
// magic is here
129140
@SuppressWarnings("unchecked")
130141
protected static <T, R> Class<T> getActualTypeParameter(Class<? extends R> thisClass, Class<R> declaringClass) {

src/main/java/gregtech/api/gui/Widget.java

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import net.minecraftforge.fml.relauncher.SideOnly;
2424

2525
import com.google.common.base.Preconditions;
26-
import org.jetbrains.annotations.Nullable;
2726
import org.lwjgl.opengl.GL11;
2827

2928
import java.awt.*;
@@ -311,28 +310,6 @@ public static void drawText(String text, float x, float y, float scale, int colo
311310
GlStateManager.enableBlend();
312311
}
313312

314-
@SideOnly(Side.CLIENT)
315-
public static void drawItemStack(ItemStack itemStack, int x, int y, @Nullable String altTxt) {
316-
GlStateManager.pushMatrix();
317-
GlStateManager.translate(0.0F, 0.0F, 32.0F);
318-
GlStateManager.color(1F, 1F, 1F, 1F);
319-
GlStateManager.enableDepth();
320-
GlStateManager.enableRescaleNormal();
321-
GlStateManager.enableLighting();
322-
RenderHelper.enableGUIStandardItemLighting();
323-
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240.0f, 240.0f);
324-
Minecraft mc = Minecraft.getMinecraft();
325-
RenderItem itemRender = mc.getRenderItem();
326-
itemRender.renderItemAndEffectIntoGUI(itemStack, x, y);
327-
itemRender.renderItemOverlayIntoGUI(mc.fontRenderer, itemStack, x, y, altTxt);
328-
GlStateManager.disableRescaleNormal();
329-
GlStateManager.disableLighting();
330-
GlStateManager.color(1F, 1F, 1F, 1F);
331-
GlStateManager.popMatrix();
332-
GlStateManager.enableBlend();
333-
GlStateManager.disableDepth();
334-
}
335-
336313
@SideOnly(Side.CLIENT)
337314
public static List<String> getItemToolTip(ItemStack itemStack) {
338315
Minecraft mc = Minecraft.getMinecraft();

src/main/java/gregtech/api/mui/GTGuiTextures.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,10 @@ private static String id(String path) {
283283
public static final UITexture PRIMITIVE_BLAST_FURNACE_PROGRESS_BAR = fullImage(
284284
"textures/gui/primitive/progress_bar_primitive_blast_furnace.png");
285285

286+
public static final UITexture FLUID_VOID_OVERLAY = fullImage("textures/gui/widget/button_fluid_void.png", true);
287+
public static final UITexture ITEM_VOID_OVERLAY = fullImage("textures/gui/widget/button_item_void.png", true);
288+
public static final UITexture FLUID_LOCK_OVERLAY = fullImage("textures/gui/widget/button_lock.png", true);
289+
286290
// todo bronze/steel/primitive fluid slots?
287291

288292
// SLOT OVERLAYS

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

Lines changed: 42 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -67,24 +67,24 @@ public void detectAndSendChanges(boolean init) {
6767
} else if (lastFluid != null && current.amount != lastFluid.amount) {
6868
lastFluid.amount = current.amount;
6969
syncToClient(UPDATE_AMOUNT, buffer -> buffer.writeInt(current.amount));
70-
}
70+
} else if (!isPhantom() && canLockFluid() &&
71+
!GTUtility.areFluidStacksEqual(this.phantomFluid, this.lockedFluid.get())) {
72+
this.phantomFluid = this.lockedFluid.get();
73+
sync(LOCK_FLUID, buffer -> {
74+
buffer.writeBoolean(this.isLocked.getAsBoolean());
75+
NetworkUtils.writeFluidStack(buffer, this.phantomFluid);
76+
});
77+
}
7178
}
7279

73-
public void lockFluid(FluidStack stack, boolean sync) {
80+
public void lockFluid(FluidStack stack) {
7481
if (!canLockFluid()) return;
7582
this.jeiHandler.accept(stack);
76-
if (sync) sync(LOCK_FLUID, buffer -> {
77-
buffer.writeBoolean(stack != null);
78-
NetworkUtils.writeFluidStack(buffer, stack);
79-
});
8083
}
8184

82-
public void lockFluid(boolean locked, boolean sync) {
85+
public void lockFluid(boolean locked) {
86+
if (!canLockFluid()) return;
8387
this.lockHandler.accept(locked);
84-
if (sync) sync(LOCK_FLUID, buffer -> {
85-
buffer.writeBoolean(locked);
86-
NetworkUtils.writeFluidStack(buffer, null);
87-
});
8888
}
8989

9090
public GTFluidSyncHandler handleLocking(@NotNull Supplier<FluidStack> lockedFluid,
@@ -106,10 +106,13 @@ public void setFluid(FluidStack fluid) {
106106
fluidTank.setFluid(fluid);
107107
} else {
108108
tank.drain(Integer.MAX_VALUE, true);
109-
if (fluid != null) tank.fill(fluid, true);
109+
if (!GTUtility.isEmpty(fluid)) tank.fill(fluid, true);
110+
}
111+
if (canLockFluid() && isLocked.getAsBoolean() && !GTUtility.isEmpty(fluid)) {
112+
lockFluid(fluid);
110113
}
111-
if (!isPhantom() || fluid == null) return;
112-
if (this.phantomFluid == null || this.phantomFluid.getFluid() != fluid.getFluid()) {
114+
if (!isPhantom() || GTUtility.isEmpty(fluid)) return;
115+
if (GTUtility.isEmpty(this.phantomFluid) || this.phantomFluid.getFluid() != fluid.getFluid()) {
113116
this.phantomFluid = fluid;
114117
}
115118
}
@@ -153,9 +156,16 @@ public boolean isPhantom() {
153156
return phantom;
154157
}
155158

159+
public GTFluidSyncHandler showAmount(boolean inSlot, boolean inTooltip) {
160+
return showAmount(() -> inSlot, () -> inTooltip);
161+
}
162+
163+
public GTFluidSyncHandler showAmount(BooleanSupplier inSlot, BooleanSupplier inTooltip) {
164+
return showAmountOnSlot(inSlot).showAmountInTooltip(inTooltip);
165+
}
166+
156167
public GTFluidSyncHandler showAmountInTooltip(boolean showAmount) {
157-
this.showAmountInTooltip = () -> showAmount;
158-
return this;
168+
return showAmountInTooltip(() -> showAmount);
159169
}
160170

161171
public GTFluidSyncHandler showAmountInTooltip(BooleanSupplier showAmount) {
@@ -170,8 +180,7 @@ public boolean showAmountInTooltip() {
170180
}
171181

172182
public GTFluidSyncHandler showAmountOnSlot(boolean showAmount) {
173-
this.showAmountOnSlot = () -> showAmount;
174-
return this;
183+
return showAmountOnSlot(() -> showAmount);
175184
}
176185

177186
public GTFluidSyncHandler showAmountOnSlot(BooleanSupplier showAmount) {
@@ -237,6 +246,7 @@ public int getFluidAmount() {
237246

238247
public void handleTooltip(@NotNull RichTooltip tooltip) {
239248
IKey nameKey = getFluidNameKey();
249+
240250
if (nameKey != IKey.EMPTY) {
241251
tooltip.addLine(nameKey);
242252
}
@@ -277,7 +287,8 @@ public void readOnClient(int id, PacketBuffer buf) {
277287
onChange(getFluid());
278288
}
279289
case LOCK_FLUID -> {
280-
lockFluid(NetworkUtils.readFluidStack(buf), false);
290+
lockHandler.accept(buf.readBoolean());
291+
lockFluid(NetworkUtils.readFluidStack(buf));
281292
FluidStack stack = getFluid();
282293
onChange(stack == null ? getLockedFluid() : stack);
283294
}
@@ -323,8 +334,7 @@ public void tryClickPhantom(MouseData data) {
323334
EntityPlayer player = getSyncManager().getPlayer();
324335
ItemStack currentStack = player.inventory.getItemStack();
325336
FluidStack currentFluid = this.tank.getFluid();
326-
if (currentStack.getCount() > 1) currentStack = GTUtility.copy(1, currentStack);
327-
var fluidHandlerItem = FluidUtil.getFluidHandler(currentStack);
337+
IFluidHandlerItem fluidHandlerItem = FluidUtil.getFluidHandler(currentStack);
328338

329339
switch (data.mouseButton) {
330340
case 0 -> {
@@ -579,18 +589,17 @@ public boolean canLockFluid() {
579589

580590
public void toggleLockFluid() {
581591
var cursorItem = getSyncManager().getCursorItem();
582-
if (getLockedFluid() == null) {
583-
if (cursorItem.isEmpty()) return;
584-
if (cursorItem.getCount() > 1) cursorItem = GTUtility.copy(1, cursorItem);
585-
586-
var fluidHandler = FluidUtil.getFluidHandler(cursorItem);
587-
if (fluidHandler == null) return;
588-
589-
var fluidStack = fluidHandler.getTankProperties()[0].getContents();
590-
if (fluidStack == null) return;
591-
lockFluid(fluidStack.copy(), true);
592-
} else if (cursorItem.isEmpty()) {
593-
lockFluid(null, true);
592+
FluidStack stack;
593+
if (GTUtility.isEmpty(getLockedFluid()) && !cursorItem.isEmpty()) {
594+
var fluidStack = FluidUtil.getFluidContained(cursorItem);
595+
stack = !GTUtility.isEmpty(fluidStack) ? fluidStack.copy() : null;
596+
} else {
597+
stack = null;
594598
}
599+
lockFluid(stack);
600+
sync(LOCK_FLUID, buffer -> {
601+
buffer.writeBoolean(this.isLocked.getAsBoolean());
602+
NetworkUtils.writeFluidStack(buffer, stack);
603+
});
595604
}
596605
}

src/main/java/gregtech/api/pipenet/block/material/BlockMaterialPipe.java

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,52 @@
1515

1616
import net.minecraft.block.state.IBlockState;
1717
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
18+
import net.minecraft.creativetab.CreativeTabs;
1819
import net.minecraft.item.Item;
1920
import net.minecraft.item.ItemStack;
21+
import net.minecraft.util.NonNullList;
2022
import net.minecraft.util.ResourceLocation;
2123
import net.minecraftforge.client.model.ModelLoader;
2224
import net.minecraftforge.fml.relauncher.Side;
2325
import net.minecraftforge.fml.relauncher.SideOnly;
2426

27+
import com.google.common.base.Preconditions;
2528
import org.jetbrains.annotations.NotNull;
2629

27-
import java.util.Objects;
30+
import java.util.*;
2831

2932
public abstract class BlockMaterialPipe<
3033
PipeType extends Enum<PipeType> & IPipeType<NodeDataType> & IMaterialPipeType<NodeDataType>, NodeDataType,
3134
WorldPipeNetType extends WorldPipeNet<NodeDataType, ? extends PipeNet<NodeDataType>>>
3235
extends BlockPipe<PipeType, NodeDataType, WorldPipeNetType> {
3336

3437
protected final PipeType pipeType;
38+
protected final Map<Material, NodeDataType> enabledMaterials;
3539
private final MaterialRegistry registry;
3640

3741
public BlockMaterialPipe(@NotNull PipeType pipeType, @NotNull MaterialRegistry registry) {
3842
this.pipeType = pipeType;
43+
this.enabledMaterials = new TreeMap<>();
3944
this.registry = registry;
4045
}
4146

47+
public boolean isValidPipeMaterial(Material material) {
48+
return !getItemPipeType(getItem(material)).getOrePrefix().isIgnored(material);
49+
}
50+
51+
public void addPipeMaterial(Material material, NodeDataType pipeProperties) {
52+
Preconditions.checkNotNull(material, "material was null");
53+
Preconditions.checkNotNull(pipeProperties, "the %s of material %s was null", getPipeTypeClass().getSimpleName(),
54+
material);
55+
Preconditions.checkArgument(material.getRegistry().getNameForObject(material) != null,
56+
"material %s is not registered", material);
57+
this.enabledMaterials.put(material, pipeProperties);
58+
}
59+
60+
public Collection<Material> getEnabledMaterials() {
61+
return Collections.unmodifiableSet(enabledMaterials.keySet());
62+
}
63+
4264
@Override
4365
public NodeDataType createProperties(IPipeTile<PipeType, NodeDataType> pipeTile) {
4466
PipeType pipeType = pipeTile.getPipeType();
@@ -80,7 +102,21 @@ public ItemStack getDropItem(IPipeTile<PipeType, NodeDataType> pipeTile) {
80102
return getItem(material);
81103
}
82104

83-
protected abstract NodeDataType createProperties(PipeType pipeType, Material material);
105+
protected NodeDataType createProperties(PipeType pipeType, Material material) {
106+
return pipeType.modifyProperties(enabledMaterials.getOrDefault(material, getFallbackType()));
107+
}
108+
109+
@Override
110+
protected NodeDataType getFallbackType() {
111+
return enabledMaterials.values().iterator().next();
112+
}
113+
114+
@Override
115+
public void getSubBlocks(@NotNull CreativeTabs itemIn, @NotNull NonNullList<ItemStack> items) {
116+
for (Material material : enabledMaterials.keySet()) {
117+
items.add(getItem(material));
118+
}
119+
}
84120

85121
public OrePrefix getPrefix() {
86122
return pipeType.getOrePrefix();

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

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,19 @@
44

55
import net.minecraft.item.ItemStack;
66
import net.minecraft.util.text.TextFormatting;
7+
import net.minecraftforge.fml.client.FMLClientHandler;
8+
import net.minecraftforge.fml.common.FMLCommonHandler;
79
import net.minecraftforge.fml.common.Loader;
810
import net.minecraftforge.fml.common.ModContainer;
911
import net.minecraftforge.fml.common.registry.GameRegistry;
1012
import net.minecraftforge.fml.relauncher.FMLLaunchHandler;
1113
import net.minecraftforge.fml.relauncher.Side;
1214
import net.minecraftforge.fml.relauncher.SideOnly;
15+
import net.optifine.shaders.Shaders;
1316

1417
import org.jetbrains.annotations.NotNull;
1518
import org.jetbrains.annotations.Nullable;
1619

17-
import java.lang.reflect.Field;
1820
import java.util.ArrayList;
1921
import java.util.Arrays;
2022
import java.util.List;
@@ -80,23 +82,26 @@ public enum Mods {
8082
Vintagium(Names.VINTAGIUM),
8183
Alfheim(Names.ALFHEIM),
8284

83-
// Special Optifine handler, but consolidated here for simplicity
84-
Optifine(null) {
85+
OptiFine(null) {
8586

8687
@Override
8788
public boolean isModLoaded() {
8889
if (this.modLoaded == null) {
89-
try {
90-
Class<?> c = Class.forName("net.optifine.shaders.Shaders");
91-
Field f = c.getDeclaredField("shaderPackLoaded");
92-
f.setAccessible(true);
93-
this.modLoaded = f.getBoolean(null);
94-
} catch (Exception ignored) {
95-
this.modLoaded = false;
96-
}
90+
this.modLoaded = FMLCommonHandler.instance().getSide().isClient() &&
91+
FMLClientHandler.instance().hasOptifine();
9792
}
9893
return this.modLoaded;
9994
}
95+
},
96+
97+
// Special Optifine shader handler, but consolidated here for simplicity
98+
ShadersMod(null) {
99+
100+
@Override
101+
public boolean isModLoaded() {
102+
// Check shader pack state at real time instead of caching it
103+
return OptiFine.isModLoaded() && Shaders.shaderPackLoaded;
104+
}
100105
};
101106

102107
public static class Names {

src/main/java/gregtech/client/model/pipeline/VertexLighterFlatSpecial.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ protected void processQuad() {
134134
updateColor(normal[v], color[v], x, y, z, tint, multiplier);
135135

136136
// When enabled this causes the rendering to be black with Optifine
137-
if (!Mods.Optifine.isModLoaded() && diffuse) {
137+
if (!Mods.ShadersMod.isModLoaded() && diffuse) {
138138
float d = LightUtil.diffuseLight(normal[v][0], normal[v][1], normal[v][2]);
139139
for (int i = 0; i < 3; i++) {
140140
color[v][i] *= d;

0 commit comments

Comments
 (0)