This commit is contained in:
paulevsGitch 2021-01-05 02:17:20 +03:00
commit c240576185
24 changed files with 216 additions and 26 deletions

Binary file not shown.

View file

@ -0,0 +1,11 @@
package ru.betterend.interfaces;
import java.util.List;
import ru.betterend.recipe.builders.AnvilSmithingRecipe;
public interface AnvilScreenHandlerExtended {
public void be_updateCurrentRecipe(AnvilSmithingRecipe recipe);
public AnvilSmithingRecipe be_getCurrentRecipe();
public List<AnvilSmithingRecipe> be_getRecipes();
}

View file

@ -0,0 +1,102 @@
package ru.betterend.mixin.client;
import java.util.List;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import com.google.common.collect.Lists;
import net.minecraft.client.gui.screen.ingame.AnvilScreen;
import net.minecraft.client.gui.screen.ingame.ForgingScreen;
import net.minecraft.client.gui.widget.AbstractButtonWidget;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.gui.widget.TextFieldWidget;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.screen.AnvilScreenHandler;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import ru.betterend.interfaces.AnvilScreenHandlerExtended;
import ru.betterend.recipe.builders.AnvilSmithingRecipe;
@Mixin(AnvilScreen.class)
public class AnvilScreenMixin extends ForgingScreen<AnvilScreenHandler> {
@Shadow
private TextFieldWidget nameField;
private List<AbstractButtonWidget> be_buttons = Lists.newArrayList();
public AnvilScreenMixin(AnvilScreenHandler handler, PlayerInventory playerInventory, Text title,
Identifier texture) {
super(handler, playerInventory, title, texture);
}
@Inject(method = "setup", at = @At("TAIL"))
protected void setup(CallbackInfo info) {
this.be_buttons.clear();
int x = (this.width - this.backgroundWidth) / 2;
int y = (this.height - this.backgroundHeight) / 2;
this.be_buttons.add(new ButtonWidget(x + 8, y + 45, 15, 20, new LiteralText("<"), (b) -> be_previousRecipe()));
this.be_buttons.add(new ButtonWidget(x + 154, y + 45, 15, 20, new LiteralText(">"), (b) -> be_nextRecipe()));
}
@Inject(method = "renderForeground", at = @At("TAIL"))
protected void renderForeground(MatrixStack matrices, int mouseX, int mouseY, float delta, CallbackInfo info) {
AnvilScreenHandlerExtended handler = AnvilScreenHandlerExtended.class.cast(this.handler);
if (handler.be_getRecipes().size() > 1) {
this.be_buttons.forEach(button -> button.render(matrices, mouseX, mouseY, delta));
}
}
@Inject(method = "onSlotUpdate", at = @At("HEAD"), cancellable = true)
public void onSlotUpdate(ScreenHandler handler, int slotId, ItemStack stack, CallbackInfo info) {
AnvilScreenHandlerExtended anvilHandler = AnvilScreenHandlerExtended.class.cast(this.handler);
if (anvilHandler.be_getCurrentRecipe() != null) {
this.nameField.setText("");
this.nameField.setEditable(false);
this.setFocused(null);
info.cancel();
}
}
private void be_nextRecipe() {
AnvilScreenHandlerExtended handler = AnvilScreenHandlerExtended.class.cast(this.handler);
List<AnvilSmithingRecipe> recipes = handler.be_getRecipes();
AnvilSmithingRecipe current = handler.be_getCurrentRecipe();
int i = recipes.indexOf(current) + 1;
if (i == recipes.size()) {
i = 0;
}
handler.be_updateCurrentRecipe(recipes.get(i));
}
private void be_previousRecipe() {
AnvilScreenHandlerExtended handler = AnvilScreenHandlerExtended.class.cast(this.handler);
List<AnvilSmithingRecipe> recipes = handler.be_getRecipes();
AnvilSmithingRecipe current = handler.be_getCurrentRecipe();
int i = recipes.indexOf(current) - 1;
if (i == 0) {
i = recipes.size() - 1;
}
handler.be_updateCurrentRecipe(recipes.get(i));
}
@Override
public boolean mouseClicked(double mouseX, double mouseY, int button) {
for (AbstractButtonWidget elem : be_buttons) {
if (elem.mouseClicked(mouseX, mouseY, button)) {
return true;
}
}
return super.mouseClicked(mouseX, mouseY, button);
}
}

