Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added index to shape info for multiblock preview #2171

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import net.minecraft.util.EnumHand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.fml.relauncher.Side;
Expand Down Expand Up @@ -67,6 +68,7 @@ public abstract class MultiblockControllerBase extends MetaTileEntity implements
private final Map<MultiblockAbility<Object>, List<Object>> multiblockAbilities = new HashMap<>();
private final List<IMultiblockPart> multiblockParts = new ArrayList<>();
private boolean structureFormed;
private int structureTier = 0;

protected EnumFacing upwardsFacing = EnumFacing.NORTH;
protected boolean isFlipped;
Expand Down Expand Up @@ -388,6 +390,33 @@ public List<IMultiblockPart> getMultiblockParts() {
return Collections.unmodifiableList(multiblockParts);
}

/**
* Grabs the current tier of the multi(whether in DummyWorld or Server) useful for whatever you want
*/
public int getStructureTier() {
return this.structureTier;
}

/**
* sets the tier of the multi clamped between 1 and maxTier()
*/
public void setStructureTier(int structureTier) {
if (this.structureTier != structureTier) {
this.structureTier = MathHelper.clamp(structureTier, 0, getMaxStructureTier());
if (getWorld() != null && !getWorld().isRemote) {
reinitializeStructurePattern();
}
}
}

/**
* Override if you are using the multiblock tiered system
* max tier of 0 means tiering is disabled
*/
public int getMaxStructureTier() {
return 0;
}

