Skip to content

Commit

Permalink
Remove IEdibleBlock.isEdibleAtMaxHunger since it has no use case
Browse files Browse the repository at this point in the history
The field usage is internal to the implementing class so it's better to simplify the interface than include a probably useless method
  • Loading branch information
squeek502 committed Dec 10, 2017
1 parent eaf5b55 commit eba6600
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 50 deletions.
6 changes: 0 additions & 6 deletions java/squeek/applecore/api/food/IEdibleBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@
*/
public interface IEdibleBlock extends IEdible
{
/**
* The IEdibleBlock equivalent of {@link ItemFood#alwaysEdible}.
* Should return true if the food can be eaten when at max hunger.
*/
public boolean isEdibleAtMaxHunger();

/**
* The IEdibleBlock equivalent of {@link ItemFood#setAlwaysEdible}.
* Should set whether or not the food can be eaten when at max hunger.
Expand Down
37 changes: 6 additions & 31 deletions java/squeek/applecore/asm/module/ModuleBlockFood.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,12 @@ private void implementIEdibleBlock(ClassNode classNode)

classNode.fields.add(new FieldNode(ACC_PUBLIC, isEdibleAtMaxHungerField, "Z", null, null));

tryAddFieldGetter(classNode, "isEdibleAtMaxHunger", isEdibleAtMaxHungerField, "Z");
tryAddFieldSetter(classNode, "setEdibleAtMaxHunger", isEdibleAtMaxHungerField, "Z");
mv = classNode.visitMethod(ACC_PUBLIC, "setEdibleAtMaxHunger", ASMHelper.toMethodDescriptor("V", "Z"), null, null);
mv.visitVarInsn(ALOAD, 0);
mv.visitVarInsn(ILOAD, 1);
mv.visitFieldInsn(PUTFIELD, ASMHelper.toInternalClassName(classNode.name), isEdibleAtMaxHungerField, "Z");
mv.visitInsn(RETURN);
mv.visitMaxs(0, 0);
}

private void addOnBlockFoodEatenHook(ClassNode classNode, MethodNode method)
Expand Down Expand Up @@ -112,33 +116,4 @@ private void addAlwaysEdibleCheck(ClassNode classNode, MethodNode method)
method.instructions.insert(pushFalse, pushField);
method.instructions.remove(pushFalse);
}

private boolean tryAddFieldGetter(ClassNode classNode, String methodName, String fieldName, String fieldDescriptor)
{
String methodDescriptor = ASMHelper.toMethodDescriptor(fieldDescriptor);
if (ASMHelper.findMethodNodeOfClass(classNode, methodName, methodDescriptor) != null)
return false;

MethodVisitor mv = classNode.visitMethod(ACC_PUBLIC, methodName, methodDescriptor, null, null);
mv.visitVarInsn(ALOAD, 0);
mv.visitFieldInsn(GETFIELD, ASMHelper.toInternalClassName(classNode.name), fieldName, fieldDescriptor);
mv.visitInsn(Type.getType(fieldDescriptor).getOpcode(IRETURN));
mv.visitMaxs(0, 0);
return true;
}

private boolean tryAddFieldSetter(ClassNode classNode, String methodName, String fieldName, String fieldDescriptor)
{
String methodDescriptor = ASMHelper.toMethodDescriptor("V", fieldDescriptor);
if (ASMHelper.findMethodNodeOfClass(classNode, methodName, methodDescriptor) != null)
return false;

MethodVisitor mv = classNode.visitMethod(ACC_PUBLIC, methodName, methodDescriptor, null, null);
mv.visitVarInsn(ALOAD, 0);
mv.visitVarInsn(Type.getType(fieldDescriptor).getOpcode(ILOAD), 1);
mv.visitFieldInsn(PUTFIELD, ASMHelper.toInternalClassName(classNode.name), fieldName, fieldDescriptor);
mv.visitInsn(RETURN);
mv.visitMaxs(0, 0);
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,6 @@ private void func_150036_b(World p_150036_1_, int p_150036_2_, int p_150036_3_,
// All of the following added by AppleCore
private boolean AppleCore_isEdibleAtMaxHunger;

@Override
public boolean isEdibleAtMaxHunger()
{
return AppleCore_isEdibleAtMaxHunger;
}

@Override
public void setEdibleAtMaxHunger(boolean value)
{
Expand Down
7 changes: 0 additions & 7 deletions java/squeek/applecore/example/BlockEdibleExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@ public class BlockEdibleExample extends BlockCake implements IEdibleBlock
{
private boolean isEdibleAtMaxHunger = false;

@Optional.Method(modid = "AppleCore")
@Override
public boolean isEdibleAtMaxHunger()
{
return isEdibleAtMaxHunger;
}

@Optional.Method(modid = "AppleCore")
@Override
public void setEdibleAtMaxHunger(boolean value)
Expand Down

0 comments on commit eba6600

Please sign in to comment.