View file

@ -1,5 +1,8 @@
package ru.betterend.mixin.common;
import java.util.Collections;
import java.util.List;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
@ -18,15 +21,14 @@ import net.minecraft.screen.ForgingScreenHandler;
import net.minecraft.screen.ScreenHandlerContext;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.tag.BlockTags;
import net.minecraft.world.World;
import ru.betterend.interfaces.AnvilScreenHandlerExtended;
import ru.betterend.recipe.builders.AnvilSmithingRecipe;
@Mixin(AnvilScreenHandler.class)
public abstract class AnvilScreenHandlerMixin extends ForgingScreenHandler {
public abstract class AnvilScreenHandlerMixin extends ForgingScreenHandler implements AnvilScreenHandlerExtended {
private final World world = this.player.world;
private final RecipeManager recipeManager = this.world.getRecipeManager();
private AnvilSmithingRecipe currentRecipe;
private List<AnvilSmithingRecipe> be_recipes = Collections.emptyList();
private AnvilSmithingRecipe be_currentRecipe;
public AnvilScreenHandlerMixin(ScreenHandlerType<?> type, int syncId, PlayerInventory playerInventory,
ScreenHandlerContext context) {
@ -38,8 +40,8 @@ public abstract class AnvilScreenHandlerMixin extends ForgingScreenHandler {
@Inject(method = "canTakeOutput", at = @At("HEAD"), cancellable = true)
protected void canTakeOutput(PlayerEntity player, boolean present, CallbackInfoReturnable<Boolean> info) {
if (currentRecipe != null) {
ItemStack output = this.currentRecipe.craft(input, player);
if (be_currentRecipe != null) {
ItemStack output = this.be_currentRecipe.craft(input, player);
if (!output.isEmpty()) {
info.setReturnValue(true);
info.cancel();
@ -49,7 +51,7 @@ public abstract class AnvilScreenHandlerMixin extends ForgingScreenHandler {
@Inject(method = "onTakeOutput", at = @At("HEAD"), cancellable = true)
protected void onTakeOutput(PlayerEntity player, ItemStack stack, CallbackInfoReturnable<ItemStack> info) {
if (currentRecipe != null) {
if (be_currentRecipe != null) {
this.input.getStack(1).decrement(1);
this.updateResult();
this.context.run((world, blockPos) -> {
@ -66,7 +68,6 @@ public abstract class AnvilScreenHandlerMixin extends ForgingScreenHandler {
} else {
world.syncWorldEvent(1030, blockPos, 0);
}
});
info.setReturnValue(stack);
info.cancel();
@ -75,18 +76,41 @@ public abstract class AnvilScreenHandlerMixin extends ForgingScreenHandler {
@Inject(method = "updateResult", at = @At("HEAD"), cancellable = true)
public void updateOutput(CallbackInfo info) {
this.currentRecipe = this.recipeManager.getFirstMatch(AnvilSmithingRecipe.TYPE, input, world).orElse(null);
if (currentRecipe != null) {
this.output.setStack(0, currentRecipe.craft(input));
this.sendContentUpdates();
RecipeManager recipeManager = this.player.world.getRecipeManager();
this.be_recipes = recipeManager.getAllMatches(AnvilSmithingRecipe.TYPE, input, player.world);
if (be_recipes.size() > 0) {
this.be_currentRecipe = recipeManager.getFirstMatch(AnvilSmithingRecipe.TYPE, input, player.world).get();
this.be_updateResult();
info.cancel();
}
}
@Inject(method = "setNewItemName", at = @At("HEAD"), cancellable = true)
public void setNewItemName(String string, CallbackInfo info) {
if (currentRecipe != null) {
if (be_currentRecipe != null) {
info.cancel();
}
}
private void be_updateResult() {
if (be_currentRecipe == null) return;
this.output.setStack(0, be_currentRecipe.craft(input));
this.sendContentUpdates();
}
@Override
public void be_updateCurrentRecipe(AnvilSmithingRecipe recipe) {
this.be_currentRecipe = recipe;
this.be_updateResult();
}
@Override
public AnvilSmithingRecipe be_getCurrentRecipe() {
return this.be_currentRecipe;
}
@Override
public List<AnvilSmithingRecipe> be_getRecipes() {
return this.be_recipes;
}
}

View file

@ -134,7 +134,8 @@ public class CraftingRecipes {
.build();
GridRecipe.make("shadow_berry_jelly", EndItems.SHADOW_BERRY_JELLY)
.setList("JWSB").addMaterial('J', EndItems.GELATINE)
.setList("JWSB")
.addMaterial('J', EndItems.GELATINE)
.addMaterial('W', PotionUtil.setPotion(new ItemStack(Items.POTION), Potions.WATER))
.addMaterial('S', Items.SUGAR)
.addMaterial('B', EndItems.SHADOW_BERRY_COOKED)
@ -172,7 +173,7 @@ public class CraftingRecipes {
.setShape("I I", "ICI", " I ")
.addMaterial('I', Items.IRON_INGOT)
.addMaterial('C', EndTags.ITEM_CHEST)
.build();;
.build();
GridRecipe.make("shulker_box", Blocks.SHULKER_BOX)
.setShape("S", "C", "S")
@ -182,6 +183,21 @@ public class CraftingRecipes {
GridRecipe.make("twisted_umbrella_moss_dye", Items.PURPLE_DYE).setList("#").addMaterial('#', EndBlocks.TWISTED_UMBRELLA_MOSS).build();
GridRecipe.make("twisted_umbrella_moss_dye_tall", Items.PURPLE_DYE).setOutputCount(2).setList("#").addMaterial('#', EndBlocks.TWISTED_UMBRELLA_MOSS_TALL).build();
GridRecipe.make("leather_to_stripes", EndItems.LEATHER_STRIPE)
.setList("L")
.addMaterial('L', Items.LEATHER)
.setOutputCount(3)
.build();
GridRecipe.make("stripes_to_leather", Items.LEATHER)
.setList("SSS")
.addMaterial('S', EndItems.LEATHER_STRIPE)
.build();
GridRecipe.make("leather_wrapped_stick", EndItems.LEATHER_WRAPPED_STICK)
.setList("SL")
.addMaterial('S', Items.STICK)
.addMaterial('L', EndItems.LEATHER_STRIPE)
.build();
}
private static void registerLantern(String name, Block lantern, Block slab) {

View file

@ -18,5 +18,30 @@ public class SmithingRecipes {
.setLevel(2)
.setDamage(3)
.build();
AnvilSmithingRecipe.Builder.create("aeternium_axe_head")
.setInput(EndItems.AETERNIUM_INGOT)
.setOutput(EndItems.AETERNIUM_AXE_HEAD, 1)
.setLevel(4)
.setDamage(6)
.build();
AnvilSmithingRecipe.Builder.create("aeternium_pickaxe_head")
.setInput(EndItems.AETERNIUM_INGOT)
.setOutput(EndItems.AETERNIUM_PICKAXE_HEAD, 1)
.setLevel(4)
.setDamage(6)
.build();
AnvilSmithingRecipe.Builder.create("aeternium_shovel_head")
.setInput(EndItems.AETERNIUM_INGOT)
.setOutput(EndItems.AETERNIUM_SHOVEL_HEAD, 1)
.setLevel(4)
.setDamage(6)
.build();
AnvilSmithingRecipe.Builder.create("aeternium_hoe_head")
.setInput(EndItems.AETERNIUM_INGOT)
.setOutput(EndItems.AETERNIUM_HOE_HEAD, 1)
.setLevel(4)
.setDamage(6)
.build();
}
}

View file

@ -68,6 +68,8 @@ public class EndItems {
public final static Item GELATINE = registerItem("gelatine");
public static final Item ETERNAL_CRYSTAL = registerItem("eternal_crystal", new EternalCrystal());
public final static Item ENCHANTED_PETAL = registerItem("enchanted_petal", new EnchantedPetal());
public final static Item LEATHER_STRIPE = registerItem("leather_stripe");
public final static Item LEATHER_WRAPPED_STICK = registerItem("leather_wrapped_stick");
// Armor //
public static final Item TERMINITE_HELMET = registerItem("terminite_helmet", new ArmorItem(EndArmorMaterial.TERMINITE, EquipmentSlot.HEAD, makeItemSettings()));
@ -110,6 +112,15 @@ public class EndItems {
public final static Item SWEET_BERRY_JELLY = registerFood("sweet_berry_jelly", 3, 0.75F);
public final static Item SHADOW_BERRY_JELLY = registerFood("shadow_berry_jelly", 4, 0.75F, new StatusEffectInstance(StatusEffects.NIGHT_VISION, 400));
// Toolparts //
public final static Item AETERNIUM_SHOVEL_HEAD = registerItem("aeternium_shovel_head");
public final static Item AETERNIUM_PICKAXE_HEAD = registerItem("aeternium_pickaxe_head");
public final static Item AETERNIUM_AXE_HEAD = registerItem("aeternium_axe_head");
public final static Item AETERNIUM_HOE_HEAD = registerItem("aeternium_hoe_head");
public final static Item AETERNIUM_HAMMER_HEAD = registerItem("aeternium_hammer_head");
public final static Item AETERNIUM_SWORD_BLADE = registerItem("aeternium_sword_blade");
public final static Item AETERNIUM_SWORD_HANDLE = registerItem("aeternium_sword_handle");
// Drinks
public final static Item UMBRELLA_CLUSTER_JUICE = registerDrink("umbrella_cluster_juice");

Binary file not shown.

Before

Width:  |  Height:  |  Size: 372 B

After

Width:  |  Height:  |  Size: 462 B

Before After
Before After

Binary file not shown.

After

Width:  |  Height:  |  Size: 355 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 395 B

After

Width:  |  Height:  |  Size: 530 B

Before After
Before After

Binary file not shown.

After

Width:  |  Height:  |  Size: 435 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 312 B

After

Width:  |  Height:  |  Size: 446 B

Before After
Before After

Binary file not shown.

After

Width:  |  Height:  |  Size: 300 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 420 B

After

Width:  |  Height:  |  Size: 557 B

Before After
Before After

Binary file not shown.

After

Width:  |  Height:  |  Size: 423 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 282 B

After

Width:  |  Height:  |  Size: 376 B

Before After
Before After

Binary file not shown.

After

Width:  |  Height:  |  Size: 262 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 542 B

After

Width:  |  Height:  |  Size: 629 B

Before After
Before After

Binary file not shown.

After

Width:  |  Height:  |  Size: 359 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 439 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 332 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 316 B

View file

@ -15,8 +15,9 @@
"MinecraftClientMixin",
"WorldRendererMixin",
"MusicTrackerMixin",
"ModelLoaderMixin",
"BiomeColorsMixin"
"AnvilScreenMixin",
"BiomeColorsMixin",
"ModelLoaderMixin"
],
"injectors": {
"defaultRequire": 1

View file

@ -10,8 +10,8 @@
"GenerationSettingsAccessor",
"NoiseChunkGeneratorMixin",
"AnvilScreenHandlerMixin",
"ServerPlayerEntityMixin",
"ChorusPlantFeatureMixin",
"ServerPlayerEntityMixin",
"ComposterBlockAccessor",
"ChorusFlowerBlockMixin",
"LandPathNodeMakerMixin",