11package 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 ;
38import static gregtech .api .util .GTStructureUtility .ofHatchAdderOptional ;
49
510import java .util .ArrayList ;
4045import com .cubefury .vendingmachine .trade .TradeManager ;
4146import com .cubefury .vendingmachine .trade .TradeRequest ;
4247import com .cubefury .vendingmachine .util .BigItemStack ;
48+ import com .cubefury .vendingmachine .util .OverlayHelper ;
4349import com .gtnewhorizon .structurelib .StructureLibAPI ;
4450import com .gtnewhorizon .structurelib .alignment .IAlignment ;
4551import com .gtnewhorizon .structurelib .alignment .IAlignmentLimits ;
5258import gregtech .api .GregTechAPI ;
5359import gregtech .api .covers .CoverRegistry ;
5460import gregtech .api .enums .Textures ;
61+ import gregtech .api .interfaces .IIconContainer ;
5562import gregtech .api .interfaces .ISecondaryDescribable ;
5663import gregtech .api .interfaces .ITexture ;
5764import gregtech .api .interfaces .metatileentity .IMetaTileEntity ;
5865import gregtech .api .interfaces .tileentity .IGregTechTileEntity ;
5966import gregtech .api .metatileentity .implementations .MTEMultiBlockBase ;
67+ import gregtech .api .render .RenderOverlay ;
6068import gregtech .api .render .TextureFactory ;
6169import gregtech .api .util .GTUtil ;
6270import 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 ())) {
0 commit comments