More refactor
This commit is contained in:
parent
04e03cac07
commit
a283ca1951
4 changed files with 27 additions and 30 deletions
|
@ -30,7 +30,6 @@ public class AnvilScreenMixin extends ItemCombinerScreen<AnvilMenu> {
|
|||
private EditBox name;
|
||||
|
||||
private final List<AbstractWidget> be_buttons = Lists.newArrayList();
|
||||
private AnvilScreenHandlerExtended anvilHandler;
|
||||
|
||||
public AnvilScreenMixin(AnvilMenu handler, Inventory playerInventory, Component title,
|
||||
ResourceLocation texture) {
|
||||
|
@ -38,18 +37,17 @@ public class AnvilScreenMixin extends ItemCombinerScreen<AnvilMenu> {
|
|||
}
|
||||
|
||||
@Inject(method = "subInit", at = @At("TAIL"))
|
||||
protected void be_setup(CallbackInfo info) {
|
||||
protected void be_subInit(CallbackInfo info) {
|
||||
int x = (width - imageWidth) / 2;
|
||||
int y = (height - imageHeight) / 2;
|
||||
anvilHandler = (AnvilScreenHandlerExtended) menu;
|
||||
be_buttons.clear();
|
||||
be_buttons.add(new Button(x + 8, y + 45, 15, 20, new TextComponent("<"), (b) -> be_previousRecipe()));
|
||||
be_buttons.add(new Button(x + 154, y + 45, 15, 20, new TextComponent(">"), (b) -> be_nextRecipe()));
|
||||
be_buttons.add(new Button(x + 8, y + 45, 15, 20, new TextComponent("<"), b -> be_previousRecipe()));
|
||||
be_buttons.add(new Button(x + 154, y + 45, 15, 20, new TextComponent(">"), b -> be_nextRecipe()));
|
||||
}
|
||||
|
||||
@Inject(method = "renderFg", at = @At("TAIL"))
|
||||
protected void be_renderForeground(PoseStack matrices, int mouseX, int mouseY, float delta, CallbackInfo info) {
|
||||
this.be_buttons.forEach(button -> {
|
||||
be_buttons.forEach(button -> {
|
||||
button.render(matrices, mouseX, mouseY, delta);
|
||||
});
|
||||
}
|
||||
|
@ -59,23 +57,23 @@ public class AnvilScreenMixin extends ItemCombinerScreen<AnvilMenu> {
|
|||
AnvilScreenHandlerExtended anvilHandler = (AnvilScreenHandlerExtended) handler;
|
||||
if (anvilHandler.be_getCurrentRecipe() != null) {
|
||||
if (anvilHandler.be_getRecipes().size() > 1) {
|
||||
this.be_buttons.forEach(button -> button.visible = true);
|
||||
be_buttons.forEach(button -> button.visible = true);
|
||||
} else {
|
||||
this.be_buttons.forEach(button -> button.visible = false);
|
||||
be_buttons.forEach(button -> button.visible = false);
|
||||
}
|
||||
this.name.setValue("");
|
||||
name.setValue("");
|
||||
info.cancel();
|
||||
} else {
|
||||
this.be_buttons.forEach(button -> button.visible = false);
|
||||
be_buttons.forEach(button -> button.visible = false);
|
||||
}
|
||||
}
|
||||
|
||||
private void be_nextRecipe() {
|
||||
anvilHandler.be_nextRecipe();
|
||||
((AnvilScreenHandlerExtended) menu).be_nextRecipe();
|
||||
}
|
||||
|
||||
private void be_previousRecipe() {
|
||||
anvilHandler.be_previousRecipe();
|
||||
((AnvilScreenHandlerExtended) menu).be_previousRecipe();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -19,10 +19,8 @@ public class AnvilBlockMixin {
|
|||
try {
|
||||
BlockState state = fallingState.setValue(destructionProperty, destruction + 1);
|
||||
info.setReturnValue(state);
|
||||
info.cancel();
|
||||
} catch (Exception ex) {
|
||||
info.setReturnValue(null);
|
||||
info.cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,17 +38,18 @@ public abstract class AnvilMenuMixin extends ItemCombinerMenu implements AnvilSc
|
|||
|
||||
@Inject(method = "<init>(ILnet/minecraft/world/entity/player/Inventory;Lnet/minecraft/world/inventory/ContainerLevelAccess;)V", at = @At("TAIL"))
|
||||
public void be_initAnvilLevel(int syncId, Inventory inventory, ContainerLevelAccess context, CallbackInfo info) {
|
||||
this.anvilLevel = addDataSlot(DataSlot.standalone());
|
||||
if (context != ContainerLevelAccess.NULL) {
|
||||
int anvLevel = context.evaluate((world, blockPos) -> {
|
||||
int level = context.evaluate((world, blockPos) -> {
|
||||
Block anvilBlock = world.getBlockState(blockPos).getBlock();
|
||||
if (anvilBlock instanceof EndAnvilBlock) {
|
||||
return ((EndAnvilBlock) anvilBlock).getCraftingLevel();
|
||||
}
|
||||
return 1;
|
||||
}, 1);
|
||||
DataSlot anvilLevel = DataSlot.standalone();
|
||||
anvilLevel.set(anvLevel);
|
||||
this.anvilLevel = addDataSlot(anvilLevel);
|
||||
anvilLevel.set(level);
|
||||
} else {
|
||||
anvilLevel.set(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -65,10 +66,10 @@ public abstract class AnvilMenuMixin extends ItemCombinerMenu implements AnvilSc
|
|||
@Inject(method = "onTake", at = @At("HEAD"), cancellable = true)
|
||||
protected void be_onTakeOutput(Player player, ItemStack stack, CallbackInfoReturnable<ItemStack> info) {
|
||||
if (be_currentRecipe != null) {
|
||||
this.inputSlots.getItem(0).shrink(be_currentRecipe.getInputCount());
|
||||
inputSlots.getItem(0).shrink(be_currentRecipe.getInputCount());
|
||||
stack = be_currentRecipe.craft(inputSlots, player);
|
||||
this.slotsChanged(inputSlots);
|
||||
this.access.execute((world, blockPos) -> {
|
||||
slotsChanged(inputSlots);
|
||||
access.execute((world, blockPos) -> {
|
||||
BlockState anvilState = world.getBlockState(blockPos);
|
||||
if (!player.abilities.instabuild && anvilState.is(BlockTags.ANVIL) && player.getRandom().nextFloat() < 0.12F) {
|
||||
BlockState landingState = AnvilBlock.damage(anvilState);
|
||||
|
@ -117,10 +118,10 @@ public abstract class AnvilMenuMixin extends ItemCombinerMenu implements AnvilSc
|
|||
@Override
|
||||
public boolean clickMenuButton(Player player, int id) {
|
||||
if (id == 0) {
|
||||
this.be_previousRecipe();
|
||||
be_previousRecipe();
|
||||
return true;
|
||||
} else if (id == 1) {
|
||||
this.be_nextRecipe();
|
||||
be_nextRecipe();
|
||||
return true;
|
||||
}
|
||||
return super.clickMenuButton(player, id);
|
||||
|
@ -128,23 +129,23 @@ public abstract class AnvilMenuMixin extends ItemCombinerMenu implements AnvilSc
|
|||
|
||||
private void be_updateResult() {
|
||||
if (be_currentRecipe == null) return;
|
||||
this.resultSlots.setItem(0, be_currentRecipe.assemble(inputSlots));
|
||||
this.broadcastChanges();
|
||||
resultSlots.setItem(0, be_currentRecipe.assemble(inputSlots));
|
||||
broadcastChanges();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void be_updateCurrentRecipe(AnvilRecipe recipe) {
|
||||
this.be_currentRecipe = recipe;
|
||||
this.be_updateResult();
|
||||
be_updateResult();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AnvilRecipe be_getCurrentRecipe() {
|
||||
return this.be_currentRecipe;
|
||||
return be_currentRecipe;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AnvilRecipe> be_getRecipes() {
|
||||
return this.be_recipes;
|
||||
return be_recipes;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,9 +27,9 @@
|
|||
"LivingEntityMixin",
|
||||
"ServerPlayerMixin",
|
||||
"SpikeFeatureMixin",
|
||||
"ServerLevelMixin",
|
||||
"AnvilBlockMixin",
|
||||
"PlayerListMixin",
|
||||
"ServerLevelMixin",
|
||||
"AnvilMenuMixin",
|
||||
"TagLoaderMixin",
|
||||
"EnderManMixin",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue