Skip to content

Commit

Permalink
Backward compatible API update: added optional onRemove() method to I…
Browse files Browse the repository at this point in the history
…PanelCell interface which is called just before a cell is removed or its panel is broken.

This was added to support add-on mods (such as the soon-to-be released wireless redstone add-on) with cells that need to perform some action when they are removed from the world.
  • Loading branch information
dannydjdk committed Sep 23, 2021
1 parent 14416ad commit 9b1e1bc
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ apply plugin: 'net.minecraftforge.gradle'
apply plugin: 'eclipse'
apply plugin: 'maven-publish'

version = '1.17.1-2.2.7'
version = '1.17.1-2.2.9'
group = 'com.dannyandson.tinyredstone' // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = 'tinyredstone'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,10 @@ default void setBaseSide(Side side){}
*/
default PanelCellVoxelShape getShape() {return PanelCellVoxelShape.FULLCELL;}

/**
* Called just before the cell is removed from the panel
* @param cellPos PanelCellPos object of this cell
*/
default void onRemove(PanelCellPos cellPos){}

}
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,10 @@ private ItemStack getItemWithNBT(BlockGetter worldIn, BlockPos pos, BlockState s
*/
@Override
public void playerWillDestroy(Level worldIn, BlockPos pos, BlockState state, Player player) {
if (worldIn.getBlockEntity(pos) instanceof PanelTile panelTile){
panelTile.onBlockDestroy();
}

if(!player.isCreative()) {
ItemStack itemstack = getItemWithNBT(worldIn, pos, state);
if(itemstack != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1148,6 +1148,8 @@ public void removeCell(PanelCellPos cellPos)
int cellIndex = cellPos.getIndex();
boolean isRedstoneDust = cellPos.getIPanelCell() instanceof RedstoneDust;

cellPos.getIPanelCell().onRemove(cellPos);

//remove from panel
cellDirections.remove(cellIndex);
cells.remove(cellIndex);
Expand Down Expand Up @@ -1282,6 +1284,13 @@ public void clearVoxelShape()
{
voxelShape=null;
}

public void onBlockDestroy() {
for (Integer index : cells.keySet()) {
PanelCellPos pos = PanelCellPos.fromIndex(this, index);
pos.getIPanelCell().onRemove(pos);
}
}
}


0 comments on commit 9b1e1bc

Please sign in to comment.