@Override
public void readFromNBT(NBTTagCompound data) {
super.readFromNBT(data);
Expand All @@ -397,6 +426,8 @@ public void readFromNBT(NBTTagCompound data) {
if (data.hasKey("IsFlipped")) {
this.isFlipped = data.getBoolean("IsFlipped");
}

structureTier = data.getInteger("structureTier");
this.reinitializeStructurePattern();
}

Expand All @@ -405,6 +436,7 @@ public NBTTagCompound writeToNBT(NBTTagCompound data) {
super.writeToNBT(data);
data.setByte("UpwardsFacing", (byte) upwardsFacing.getIndex());
data.setBoolean("IsFlipped", isFlipped);
data.setInteger("structureTier", structureTier);
return data;
}

Expand All @@ -414,6 +446,7 @@ public void writeInitialSyncData(PacketBuffer buf) {
buf.writeBoolean(structureFormed);
buf.writeByte(upwardsFacing.getIndex());
buf.writeBoolean(isFlipped);
buf.writeInt(structureTier);
}

@Override
Expand All @@ -422,6 +455,7 @@ public void receiveInitialSyncData(PacketBuffer buf) {
this.structureFormed = buf.readBoolean();
this.upwardsFacing = EnumFacing.VALUES[buf.readByte()];
this.isFlipped = buf.readBoolean();
this.structureTier = buf.readInt();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,12 @@ public Builder addFuelNeededLine(String fuelName, int previousRecipeDuration) {
return this;
}

public Builder addStructureTierLine(int tier) {
textList.add(TextComponentUtil.translationWithColor(TextFormatting.GRAY,
"gregtech.multiblock.structure_tier", tier));
return this;
}

/** Insert an empty line into the text list. */
public Builder addEmptyLine() {
textList.add(EMPTY_COMPONENT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class MultiblockPreviewRenderer {
private static long mbpEndTime;
private static int opList = -1;
private static int layer;
private static int tier;

public static void renderWorldLastEvent(RenderWorldLastEvent event) {
if (mbpPos != null) {
Expand All @@ -49,6 +50,7 @@ public static void renderWorldLastEvent(RenderWorldLastEvent event) {
if (opList == -1 || time > mbpEndTime || !(mc.world.getTileEntity(mbpPos) instanceof IGregTechTileEntity)) {
resetMultiblockRender();
layer = 0;
tier = 0;
return;
}
Entity entity = mc.getRenderViewEntity();
Expand Down Expand Up @@ -85,8 +87,14 @@ public static void renderMultiBlockPreview(MultiblockControllerBase controller,
mbpEndTime = System.currentTimeMillis() + durTimeMillis;
opList = GLAllocation.generateDisplayLists(1); // allocate op list
GlStateManager.glNewList(opList, GL11.GL_COMPILE);
if (tier != controller.getStructureTier()) {
tier = controller.getStructureTier();
controller.reinitializeStructurePattern();
}
List<MultiblockShapeInfo> shapes = controller.getMatchingShapes();
if (!shapes.isEmpty()) renderControllerInList(controller, shapes.get(0), layer);
if (!shapes.isEmpty()) {
renderControllerInList(controller, shapes.get(0), layer);
}
GlStateManager.glEndList();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,13 @@ public MBPattern(final WorldSceneRenderer sceneRenderer, final List<ItemStack> p
}

private final MultiblockControllerBase controller;
private final MBPattern[] patterns;
private MBPattern[] patterns;
private final Map<GuiButton, Runnable> buttons = new HashMap<>();
private RecipeLayout recipeLayout;
private final List<ItemStack> allItemStackInputs = new ArrayList<>();

private int layerIndex = -1;
private int tierIndex = 0;
private int currentRendererPage = 0;
private int lastMouseX;
private int lastMouseY;
Expand All @@ -109,6 +110,7 @@ public MBPattern(final WorldSceneRenderer sceneRenderer, final List<ItemStack> p
private final GuiButton buttonPreviousPattern;
private final GuiButton buttonNextPattern;
private final GuiButton nextLayerButton;
private final GuiButton nextTierButton;

private IDrawable slot;
private IDrawable infoIcon;
Expand All @@ -133,12 +135,16 @@ public MultiblockInfoRecipeWrapper(@NotNull MultiblockControllerBase controller)
this.buttonPreviousPattern = new GuiButton(0, 176 - ((2 * ICON_SIZE) + RIGHT_PADDING + 1), 90, ICON_SIZE,
ICON_SIZE, "<");
this.buttonNextPattern = new GuiButton(0, 176 - (ICON_SIZE + RIGHT_PADDING), 90, ICON_SIZE, ICON_SIZE, ">");
this.nextTierButton = new GuiButton(0, 176 - (ICON_SIZE + RIGHT_PADDING), 110, ICON_SIZE, ICON_SIZE, "^");
this.buttons.put(nextLayerButton, this::toggleNextLayer);
this.buttons.put(buttonPreviousPattern, () -> switchRenderPage(-1));
this.buttons.put(buttonNextPattern, () -> switchRenderPage(1));
this.buttons.put(nextTierButton, this::toggleNextTier);
boolean isPagesDisabled = patterns.length == 1;
this.buttonPreviousPattern.visible = !isPagesDisabled;
this.buttonNextPattern.visible = !isPagesDisabled;
boolean isTieringEnabled = controller.getMaxStructureTier() > 0;
this.nextTierButton.visible = isTieringEnabled;
this.predicates = new ArrayList<>();
}

Expand Down Expand Up @@ -210,6 +216,18 @@ private void toggleNextLayer() {
setNextLayer(layerIndex);
}

private void toggleNextTier() {
if (++this.tierIndex > controller.getMaxStructureTier()) {
this.tierIndex = 0;
}
this.controller.setStructureTier(tierIndex);
controller.reinitializeStructurePattern();
Set<ItemStack> drops = new ObjectOpenCustomHashSet<>(ItemStackHashStrategy.comparingAllButCount());
this.patterns = controller.getMatchingShapes().stream()
.map(it -> initializePattern(it, drops))
.toArray(MBPattern[]::new);
}

private void setNextLayer(int newLayer) {
this.layerIndex = newLayer;
this.nextLayerButton.displayString = "L:" + (layerIndex == -1 ? "A" : Integer.toString(layerIndex + 1));
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/assets/gregtech/lang/en_us.lang
Original file line number Diff line number Diff line change
Expand Up @@ -5598,6 +5598,8 @@ gregtech.multiblock.turbine.obstructed=Turbine Face Obstructed!
gregtech.multiblock.turbine.obstructed.desc=Turbine must have air space in the 3x3 in front of it.
gregtech.multiblock.turbine.efficiency_tooltip=Each Rotor Holder above %s§7 adds §f10%% efficiency§7.

gregtech.multiblock.structure_tier=Structure Tier:

gregtech.multiblock.large_boiler.efficiency=Efficiency: %s
gregtech.multiblock.large_boiler.steam_output=Steam Output: %s
gregtech.multiblock.large_boiler.throttle=Throttle: %s
Expand Down