Skip to content

Commit c49a53b

Browse files
authored
Add textures (#10)
* Swapped controller texture * Added overlay for active vending machine * Remove trailing commas * Removed texture interpolation for animation * Update README.md * Changed output slots to 6 (from 4)
1 parent 841d6bf commit c49a53b

26 files changed

Lines changed: 261 additions & 22 deletions

README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,26 @@
22

33
This mod adds a vending machine, unlocking trades based on questbook data. If you have AE2 installed, it will also add an AE2 vending terminal, which will allow you perform trades directly with items from your ME system.
44

5+
### Structure
6+
7+
![img.png](img.png)
8+
9+
### Interface
10+
![img_1.png](img_1.png)
11+
512
## Current Status
613

7-
WIP
14+
Alpha Testing
815

916
## For Non-GTNH Modpacks
1017

11-
This can be used as a standalone mod with several dependencies. The vending machine block and ME Vending terminal do not come with default recipes.
18+
This can be used as a standalone mod with several dependencies. The vending machine block and ME Vending Uplink do not come with default recipes.
1219

1320
### Required Dependencies:
21+
- GT5U
1422
- ModularUI 2
23+
- NotEnoughItems
24+
- Applied Energistics 2
1525

1626
### Optional Dependencies:
1727
- BetterQuesting

img.png

69.4 KB
Loading

img_1.png

126 KB
Loading
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.cubefury.vendingmachine.api.enums;
2+
3+
import gregtech.api.enums.Textures.BlockIcons.CustomIcon;
4+
import gregtech.api.interfaces.IIconContainer;
5+
6+
public class Textures {
7+
8+
public static final CustomIcon VM_MACHINE_FRONT_OFF = new CustomIcon("vendingmachine:vending_machine_front_off"),
9+
VM_MACHINE_FRONT_ON = new CustomIcon("vendingmachine:vending_machine_front_on"),
10+
VM_MACHINE_FRONT_ON_GLOW = new CustomIcon("vendingmachine:vending_machine_front_on_glow"),
11+
12+
VM_OVERLAY_0 = new CustomIcon("vendingmachine:vending_machine_overlay_0"),
13+
VM_OVERLAY_1 = new CustomIcon("vendingmachine:vending_machine_overlay_1"),
14+
VM_OVERLAY_2 = new CustomIcon("vendingmachine:vending_machine_overlay_2"),
15+
VM_OVERLAY_3 = new CustomIcon("vendingmachine:vending_machine_overlay_3"),
16+
VM_OVERLAY_4 = new CustomIcon("vendingmachine:vending_machine_overlay_4"),
17+
18+
VM_OVERLAY_ACTIVE_0 = new CustomIcon("vendingmachine:vending_machine_overlay_active_0"),
19+
VM_OVERLAY_ACTIVE_1 = new CustomIcon("vendingmachine:vending_machine_overlay_active_1"),
20+
VM_OVERLAY_ACTIVE_2 = new CustomIcon("vendingmachine:vending_machine_overlay_active_2"),
21+
VM_OVERLAY_ACTIVE_3 = new CustomIcon("vendingmachine:vending_machine_overlay_active_3");
22+
23+
public static final IIconContainer[] VM_OVERLAY_ACTIVE = { VM_OVERLAY_ACTIVE_0, VM_OVERLAY_ACTIVE_1,
24+
VM_OVERLAY_ACTIVE_2, VM_OVERLAY_ACTIVE_3, VM_OVERLAY_4 // bottom right not animated
25+
};
26+
27+
public static final IIconContainer[] VM_OVERLAY = { VM_OVERLAY_0, VM_OVERLAY_1, VM_OVERLAY_2, VM_OVERLAY_3,
28+
VM_OVERLAY_4 };
29+
30+
}

src/main/java/com/cubefury/vendingmachine/blocks/MTEVendingMachine.java

Lines changed: 66 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package com.cubefury.vendingmachine.blocks;
22

3+
import static com.cubefury.vendingmachine.api.enums.Textures.VM_MACHINE_FRONT_OFF;
4+
import static com.cubefury.vendingmachine.api.enums.Textures.VM_MACHINE_FRONT_ON;
5+
import static com.cubefury.vendingmachine.api.enums.Textures.VM_MACHINE_FRONT_ON_GLOW;
6+
import static com.cubefury.vendingmachine.api.enums.Textures.VM_OVERLAY;
7+
import static com.cubefury.vendingmachine.api.enums.Textures.VM_OVERLAY_ACTIVE;
38
import static gregtech.api.util.GTStructureUtility.ofHatchAdderOptional;
49

510
import java.util.ArrayList;
@@ -40,6 +45,7 @@
4045
import com.cubefury.vendingmachine.trade.TradeManager;
4146
import com.cubefury.vendingmachine.trade.TradeRequest;
4247
import com.cubefury.vendingmachine.util.BigItemStack;
48+
import com.cubefury.vendingmachine.util.OverlayHelper;
4349
import com.gtnewhorizon.structurelib.StructureLibAPI;
4450
import com.gtnewhorizon.structurelib.alignment.IAlignment;
4551
import com.gtnewhorizon.structurelib.alignment.IAlignmentLimits;
@@ -52,11 +58,13 @@
5258
import gregtech.api.GregTechAPI;
5359
import gregtech.api.covers.CoverRegistry;
5460
import gregtech.api.enums.Textures;
61+
import gregtech.api.interfaces.IIconContainer;
5562
import gregtech.api.interfaces.ISecondaryDescribable;
5663
import gregtech.api.interfaces.ITexture;
5764
import gregtech.api.interfaces.metatileentity.IMetaTileEntity;
5865
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
5966
import gregtech.api.metatileentity.implementations.MTEMultiBlockBase;
67+
import gregtech.api.render.RenderOverlay;
6068
import gregtech.api.render.TextureFactory;
6169
import gregtech.api.util.GTUtil;
6270
import gregtech.api.util.GTUtility;
@@ -82,26 +90,26 @@ public class MTEVendingMachine extends MTEMultiBlockBase
8290
private final ArrayList<MTEVendingUplinkHatch> uplinkHatches = new ArrayList<>();
8391

8492
public static final int INPUT_SLOTS = 6;
85-
public static final int OUTPUT_SLOTS = 4;
93+
public static final int OUTPUT_SLOTS = 6;
8694

8795
public static final int MAX_TRADES = 300;
8896

8997
public static final int STRUCTURE_CHECK_TICKS = 20;
9098

9199
private static final ITexture[] FACING_SIDE = {
92100
TextureFactory.of(Textures.BlockIcons.MACHINE_CASING_ITEM_PIPE_TIN) };
93-
private static final ITexture[] FACING_FRONT = {
94-
TextureFactory.of(Textures.BlockIcons.MACHINE_CASING_BRICKEDBLASTFURNACE_INACTIVE) };
95-
private static final ITexture[] FACING_ACTIVE = {
96-
TextureFactory.of(Textures.BlockIcons.MACHINE_CASING_BRICKEDBLASTFURNACE_ACTIVE), TextureFactory.builder()
97-
.addIcon(Textures.BlockIcons.MACHINE_CASING_BRICKEDBLASTFURNACE_ACTIVE_GLOW)
98-
.glow()
99-
.build() };
101+
private static final ITexture[] FACING_FRONT = { TextureFactory.of(VM_MACHINE_FRONT_OFF) };
102+
private static final ITexture[] FACING_ACTIVE = { TextureFactory.of(VM_MACHINE_FRONT_ON), TextureFactory.builder()
103+
.addIcon(VM_MACHINE_FRONT_ON_GLOW)
104+
.glow()
105+
.build() };
106+
protected final List<RenderOverlay.OverlayTicket> overlayTickets = new ArrayList<>();
100107

101108
private MultiblockTooltipBuilder tooltipBuilder;
102109

103110
public int mUpdate = 0;
104111
public boolean mMachine = false;
112+
private boolean mIsAnimated;
105113

106114
public ItemStackHandler inputItems = new ItemStackHandler(INPUT_SLOTS);
107115
public ItemStackHandler outputItems = new ItemStackHandler(OUTPUT_SLOTS);
@@ -118,17 +126,24 @@ public class MTEVendingMachine extends MTEMultiBlockBase
118126

119127
public MTEVendingMachine(final int aID, final String aName, final String aNameRegional) {
120128
super(aID, aName, aNameRegional);
129+
this.mIsAnimated = true;
121130
}
122131

123132
protected MTEVendingMachine(String aName) {
124133
super(aName);
134+
this.mIsAnimated = true;
125135
}
126136

127137
@Override
128138
public IMetaTileEntity newMetaEntity(IGregTechTileEntity aTileEntity) {
129139
return new MTEVendingMachine(this.mName);
130140
}
131141

142+
public boolean usingAnimations() {
143+
// Logger.INFO("Is animated? "+this.mIsAnimated);
144+
return this.mIsAnimated;
145+
}
146+
132147
public void sendTradeRequest(TradeItemDisplay trade) {
133148
IGregTechTileEntity baseTile = getBaseMetaTileEntity();
134149
if (baseTile == null) {
@@ -374,11 +389,32 @@ public boolean isFacingValid(ForgeDirection facing) {
374389
public ITexture[] getTexture(IGregTechTileEntity baseMetaTileEntity, ForgeDirection side, ForgeDirection facing,
375390
int colorIndex, boolean active, boolean redstoneLevel) {
376391
if (side == facing) {
392+
if (baseMetaTileEntity == null) {
393+
return FACING_FRONT;
394+
}
377395
return active ? FACING_ACTIVE : FACING_FRONT;
378396
}
379397
return FACING_SIDE;
380398
}
381399

400+
protected void setTextureOverlay() {
401+
IGregTechTileEntity tile = getBaseMetaTileEntity();
402+
if (tile == null || tile.isServerSide()) return;
403+
404+
IIconContainer[] vmTextures;
405+
if (getBaseMetaTileEntity().isActive() && usingAnimations()) vmTextures = VM_OVERLAY_ACTIVE;
406+
else vmTextures = VM_OVERLAY;
407+
408+
OverlayHelper.setVMOverlay(
409+
tile.getWorld(),
410+
tile.getXCoord(),
411+
tile.getYCoord(),
412+
tile.getZCoord(),
413+
getExtendedFacing(),
414+
vmTextures,
415+
overlayTickets);
416+
}
417+
382418
@Override
383419
public String[] getDescription() {
384420
return getCurrentDescription();
@@ -460,7 +496,16 @@ public ExtendedFacing getExtendedFacing() {
460496

461497
@Override
462498
public void setExtendedFacing(ExtendedFacing alignment) {
499+
boolean extendedFacingChanged = alignment != getExtendedFacing();
463500
getBaseMetaTileEntity().setFrontFacing(alignment.getDirection());
501+
if (extendedFacingChanged) {
502+
setTextureOverlay();
503+
}
504+
}
505+
506+
@Override
507+
public void onTextureUpdate() {
508+
setTextureOverlay();
464509
}
465510

466511
@Override
@@ -491,8 +536,8 @@ public boolean checkMachine(IGregTechTileEntity aBaseMetaTileEntity, ItemStack a
491536

492537
@Override
493538
public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTimer) {
494-
if ((aBaseMetaTileEntity.isClientSide()) && (aBaseMetaTileEntity.isActive())) {
495-
// spawn something maybe
539+
if (aBaseMetaTileEntity.isClientSide() && !aBaseMetaTileEntity.isActive()) {
540+
OverlayHelper.clearVMOverlay(overlayTickets);
496541
}
497542
if (aBaseMetaTileEntity.isServerSide()) {
498543
dispenseItems();
@@ -537,7 +582,8 @@ public boolean inputItemsSatisfied(List<BigItemStack> fromItems) {
537582
ItemStack aeStackSearch = base.getBaseStack();
538583
aeStackSearch.stackSize = bis.stackSize;
539584
if (this.inputSlotCache.get(base) != null) {
540-
aeStackSearch.stackSize = Math.max(aeStackSearch.stackSize - this.inputSlotCache.get(base), 0);
585+
aeStackSearch.stackSize = Math
586+
.max(aeStackSearch.stackSize - this.inputSlotCache.getOrDefault(base, 0), 0);
541587
}
542588
if (aeStackSearch.stackSize == 0) {
543589
continue;
@@ -570,8 +616,10 @@ public boolean getActive() {
570616
@Override
571617
public void onFirstTick(IGregTechTileEntity aBaseMetaTileEntity) {
572618
super.onFirstTick(aBaseMetaTileEntity);
573-
if (aBaseMetaTileEntity.isClientSide())
619+
if (aBaseMetaTileEntity.isClientSide()) {
574620
StructureLibAPI.queryAlignment((IAlignmentProvider) aBaseMetaTileEntity);
621+
setTextureOverlay();
622+
}
575623
}
576624

577625
@Override
@@ -611,6 +659,12 @@ public void construct(ItemStack stackSize, boolean hintsOnly) {
611659
hintsOnly);
612660
}
613661

662+
@Override
663+
public void onRemoval() {
664+
super.onRemoval();
665+
if (getBaseMetaTileEntity().isClientSide()) OverlayHelper.clearVMOverlay(overlayTickets);
666+
}
667+
614668
@Override
615669
public boolean onRightclick(IGregTechTileEntity aBaseMetaTileEntity, EntityPlayer aPlayer) {
616670
if (GTUtil.hasMultiblockInputConfiguration(aPlayer.getHeldItem())) {

src/main/java/com/cubefury/vendingmachine/blocks/gui/MTEVendingMachineGui.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public ModularPanel build(PosGuiData guiData, PanelSyncManager syncManager, UISe
123123
.child(createTradeUI((TradeMainPanel) panel, this.tabController));
124124
mainColumn.child(createCoinInventoryRow((TradeMainPanel) panel));
125125
}
126-
mainColumn.child(createInventoryRow(panel, syncManager));
126+
mainColumn.child(createInventoryRow());
127127
panel.child(mainColumn);
128128
panel.child(
129129
new Column().size(20)
@@ -256,7 +256,7 @@ private void doEjectItems() {
256256
private IWidget createIOColumn(PanelSyncManager syncManager) {
257257
return new ParentWidget<>().excludeAreaInNEI()
258258
.width(50)
259-
.height(160)
259+
.height(178)
260260
.right(-48)
261261
.top(40)
262262
.widgetTheme(WidgetThemes.BACKGROUND_SIDEPANEL)
@@ -268,7 +268,7 @@ private IWidget createIOColumn(PanelSyncManager syncManager) {
268268
.width(30)
269269
.height(20))
270270
.child(
271-
new Row().child(createInputRow(syncManager).center())
271+
new Row().child(createInputRow().center())
272272
.top(20)
273273
.height(18 * 3))
274274
.child(
@@ -289,17 +289,17 @@ private IWidget createIOColumn(PanelSyncManager syncManager) {
289289
.child(
290290
GuiTextures.OUTPUT_SPRITE.asWidget()
291291
.leftRel(0.5f)
292-
.bottom(34)
292+
.bottom(52)
293293
.width(30)
294294
.height(20))
295295
.child(
296296
new Row().child(createOutputSlots().center())
297297
.bottom(6)
298-
.height(18 * 2))
298+
.height(18 * 3))
299299
.right(1));
300300
}
301301

302-
private SlotGroupWidget createInputRow(PanelSyncManager syncManager) {
302+
private SlotGroupWidget createInputRow() {
303303
return SlotGroupWidget.builder()
304304
.matrix("II", "II", "II")
305305
.key('I', index -> {
@@ -334,7 +334,7 @@ private SlotGroupWidget createInputRow(PanelSyncManager syncManager) {
334334

335335
private SlotGroupWidget createOutputSlots() {
336336
return SlotGroupWidget.builder()
337-
.matrix("II", "II")
337+
.matrix("II", "II", "II")
338338
.key('I', index -> {
339339
ModularSlot ms = new ModularSlot(base.outputItems, index).accessibility(false, true)
340340
.slotGroup("outputSlotGroup");
@@ -474,7 +474,7 @@ private IWidget createCoinInventoryRow(TradeMainPanel panel) {
474474
}
475475

476476
// why is the original method private lmao
477-
private IWidget createInventoryRow(ModularPanel panel, PanelSyncManager syncManager) {
477+
private IWidget createInventoryRow() {
478478
return new Row().widthRel(1)
479479
.height(76)
480480
.alignX(0)
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package com.cubefury.vendingmachine.util;
2+
3+
import java.util.List;
4+
5+
import net.minecraft.world.World;
6+
import net.minecraftforge.common.util.ForgeDirection;
7+
8+
import com.gtnewhorizon.structurelib.alignment.enumerable.ExtendedFacing;
9+
10+
import gregtech.api.interfaces.IIconContainer;
11+
import gregtech.api.render.RenderOverlay;
12+
import gregtech.api.render.TextureFactory;
13+
14+
public class OverlayHelper {
15+
16+
private static final int[] vmX = new int[] { -1, 0, -1, -1, 0 };
17+
private static final int[] vmY = new int[] { -1, -1, 0, 1, 1 };
18+
19+
public static void clearVMOverlay(List<RenderOverlay.OverlayTicket> overlayTickets) {
20+
overlayTickets.forEach(RenderOverlay.OverlayTicket::remove);
21+
overlayTickets.clear();
22+
}
23+
24+
/**
25+
* Texture Display Front View
26+
* -----
27+
* 0 | 1
28+
* 2 | ~
29+
* 3 | 4
30+
* -----
31+
* Only 0-3 are animated
32+
* 4 is a static texture without glow
33+
*/
34+
public static void setVMOverlay(World world, int x, short y, int z, ExtendedFacing facing,
35+
IIconContainer[] vmTextures, List<RenderOverlay.OverlayTicket> overlayTickets) {
36+
clearVMOverlay(overlayTickets);
37+
38+
int[] tXYZOffset = new int[3];
39+
final ForgeDirection tDirection = facing.getDirection();
40+
facing = ExtendedFacing.of(tDirection);
41+
42+
RenderOverlay overlay = RenderOverlay.getOrCreate(world);
43+
44+
for (int i = 0; i < 5; i++) {
45+
int[] tABCCoord = new int[] { vmX[i], vmY[i], 0 };
46+
47+
facing.getWorldOffset(tABCCoord, tXYZOffset);
48+
int tX = tXYZOffset[0] + x;
49+
int tY = tXYZOffset[1] + y;
50+
int tZ = tXYZOffset[2] + z;
51+
52+
if (i == 4) { // bottom right
53+
overlayTickets.add(overlay.set(x, y, z, tX, tY, tZ, tDirection, TextureFactory.of(vmTextures[i]), 0));
54+
} else {
55+
overlayTickets.add(
56+
overlay.set(
57+
x,
58+
y,
59+
z,
60+
tX,
61+
tY,
62+
tZ,
63+
tDirection,
64+
TextureFactory.builder()
65+
.addIcon(vmTextures[i])
66+
.glow()
67+
.build(),
68+
0));
69+
}
70+
}
71+
}
72+
}
699 Bytes
Loading
693 Bytes
Loading
325 Bytes
Loading

0 commit comments

Comments
 (0)