Anvil crafting fixes
This commit is contained in:
parent
c5182a4418
commit
7e367a1971
9 changed files with 76 additions and 83 deletions
|
@ -8,66 +8,35 @@ import java.util.Map;
|
|||
import com.google.common.collect.Maps;
|
||||
|
||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||
import net.minecraft.block.AnvilBlock;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.block.*;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.loot.context.LootContext;
|
||||
import net.minecraft.state.StateManager;
|
||||
import net.minecraft.state.property.IntProperty;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import ru.betterend.blocks.basis.EndAnvilBlock;
|
||||
import ru.betterend.item.material.EndToolMaterial;
|
||||
import ru.betterend.patterns.BlockPatterned;
|
||||
import ru.betterend.patterns.Patterns;
|
||||
import ru.betterend.registry.EndBlocks;
|
||||
|
||||
public class AeterniumAnvil extends AnvilBlock implements BlockPatterned {
|
||||
public class AeterniumAnvil extends EndAnvilBlock {
|
||||
public static final IntProperty DESTRUCTION = BlockProperties.DESTRUCTION_LONG;
|
||||
private final int level;
|
||||
|
||||
public AeterniumAnvil() {
|
||||
super(FabricBlockSettings.copyOf(Blocks.ANVIL).materialColor(EndBlocks.AETERNIUM_BLOCK.getDefaultMaterialColor()));
|
||||
this.level = EndToolMaterial.AETERNIUM.getMiningLevel();
|
||||
super(EndBlocks.AETERNIUM_BLOCK.getDefaultMaterialColor(), EndToolMaterial.AETERNIUM.getMiningLevel());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
|
||||
super.appendProperties(builder);
|
||||
builder.add(DESTRUCTION);
|
||||
}
|
||||
|
||||
public int getCraftingLevel() {
|
||||
return level;
|
||||
builder.add(FACING);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getDroppedStacks(BlockState state, LootContext.Builder builder) {
|
||||
return Collections.singletonList(new ItemStack(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getStatesPattern(Reader data) {
|
||||
Identifier blockId = Registry.BLOCK.getId(this);
|
||||
return Patterns.createJson(data, blockId.getPath(), blockId.getPath());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getModelPattern(String block) {
|
||||
Identifier blockId = Registry.BLOCK.getId(this);
|
||||
Map<String, String> map = Maps.newHashMap();
|
||||
map.put("%anvil%", blockId.getPath());
|
||||
map.put("%top%", getTop(blockId, block));
|
||||
return Patterns.createJson(Patterns.BLOCK_ANVIL, map);
|
||||
}
|
||||
|
||||
private String getTop(Identifier blockId, String block) {
|
||||
if (block.contains("item")) {
|
||||
return blockId.getPath() + "_top_0";
|
||||
}
|
||||
char last = block.charAt(block.length() - 1);
|
||||
return blockId.getPath() + "_top_" + last;
|
||||
public IntProperty getDestructionProperty() {
|
||||
return DESTRUCTION;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -25,7 +25,7 @@ import ru.betterend.patterns.Patterns;
|
|||
|
||||
public class EndAnvilBlock extends AnvilBlock implements BlockPatterned {
|
||||
public static final IntProperty DESTRUCTION = BlockProperties.DESTRUCTION;
|
||||
private final int level;
|
||||
protected final int level;
|
||||
|
||||
public EndAnvilBlock(MaterialColor color, int level) {
|
||||
super(FabricBlockSettings.copyOf(Blocks.ANVIL).materialColor(color));
|
||||
|
@ -38,6 +38,10 @@ public class EndAnvilBlock extends AnvilBlock implements BlockPatterned {
|
|||
builder.add(DESTRUCTION);
|
||||
}
|
||||
|
||||
public IntProperty getDestructionProperty() {
|
||||
return DESTRUCTION;
|
||||
}
|
||||
|
||||
public int getCraftingLevel() {
|
||||
return level;
|
||||
}
|
||||
|
@ -62,7 +66,7 @@ public class EndAnvilBlock extends AnvilBlock implements BlockPatterned {
|
|||
return Patterns.createJson(Patterns.BLOCK_ANVIL, map);
|
||||
}
|
||||
|
||||
private String getTop(Identifier blockId, String block) {
|
||||
protected String getTop(Identifier blockId, String block) {
|
||||
if (block.contains("item")) {
|
||||
return blockId.getPath() + "_top_0";
|
||||
}
|
||||
|
|
|
@ -17,8 +17,7 @@ import ru.betterend.util.JsonFactory;
|
|||
|
||||
public final class ConfigKeeper {
|
||||
|
||||
private Map<ConfigKey, Entry<?>> configEntries = Maps.newHashMap();
|
||||
|
||||
private final Map<ConfigKey, Entry<?>> configEntries = Maps.newHashMap();
|
||||
private final JsonObject configObject;
|
||||
private final ConfigWriter writer;
|
||||
|
||||
|
|
|
@ -5,27 +5,29 @@ import java.util.List;
|
|||
import ru.betterend.recipe.builders.AnvilRecipe;
|
||||
|
||||
public interface AnvilScreenHandlerExtended {
|
||||
public void be_updateCurrentRecipe(AnvilRecipe recipe);
|
||||
public AnvilRecipe be_getCurrentRecipe();
|
||||
public List<AnvilRecipe> be_getRecipes();
|
||||
void be_updateCurrentRecipe(AnvilRecipe recipe);
|
||||
AnvilRecipe be_getCurrentRecipe();
|
||||
List<AnvilRecipe> be_getRecipes();
|
||||
|
||||
default void be_nextRecipe() {
|
||||
List<AnvilRecipe> recipes = this.be_getRecipes();
|
||||
AnvilRecipe current = this.be_getCurrentRecipe();
|
||||
List<AnvilRecipe> recipes = be_getRecipes();
|
||||
if (recipes.size() < 2) return;
|
||||
AnvilRecipe current = be_getCurrentRecipe();
|
||||
int i = recipes.indexOf(current) + 1;
|
||||
if (i >= recipes.size()) {
|
||||
i = 0;
|
||||
}
|
||||
this.be_updateCurrentRecipe(recipes.get(i));
|
||||
be_updateCurrentRecipe(recipes.get(i));
|
||||
}
|
||||
|
||||
default void be_previousRecipe() {
|
||||
List<AnvilRecipe> recipes = this.be_getRecipes();
|
||||
AnvilRecipe current = this.be_getCurrentRecipe();
|
||||
List<AnvilRecipe> recipes = be_getRecipes();
|
||||
if (recipes.size() < 2) return;
|
||||
AnvilRecipe current = be_getCurrentRecipe();
|
||||
int i = recipes.indexOf(current) - 1;
|
||||
if (i <= 0) {
|
||||
i = recipes.size() - 1;
|
||||
}
|
||||
this.be_updateCurrentRecipe(recipes.get(i));
|
||||
be_updateCurrentRecipe(recipes.get(i));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package ru.betterend.mixin.common;
|
||||
|
||||
import net.minecraft.state.property.IntProperty;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
|
@ -15,10 +16,16 @@ public class AnvilBlockMixin {
|
|||
@Inject(method = "getLandingState", at = @At("HEAD"), cancellable = true)
|
||||
private static void be_getLandingState(BlockState fallingState, CallbackInfoReturnable<BlockState> info) {
|
||||
if (fallingState.getBlock() instanceof EndAnvilBlock) {
|
||||
int destruction = fallingState.get(BlockProperties.DESTRUCTION);
|
||||
BlockState state = (destruction < 2) ? fallingState.with(BlockProperties.DESTRUCTION, destruction + 1) : null;
|
||||
info.setReturnValue(state);
|
||||
info.cancel();
|
||||
IntProperty destructionProperty = ((EndAnvilBlock) fallingState.getBlock()).getDestructionProperty();
|
||||
int destruction = fallingState.get(destructionProperty);
|
||||
try {
|
||||
BlockState state = fallingState.with(destructionProperty, destruction + 1);
|
||||
info.setReturnValue(state);
|
||||
info.cancel();
|
||||
} catch (Exception ex) {
|
||||
info.setReturnValue(null);
|
||||
info.cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import java.util.Collections;
|
|||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import net.minecraft.screen.*;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
|
@ -18,10 +19,6 @@ import net.minecraft.entity.player.PlayerEntity;
|
|||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.recipe.RecipeManager;
|
||||
import net.minecraft.screen.AnvilScreenHandler;
|
||||
import net.minecraft.screen.ForgingScreenHandler;
|
||||
import net.minecraft.screen.ScreenHandlerContext;
|
||||
import net.minecraft.screen.ScreenHandlerType;
|
||||
import net.minecraft.tag.BlockTags;
|
||||
import ru.betterend.blocks.basis.EndAnvilBlock;
|
||||
import ru.betterend.interfaces.AnvilScreenHandlerExtended;
|
||||
|
@ -32,12 +29,27 @@ public abstract class AnvilScreenHandlerMixin extends ForgingScreenHandler imple
|
|||
|
||||
private List<AnvilRecipe> be_recipes = Collections.emptyList();
|
||||
private AnvilRecipe be_currentRecipe;
|
||||
private Property anvilLevel;
|
||||
|
||||
public AnvilScreenHandlerMixin(ScreenHandlerType<?> type, int syncId, PlayerInventory playerInventory,
|
||||
ScreenHandlerContext context) {
|
||||
super(type, syncId, playerInventory, context);
|
||||
}
|
||||
|
||||
@Inject(method = "<init>*", at = @At("TAIL"))
|
||||
public void be_initAnvilLevel(int syncId, PlayerInventory inventory, ScreenHandlerContext context, CallbackInfo info) {
|
||||
int anvLevel = context.run((world, blockPos) -> {
|
||||
Block anvilBlock = world.getBlockState(blockPos).getBlock();
|
||||
if (anvilBlock instanceof EndAnvilBlock) {
|
||||
return ((EndAnvilBlock) anvilBlock).getCraftingLevel();
|
||||
}
|
||||
return 1;
|
||||
}, 1);
|
||||
Property anvilLevel = Property.create();
|
||||
anvilLevel.set(anvLevel);
|
||||
this.anvilLevel = addProperty(anvilLevel);
|
||||
}
|
||||
|
||||
@Shadow
|
||||
public abstract void updateResult();
|
||||
|
||||
|
@ -76,25 +88,19 @@ public abstract class AnvilScreenHandlerMixin extends ForgingScreenHandler imple
|
|||
@Inject(method = "updateResult", at = @At("HEAD"), cancellable = true)
|
||||
public void be_updateOutput(CallbackInfo info) {
|
||||
RecipeManager recipeManager = this.player.world.getRecipeManager();
|
||||
this.be_recipes = recipeManager.getAllMatches(AnvilRecipe.TYPE, input, player.world);
|
||||
be_recipes = recipeManager.getAllMatches(AnvilRecipe.TYPE, input, player.world);
|
||||
if (be_recipes.size() > 0) {
|
||||
this.context.run((world, blockPos) -> {
|
||||
int anvilLevel;
|
||||
Block anvilBlock = world.getBlockState(blockPos).getBlock();
|
||||
if (anvilBlock instanceof EndAnvilBlock) {
|
||||
anvilLevel = ((EndAnvilBlock) anvilBlock).getCraftingLevel();
|
||||
} else {
|
||||
anvilLevel = 1;
|
||||
}
|
||||
this.be_recipes = be_recipes.stream().filter(recipe ->
|
||||
int anvilLevel = this.anvilLevel.get();
|
||||
be_recipes = be_recipes.stream().filter(recipe ->
|
||||
anvilLevel >= recipe.getAnvilLevel()).collect(Collectors.toList());
|
||||
});
|
||||
if (be_recipes.size() > 0) {
|
||||
if (be_currentRecipe == null || !be_recipes.contains(be_currentRecipe)) {
|
||||
this.be_currentRecipe = be_recipes.get(0);
|
||||
be_currentRecipe = be_recipes.get(0);
|
||||
}
|
||||
this.be_updateResult();
|
||||
be_updateResult();
|
||||
info.cancel();
|
||||
} else {
|
||||
be_currentRecipe = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,45 +20,46 @@ public class AnvilRecipes {
|
|||
.setDamage(3)
|
||||
.build();
|
||||
|
||||
int anvilLevel = EndToolMaterial.AETERNIUM.getMiningLevel();
|
||||
AnvilRecipe.Builder.create("aeternium_axe_head")
|
||||
.setInput(EndItems.AETERNIUM_INGOT)
|
||||
.setOutput(EndItems.AETERNIUM_AXE_HEAD)
|
||||
.setAnvilLevel(EndToolMaterial.AETERNIUM.getDurability())
|
||||
.setAnvilLevel(anvilLevel)
|
||||
.setToolLevel(4)
|
||||
.setDamage(6)
|
||||
.build();
|
||||
AnvilRecipe.Builder.create("aeternium_pickaxe_head")
|
||||
.setInput(EndItems.AETERNIUM_INGOT)
|
||||
.setOutput(EndItems.AETERNIUM_PICKAXE_HEAD)
|
||||
.setAnvilLevel(EndToolMaterial.AETERNIUM.getDurability())
|
||||
.setAnvilLevel(anvilLevel)
|
||||
.setToolLevel(4)
|
||||
.setDamage(6)
|
||||
.build();
|
||||
AnvilRecipe.Builder.create("aeternium_shovel_head")
|
||||
.setInput(EndItems.AETERNIUM_INGOT)
|
||||
.setOutput(EndItems.AETERNIUM_SHOVEL_HEAD)
|
||||
.setAnvilLevel(EndToolMaterial.AETERNIUM.getDurability())
|
||||
.setAnvilLevel(anvilLevel)
|
||||
.setToolLevel(4)
|
||||
.setDamage(6)
|
||||
.build();
|
||||
AnvilRecipe.Builder.create("aeternium_hoe_head")
|
||||
.setInput(EndItems.AETERNIUM_INGOT)
|
||||
.setOutput(EndItems.AETERNIUM_HOE_HEAD)
|
||||
.setAnvilLevel(EndToolMaterial.AETERNIUM.getDurability())
|
||||
.setAnvilLevel(anvilLevel)
|
||||
.setToolLevel(4)
|
||||
.setDamage(6)
|
||||
.build();
|
||||
AnvilRecipe.Builder.create("aeternium_hammer_head")
|
||||
.setInput(EndItems.AETERNIUM_INGOT)
|
||||
.setOutput(EndItems.AETERNIUM_HAMMER_HEAD)
|
||||
.setAnvilLevel(EndToolMaterial.AETERNIUM.getDurability())
|
||||
.setAnvilLevel(anvilLevel)
|
||||
.setToolLevel(4)
|
||||
.setDamage(6)
|
||||
.build();
|
||||
AnvilRecipe.Builder.create("aeternium_sword_blade")
|
||||
.setInput(EndItems.AETERNIUM_INGOT)
|
||||
.setOutput(EndItems.AETERNIUM_SWORD_BLADE)
|
||||
.setAnvilLevel(EndToolMaterial.AETERNIUM.getDurability())
|
||||
.setAnvilLevel(anvilLevel)
|
||||
.setToolLevel(4)
|
||||
.setDamage(6)
|
||||
.build();
|
||||
|
|
|
@ -161,6 +161,11 @@ public class AnvilRecipe implements Recipe<Inventory>, BetterEndRecipe {
|
|||
return Objects.hash(id, input, output, damage, toolLevel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "AnvilRecipe [" + id + "]";
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private final static Builder INSTANCE = new Builder();
|
||||
|
||||
|
@ -299,7 +304,5 @@ public class AnvilRecipe implements Recipe<Inventory>, BetterEndRecipe {
|
|||
packetBuffer.writeVarInt(recipe.anvilLevel);
|
||||
packetBuffer.writeVarInt(recipe.damage);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ import net.minecraft.world.biome.Biome.Category;
|
|||
import net.minecraft.world.gen.surfacebuilder.SurfaceConfig;
|
||||
import ru.betterend.BetterEnd;
|
||||
import ru.betterend.blocks.EndTerrainBlock;
|
||||
import ru.betterend.blocks.basis.EndAnvilBlock;
|
||||
import ru.betterend.blocks.basis.PedestalBlock;
|
||||
import ru.betterend.blocks.basis.SimpleLeavesBlock;
|
||||
import ru.betterend.blocks.basis.VineBlock;
|
||||
|
@ -113,6 +114,7 @@ public class EndTags {
|
|||
));
|
||||
|
||||
TagHelper.addTag(FURNACES, Blocks.FURNACE);
|
||||
TagHelper.addTag(BlockTags.ANVIL, EndBlocks.AETERNIUM_ANVIL);
|
||||
}
|
||||
|
||||
public static void addSurfaceBlock(Block block) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue