Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#355 - Add support of IItemHandlers.
- Loading branch information
1 parent
37e4095
commit a820784
Showing
11 changed files
with
293 additions
and
138 deletions.
There are no files selected for viewing
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
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
6 changes: 2 additions & 4 deletions
6
src/main/java/mod/chiselsandbits/helpers/IContinuousInventory.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 |
---|---|---|
@@ -1,19 +1,17 @@ | ||
package mod.chiselsandbits.helpers; | ||
|
||
import mod.chiselsandbits.helpers.ModUtil.ItemStackSlot; | ||
|
||
public interface IContinuousInventory | ||
{ | ||
|
||
void useItem( | ||
boolean useItem( | ||
int blockId ); | ||
|
||
void fail( | ||
int blockId ); | ||
|
||
boolean isValid(); | ||
|
||
ItemStackSlot getItem( | ||
IItemInInventory getItem( | ||
int blockId ); | ||
|
||
} |
78 changes: 78 additions & 0 deletions
78
src/main/java/mod/chiselsandbits/helpers/IItemHandlerSlot.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,78 @@ | ||
package mod.chiselsandbits.helpers; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
import net.minecraft.item.ItemStack; | ||
import net.minecraftforge.items.IItemHandler; | ||
|
||
public class IItemHandlerSlot implements IItemInInventory | ||
{ | ||
|
||
private IItemHandler internal; | ||
private int zz; | ||
private @Nonnull ItemStack stack; // copy of itemstack | ||
private final @Nonnull ItemStack originalStack; | ||
private ActingPlayer src; | ||
private boolean isEditable; | ||
|
||
public IItemHandlerSlot( | ||
IItemHandler internal, | ||
int zz, | ||
ItemStack which, | ||
ActingPlayer src, | ||
boolean canEdit ) | ||
{ | ||
this.internal = internal; | ||
this.zz = zz; | ||
this.stack = ModUtil.copy( which ); | ||
this.originalStack = ModUtil.copy( which ); | ||
this.src = src; | ||
this.isEditable = canEdit; | ||
} | ||
|
||
@Override | ||
public boolean isValid() | ||
{ | ||
return isEditable && ( src.isCreative() || !ModUtil.isEmpty( stack ) && ModUtil.getStackSize( stack ) > 0 ); | ||
} | ||
|
||
@Override | ||
public void damage( | ||
ActingPlayer who ) | ||
{ | ||
throw new RuntimeException( "Cannot damage an item in an inventory?" ); | ||
} | ||
|
||
@Override | ||
public boolean consume() | ||
{ | ||
ItemStack is = internal.extractItem( zz, 1, true ); | ||
if ( is != null && ItemStack.areItemStackTagsEqual( is, stack ) && ItemStack.areItemStackTagsEqual( is, stack ) ) | ||
{ | ||
internal.extractItem( zz, 1, false ); | ||
ModUtil.adjustStackSize( stack, -1 ); | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
@Override | ||
public ItemStack getStack() | ||
{ | ||
return stack; | ||
} | ||
|
||
@Override | ||
public void swapWithWeapon() | ||
{ | ||
throw new RuntimeException( "Cannot swap an item in an inventory?" ); | ||
} | ||
|
||
@Override | ||
public ItemStack getStackType() | ||
{ | ||
return originalStack; | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/mod/chiselsandbits/helpers/IItemInInventory.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,21 @@ | ||
package mod.chiselsandbits.helpers; | ||
|
||
import net.minecraft.item.ItemStack; | ||
|
||
public interface IItemInInventory | ||
{ | ||
|
||
boolean isValid(); | ||
|
||
void damage( | ||
ActingPlayer who ); | ||
|
||
boolean consume(); | ||
|
||
ItemStack getStack(); | ||
|
||
void swapWithWeapon(); | ||
|
||
ItemStack getStackType(); | ||
|
||
} |
Oops, something went wrong.