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