Skip to content

Commit 6848b98

Browse files
committed
- Limited GregTechCEu hatch compatibility available.
1 parent 9d6f500 commit 6848b98

File tree

10 files changed

+181
-19
lines changed

10 files changed

+181
-19
lines changed

src/main/java/com/cleanroommc/client/preview/renderer/scene/WorldSceneRenderer.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,25 @@ public abstract class WorldSceneRenderer {
6060
protected static final AtomicInteger THREAD_ID = new AtomicInteger(0);
6161

6262
protected static final Object2IntMap<BlockRenderLayer> LAYER_PROGRESS_UNITS = new Object2IntOpenHashMap<>();
63+
protected static final int TOTAL_PROGRESS_UNIT;
6364

6465
protected volatile Map<BlockRenderLayer, BufferBuilder> layerBufferBuilders = new EnumMap<>(BlockRenderLayer.class);
6566

6667
static {
68+
int totalProgressUnit = 0;
6769
LAYER_PROGRESS_UNITS.defaultReturnValue(1);
68-
LAYER_PROGRESS_UNITS.put(BlockRenderLayer.SOLID, 4);
69-
LAYER_PROGRESS_UNITS.put(BlockRenderLayer.CUTOUT_MIPPED, 1);
70-
LAYER_PROGRESS_UNITS.put(BlockRenderLayer.CUTOUT, 3);
71-
LAYER_PROGRESS_UNITS.put(BlockRenderLayer.TRANSLUCENT, 2);
70+
for (final BlockRenderLayer layer : BlockRenderLayer.values()) {
71+
int progressUnit = 1;
72+
switch (layer) {
73+
case SOLID -> progressUnit = 4;
74+
case CUTOUT_MIPPED -> progressUnit = 1;
75+
case CUTOUT -> progressUnit = 3;
76+
case TRANSLUCENT -> progressUnit = 2;
77+
}
78+
LAYER_PROGRESS_UNITS.put(layer, progressUnit);
79+
totalProgressUnit += progressUnit;
80+
}
81+
TOTAL_PROGRESS_UNIT = totalProgressUnit;
7282
}
7383

7484
enum CacheState {
@@ -399,7 +409,7 @@ public boolean isCompilerThreadAlive() {
399409

400410
public float getCompileProgress() {
401411
// 1000 blocks, 11 is per block unit.
402-
if (maxProgress <= 1000 * 11) {
412+
if (maxProgress <= 1000 * TOTAL_PROGRESS_UNIT) {
403413
return -1;
404414
}
405415
return (float) progress.get() / maxProgress;
@@ -542,7 +552,7 @@ private void compileCache(final Minecraft mc, final BlockRenderLayer oldRenderLa
542552
BlockRendererDispatcher blockrendererdispatcher = mc.getBlockRendererDispatcher();
543553
Map<Collection<BlockPos>, ISceneRenderHook> renderedBlocksMap = this.renderedBlocksMap.getAnotherMap();
544554
for (final BlockRenderLayer layer : BlockRenderLayer.values()) {
545-
int progressUnit = LAYER_PROGRESS_UNITS.get(layer);
555+
int progressUnit = LAYER_PROGRESS_UNITS.getInt(layer);
546556
ForgeHooksClient.setRenderLayer(layer);
547557
BufferBuilder buffer = getLayerBufferBuilder(layer);
548558
synchronized (buffer) {

src/main/java/github/kasuminova/mmce/client/gui/widget/preview/MachineStructurePreviewPanel.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import net.minecraft.tileentity.TileEntity;
2323
import net.minecraft.util.ResourceLocation;
2424
import net.minecraft.util.math.BlockPos;
25+
import net.minecraft.world.World;
2526

2627
import javax.annotation.Nonnull;
2728
import java.util.*;
@@ -304,10 +305,11 @@ protected void handlePatternBlockSelected(final BlockPos relativePos, final Slot
304305
return;
305306
}
306307

307-
IBlockState clickedBlock = renderer.getWorldRenderer().getWorld().getBlockState(relativePos);
308+
World world = renderer.getWorldRenderer().getWorld();
309+
IBlockState clickedBlock = world.getBlockState(relativePos);
308310
BlockArray.BlockInformation clicked = renderer.getPattern().getPattern().get(pos);
309-
ItemStack clickedBlockStack = StackUtils.getStackFromBlockState(clickedBlock);
310-
List<ItemStack> replaceable = clicked.getIngredientList().stream()
311+
ItemStack clickedBlockStack = StackUtils.getStackFromBlockState(clickedBlock, relativePos, world);
312+
List<ItemStack> replaceable = clicked.getIngredientList(pos, world).stream()
311313
.filter(replaceableStack -> !ItemUtils.matchStacks(clickedBlockStack, replaceableStack))
312314
.collect(Collectors.toList());
313315
selectedBlockIngredientMain.setStackInSlot(clickedBlockStack);
@@ -317,7 +319,7 @@ protected void handlePatternBlockSelected(final BlockPos relativePos, final Slot
317319
}
318320

319321
protected void handleRendererPatternUpdate(final DynamicMachine machine, final WorldSceneRendererWidget r, final IngredientList ingredientList) {
320-
List<ItemStack> stackList = renderer.getPattern().getDescriptiveStackList(renderer.getTickSnap());
322+
List<ItemStack> stackList = r.getPattern().getDescriptiveStackList(r.getTickSnap(), r.getWorldRenderer().getWorld(), r.getRenderOffset());
321323
ingredientList.setStackList(stackList.stream()
322324
.sorted(Comparator.comparingInt(ItemStack::getCount).reversed())
323325
.collect(Collectors.toList()));

src/main/java/github/kasuminova/mmce/client/gui/widget/preview/WorldSceneRendererWidget.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@
3939

4040
import javax.vecmath.Vector3f;
4141
import java.awt.*;
42-
import java.util.*;
4342
import java.util.List;
43+
import java.util.*;
4444
import java.util.function.Consumer;
4545

4646
@SuppressWarnings({"unused", "UnusedReturnValue"})
@@ -289,7 +289,7 @@ public void render(final WidgetGui gui, final RenderSize renderSize, final Rende
289289
@Override
290290
public boolean onMouseDWheel(final MousePos mousePos, final RenderPos renderPos, final int wheel) {
291291
if (isMouseOver(mousePos)) {
292-
zoom.set(MathHelper.clamp(zoom.getTargetValue() + (wheel < 0 ? 1.5f : -1.5f), defaultZoom / 80D, defaultZoom * 80D));
292+
zoom.set(MathHelper.clamp(zoom.getTargetValue() + (wheel < 0 ? 1.5f : -1.5f), defaultZoom / 80D, defaultZoom * 40D));
293293
return true;
294294
}
295295
return super.onMouseDWheel(mousePos, renderPos, wheel);
@@ -324,8 +324,8 @@ protected void handleMouseMove() {
324324

325325
int mouseX = Mouse.getX();
326326
int mouseY = Mouse.getY();
327-
int mouseOffsetX = mouseX - lastMouseX;
328-
int mouseOffsetY = mouseY - lastMouseY;
327+
float mouseOffsetX = mouseX - lastMouseX;
328+
float mouseOffsetY = mouseY - lastMouseY;
329329

330330
if (mouseButton == 0) {
331331
rotationPitch += ((mouseOffsetX) * 0.25F) + 360;

src/main/java/github/kasuminova/mmce/common/integration/gregtech/ModIntegrationGTCEU.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,18 @@
33
import github.kasuminova.mmce.common.integration.gregtech.componentproxy.GTEnergyHatchProxy;
44
import github.kasuminova.mmce.common.integration.gregtech.componentproxy.GTFluidHatchProxy;
55
import github.kasuminova.mmce.common.integration.gregtech.componentproxy.GTItemBusProxy;
6+
import github.kasuminova.mmce.common.integration.gregtech.patternproxy.GTBlockMachineProxy;
67
import github.kasuminova.mmce.common.machine.component.MachineComponentProxyRegistry;
8+
import github.kasuminova.mmce.common.machine.pattern.SpecialItemBlockProxyRegistry;
79

810
public class ModIntegrationGTCEU {
911

1012
public static void initialize() {
1113
MachineComponentProxyRegistry.INSTANCE.register("GTEnergyHatchProxy", GTEnergyHatchProxy.INSTANCE);
1214
MachineComponentProxyRegistry.INSTANCE.register("GTItemBusProxy", GTItemBusProxy.INSTANCE);
1315
MachineComponentProxyRegistry.INSTANCE.register("GTFluidHatchProxy", GTFluidHatchProxy.INSTANCE);
16+
17+
SpecialItemBlockProxyRegistry.INSTANCE.register("GTBlockMachineProxy", GTBlockMachineProxy.INSTANCE);
1418
}
1519

1620
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package github.kasuminova.mmce.common.integration.gregtech.patternproxy;
2+
3+
import github.kasuminova.mmce.common.machine.pattern.SpecialItemBlockProxy;
4+
import gregtech.api.block.machines.MachineItemBlock;
5+
import gregtech.api.metatileentity.MetaTileEntity;
6+
import gregtech.api.metatileentity.MetaTileEntityHolder;
7+
import gregtech.api.util.GTUtility;
8+
import net.minecraft.block.state.IBlockState;
9+
import net.minecraft.item.ItemStack;
10+
import net.minecraft.tileentity.TileEntity;
11+
import net.minecraft.world.World;
12+
13+
public class GTBlockMachineProxy implements SpecialItemBlockProxy {
14+
public static final GTBlockMachineProxy INSTANCE = new GTBlockMachineProxy();
15+
16+
private GTBlockMachineProxy() {
17+
}
18+
19+
@Override
20+
public boolean isValid(final ItemStack stack) {
21+
return stack.getItem() instanceof MachineItemBlock;
22+
}
23+
24+
@Override
25+
public TileEntity transformState(final ItemStack stack, final World world) {
26+
MetaTileEntity metaTileEntity = GTUtility.getMetaTileEntity(stack);
27+
MetaTileEntityHolder holder = new MetaTileEntityHolder();
28+
holder.setMetaTileEntity(metaTileEntity);
29+
holder.getMetaTileEntity().onPlacement();
30+
return holder;
31+
}
32+
33+
@Override
34+
public ItemStack getTrueStack(final IBlockState state, final TileEntity te) {
35+
if (!(te instanceof MetaTileEntityHolder holder)) {
36+
return ItemStack.EMPTY;
37+
}
38+
MetaTileEntity mte = holder.getMetaTileEntity();
39+
return mte != null ? mte.getStackForm() : ItemStack.EMPTY;
40+
}
41+
42+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package github.kasuminova.mmce.common.machine.pattern;
2+
3+
import net.minecraft.block.state.IBlockState;
4+
import net.minecraft.item.ItemStack;
5+
import net.minecraft.tileentity.TileEntity;
6+
import net.minecraft.world.World;
7+
8+
public interface SpecialItemBlockProxy {
9+
10+
boolean isValid(final ItemStack stack);
11+
12+
TileEntity transformState(final ItemStack stack, final World world);
13+
14+
ItemStack getTrueStack(final IBlockState state, final TileEntity te);
15+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package github.kasuminova.mmce.common.machine.pattern;
2+
3+
import net.minecraft.item.ItemStack;
4+
5+
import javax.annotation.Nullable;
6+
import java.util.Collections;
7+
import java.util.HashMap;
8+
import java.util.Map;
9+
10+
public class SpecialItemBlockProxyRegistry {
11+
public static final SpecialItemBlockProxyRegistry INSTANCE = new SpecialItemBlockProxyRegistry();
12+
13+
private SpecialItemBlockProxyRegistry() {
14+
}
15+
16+
private final Map<String, SpecialItemBlockProxy> proxyRegistry = new HashMap<>();
17+
18+
public Map<String, SpecialItemBlockProxy> getRegistry() {
19+
return Collections.unmodifiableMap(proxyRegistry);
20+
}
21+
22+
public SpecialItemBlockProxy register(String name, SpecialItemBlockProxy proxy) {
23+
if (proxyRegistry.containsKey(name)) {
24+
throw new IllegalArgumentException("Duplicate SpecialTileEntityProxy proxy key: " + name);
25+
}
26+
proxyRegistry.put(name, proxy);
27+
return proxy;
28+
}
29+
30+
public void unregister(String name) {
31+
proxyRegistry.remove(name);
32+
}
33+
34+
@Nullable
35+
public SpecialItemBlockProxy getValidProxy(ItemStack te) {
36+
for (final SpecialItemBlockProxy proxy : proxyRegistry.values()) {
37+
if (proxy.isValid(te)) {
38+
return proxy;
39+
}
40+
}
41+
return null;
42+
}
43+
}

src/main/java/hellfirepvp/modularmachinery/common/crafting/requirement/jei/JEIComponentIngredientArray.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,13 @@
44
import github.kasuminova.mmce.common.itemtype.ChancedIngredientStack;
55
import hellfirepvp.modularmachinery.common.crafting.helper.ComponentRequirement;
66
import hellfirepvp.modularmachinery.common.crafting.requirement.RequirementIngredientArray;
7-
import hellfirepvp.modularmachinery.common.integration.ingredient.IngredientItemStack;
87
import hellfirepvp.modularmachinery.common.integration.recipe.RecipeLayoutPart;
98
import hellfirepvp.modularmachinery.common.machine.IOType;
10-
import hellfirepvp.modularmachinery.common.util.ItemUtils;
119
import hellfirepvp.modularmachinery.common.util.MiscUtils;
1210
import net.minecraft.client.resources.I18n;
1311
import net.minecraft.item.ItemStack;
14-
import net.minecraft.util.NonNullList;
15-
import net.minecraftforge.oredict.OreDictionary;
1612

1713
import java.awt.*;
18-
import java.util.ArrayList;
1914
import java.util.List;
2015

2116
public class JEIComponentIngredientArray extends ComponentRequirement.JEIComponent<ItemStack> {

src/main/java/hellfirepvp/modularmachinery/common/util/BlockArray.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import com.google.gson.JsonParseException;
1313
import crafttweaker.annotations.ZenRegister;
1414
import github.kasuminova.mmce.common.helper.AdvancedBlockChecker;
15+
import github.kasuminova.mmce.common.machine.pattern.SpecialItemBlockProxy;
16+
import github.kasuminova.mmce.common.machine.pattern.SpecialItemBlockProxyRegistry;
1517
import hellfirepvp.modularmachinery.client.ClientScheduler;
1618
import hellfirepvp.modularmachinery.common.block.BlockStatedMachineComponent;
1719
import hellfirepvp.modularmachinery.common.util.nbt.NBTJsonSerializer;
@@ -265,6 +267,33 @@ public List<ItemStack> getDescriptiveStackList(long snapTick) {
265267
return stackList;
266268
}
267269

270+
public List<ItemStack> getDescriptiveStackList(long snapTick, World world, BlockPos offset) {
271+
List<ItemStack> stackList = new ArrayList<>();
272+
273+
pattern.forEach((pos, info) -> {
274+
ItemStack descriptiveStack = info.getDescriptiveStack(snapTick);
275+
if (descriptiveStack.isEmpty()) {
276+
return;
277+
}
278+
SpecialItemBlockProxy specialItemBlockProxy = SpecialItemBlockProxyRegistry.INSTANCE.getValidProxy(descriptiveStack);
279+
if (specialItemBlockProxy != null) {
280+
BlockPos realPos = pos.add(offset);
281+
descriptiveStack = specialItemBlockProxy.getTrueStack(world.getBlockState(realPos), world.getTileEntity(realPos));
282+
}
283+
284+
for (final ItemStack stack : stackList) {
285+
if (ItemUtils.matchStacks(descriptiveStack, stack)) {
286+
stack.grow(1);
287+
return;
288+
}
289+
}
290+
291+
stackList.add(descriptiveStack);
292+
});
293+
294+
return stackList;
295+
}
296+
268297
public boolean matches(World world, BlockPos center, boolean oldState, @Nullable Map<BlockPos, List<BlockInformation>> modifierReplacementPattern) {
269298
// if (pattern.size() >= 1500) {
270299
// return matchesParallel(world, center, oldState, modifierReplacementPattern);
@@ -558,6 +587,15 @@ public List<ItemStack> getIngredientList() {
558587
return list;
559588
}
560589

590+
public List<ItemStack> getIngredientList(BlockPos pos, World world) {
591+
List<ItemStack> list = new ArrayList<>();
592+
samples.stream()
593+
.map(state -> StackUtils.getStackFromBlockState(state, pos, world))
594+
.filter(stackFromBlockState -> ItemUtils.stackNotInList(list, stackFromBlockState))
595+
.forEach(list::add);
596+
return list;
597+
}
598+
561599
public List<Tuple<ItemStack, IBlockState>> getBlockStateIngredientList() {
562600
return samples.stream()
563601
.map(BlockInformation::getTupleIngredientFromBlockState)

src/main/java/ink/ikx/mmce/common/utils/StackUtils.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package ink.ikx.mmce.common.utils;
22

3+
import github.kasuminova.mmce.common.machine.pattern.SpecialItemBlockProxy;
4+
import github.kasuminova.mmce.common.machine.pattern.SpecialItemBlockProxyRegistry;
35
import hellfirepvp.modularmachinery.common.block.BlockController;
46
import net.minecraft.block.Block;
57
import net.minecraft.block.BlockLiquid;
@@ -9,6 +11,8 @@
911
import net.minecraft.item.Item;
1012
import net.minecraft.item.ItemBucket;
1113
import net.minecraft.item.ItemStack;
14+
import net.minecraft.util.math.BlockPos;
15+
import net.minecraft.world.World;
1216
import net.minecraftforge.fluids.*;
1317

1418
import java.util.List;
@@ -38,6 +42,15 @@ public static ItemStack getStackFromBlockState(IBlockState state) {
3842
return new ItemStack(Item.getItemFromBlock(block), 1, block.damageDropped(state));
3943
}
4044

45+
public static ItemStack getStackFromBlockState(IBlockState state, BlockPos pos, World world) {
46+
ItemStack rawStack = getStackFromBlockState(state);
47+
SpecialItemBlockProxy specialItemBlockProxy = SpecialItemBlockProxyRegistry.INSTANCE.getValidProxy(rawStack);
48+
if (specialItemBlockProxy != null) {
49+
return specialItemBlockProxy.getTrueStack(world.getBlockState(pos), world.getTileEntity(pos));
50+
}
51+
return rawStack;
52+
}
53+
4154
public static ItemStack hasStacks(List<ItemStack> inputStacks, List<ItemStack> outputStacks, boolean isRemove) {
4255
return outputStacks.stream().filter(stack -> isNotEmpty(hasStack(stack, inputStacks, isRemove))).findFirst().orElse(ItemStack.EMPTY);
4356
}

0 commit comments

Comments
 (0)