-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
28 changed files
with
807 additions
and
243 deletions.
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
src/main/java/gregtech/api/capability/INotifiableHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package gregtech.api.capability; | ||
|
||
import gregtech.api.metatileentity.MetaTileEntity; | ||
|
||
/** | ||
* For Item and Fluid handlers capable of notifying entities when | ||
* their contents change | ||
*/ | ||
public interface INotifiableHandler { | ||
|
||
/** | ||
* Adds the notified handler to the notified list | ||
* | ||
* @param isExport boolean specifying if a handler is an output handler | ||
*/ | ||
|
||
default <T> void addToNotifiedList(MetaTileEntity metaTileEntity, T handler, boolean isExport) { | ||
if (metaTileEntity != null && metaTileEntity.isValid()) { | ||
if (isExport) { | ||
metaTileEntity.addNotifiedOutput(handler); | ||
} else { | ||
metaTileEntity.addNotifiedInput(handler); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* @param metaTileEntity MetaTileEntity to be notified | ||
*/ | ||
default void setNotifiableMetaTileEntity(MetaTileEntity metaTileEntity) { | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/main/java/gregtech/api/capability/impl/NotifiableFilteredFluidHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package gregtech.api.capability.impl; | ||
|
||
import gregtech.api.capability.INotifiableHandler; | ||
import gregtech.api.metatileentity.MetaTileEntity; | ||
|
||
public class NotifiableFilteredFluidHandler extends FilteredFluidHandler implements INotifiableHandler { | ||
|
||
MetaTileEntity notifiableEntity; | ||
private final boolean isExport; | ||
|
||
public NotifiableFilteredFluidHandler(int capacity, MetaTileEntity entityToNotify, boolean isExport) { | ||
super(capacity); | ||
this.notifiableEntity = entityToNotify; | ||
this.isExport = isExport; | ||
} | ||
|
||
@Override | ||
protected void onContentsChanged() { | ||
super.onContentsChanged(); | ||
addToNotifiedList(notifiableEntity, this, isExport); | ||
} | ||
|
||
@Override | ||
public void setNotifiableMetaTileEntity(MetaTileEntity metaTileEntity) { | ||
this.notifiableEntity = metaTileEntity; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/gregtech/api/capability/impl/NotifiableFluidTank.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package gregtech.api.capability.impl; | ||
|
||
import gregtech.api.capability.INotifiableHandler; | ||
import gregtech.api.metatileentity.MetaTileEntity; | ||
import net.minecraftforge.fluids.FluidTank; | ||
|
||
public class NotifiableFluidTank extends FluidTank implements INotifiableHandler { | ||
|
||
MetaTileEntity notifiableEntity; | ||
private final boolean isExport; | ||
|
||
public NotifiableFluidTank(int capacity, MetaTileEntity entityToNotify, boolean isExport) { | ||
super(capacity); | ||
this.notifiableEntity = entityToNotify; | ||
this.isExport = isExport; | ||
} | ||
|
||
@Override | ||
protected void onContentsChanged() { | ||
super.onContentsChanged(); | ||
addToNotifiedList(notifiableEntity, this, isExport); | ||
} | ||
|
||
@Override | ||
public void setNotifiableMetaTileEntity(MetaTileEntity metaTileEntity) { | ||
this.notifiableEntity = metaTileEntity; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/gregtech/api/capability/impl/NotifiableItemStackHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package gregtech.api.capability.impl; | ||
|
||
import gregtech.api.capability.INotifiableHandler; | ||
import gregtech.api.metatileentity.MetaTileEntity; | ||
import net.minecraftforge.items.IItemHandlerModifiable; | ||
import net.minecraftforge.items.ItemStackHandler; | ||
|
||
public class NotifiableItemStackHandler extends ItemStackHandler implements IItemHandlerModifiable, INotifiableHandler { | ||
|
||
MetaTileEntity notifiableEntity; | ||
private final boolean isExport; | ||
|
||
public NotifiableItemStackHandler(int slots, MetaTileEntity entityToNotify, boolean isExport) { | ||
super(slots); | ||
this.notifiableEntity = entityToNotify; | ||
this.isExport = isExport; | ||
} | ||
|
||
@Override | ||
public void onContentsChanged(int slot) { | ||
super.onContentsChanged(slot); | ||
addToNotifiedList(notifiableEntity, this, isExport); | ||
} | ||
|
||
@Override | ||
public void setNotifiableMetaTileEntity(MetaTileEntity metaTileEntity) { | ||
this.notifiableEntity = metaTileEntity; | ||
} | ||
} |
Oops, something went wrong.