Recipes
This commit is contained in:
parent
2bc84f65a1
commit
ea7cca31d5
15 changed files with 341 additions and 4 deletions
20
src/main/java/ru/betterend/blocks/BlockBase.java
Normal file
20
src/main/java/ru/betterend/blocks/BlockBase.java
Normal file
|
@ -0,0 +1,20 @@
|
|||
package ru.betterend.blocks;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.loot.context.LootContext;
|
||||
|
||||
public class BlockBase extends Block {
|
||||
public BlockBase(Settings settings) {
|
||||
super(settings);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getDroppedStacks(BlockState state, LootContext.Builder builder) {
|
||||
return Collections.singletonList(new ItemStack(this));
|
||||
}
|
||||
}
|
35
src/main/java/ru/betterend/blocks/BlockEndstoneDust.java
Normal file
35
src/main/java/ru/betterend/blocks/BlockEndstoneDust.java
Normal file
|
@ -0,0 +1,35 @@
|
|||
package ru.betterend.blocks;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.block.FallingBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.loot.context.LootContext;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.BlockView;
|
||||
import ru.betterend.util.MHelper;
|
||||
|
||||
public class BlockEndstoneDust extends FallingBlock {
|
||||
@Environment(EnvType.CLIENT)
|
||||
private static final int COLOR = MHelper.color(226, 239, 168);
|
||||
|
||||
public BlockEndstoneDust() {
|
||||
super(FabricBlockSettings.copyOf(Blocks.SAND).materialColor(Blocks.END_STONE.getDefaultMaterialColor()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getDroppedStacks(BlockState state, LootContext.Builder builder) {
|
||||
return Collections.singletonList(new ItemStack(this));
|
||||
}
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public int getColor(BlockState state, BlockView world, BlockPos pos) {
|
||||
return COLOR;
|
||||
}
|
||||
}
|
|
@ -1,10 +1,9 @@
|
|||
package ru.betterend.blocks;
|
||||
|
||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.Blocks;
|
||||
|
||||
public class BlockWetMycelium extends Block {
|
||||
public class BlockWetMycelium extends BlockBase {
|
||||
public BlockWetMycelium() {
|
||||
super(FabricBlockSettings.copyOf(Blocks.END_STONE));
|
||||
}
|
||||
|
|
|
@ -27,7 +27,6 @@ import net.minecraft.client.util.math.Vector3f;
|
|||
import net.minecraft.client.world.ClientWorld;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.Quaternion;
|
||||
|
||||
import ru.betterend.BetterEnd;
|
||||
import ru.betterend.util.MHelper;
|
||||
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
package ru.betterend.mixin.common;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Overwrite;
|
||||
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.gson.JsonElement;
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.recipe.Recipe;
|
||||
import net.minecraft.recipe.RecipeManager;
|
||||
import net.minecraft.recipe.RecipeType;
|
||||
import net.minecraft.resource.ResourceManager;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.Util;
|
||||
import net.minecraft.util.profiler.Profiler;
|
||||
import net.minecraft.world.World;
|
||||
import ru.betterend.mixin.recipe.EndRecipeManager;
|
||||
|
||||
@Mixin(RecipeManager.class)
|
||||
public class RecipeManagerMixin
|
||||
{
|
||||
@Shadow
|
||||
private Map<RecipeType<?>, Map<Identifier, Recipe<?>>> recipes;
|
||||
|
||||
@Inject(method = "apply", at = @At(value = "TAIL"))
|
||||
private void setRecipes(Map<Identifier, JsonElement> map, ResourceManager resourceManager, Profiler profiler, CallbackInfo info)
|
||||
{
|
||||
recipes = EndRecipeManager.getMap(recipes);
|
||||
}
|
||||
|
||||
@Shadow
|
||||
private <C extends Inventory, T extends Recipe<C>> Map<Identifier, Recipe<C>> getAllOfType(RecipeType<T> type) { return null; }
|
||||
|
||||
@Overwrite
|
||||
public <C extends Inventory, T extends Recipe<C>> Optional<T> getFirstMatch(RecipeType<T> type, C inventory, World world)
|
||||
{
|
||||
Collection<Recipe<C>> values = getAllOfType(type).values();
|
||||
List<Recipe<C>> list = new ArrayList<Recipe<C>>(values);
|
||||
list.sort((v1, v2) -> {
|
||||
boolean b1 = v1.getId().getNamespace().equals("minecraft");
|
||||
boolean b2 = v2.getId().getNamespace().equals("minecraft");
|
||||
return b1 ^ b2 ? (b1 ? 1 : -1) : 0;
|
||||
});
|
||||
|
||||
return list.stream().flatMap((recipe) -> {
|
||||
return Util.stream(type.get(recipe, world, inventory));
|
||||
}).findFirst();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
package ru.betterend.mixin.recipe;
|
||||
|
||||
import java.util.Map;
|
||||
import com.google.common.collect.Maps;
|
||||
import net.minecraft.recipe.Recipe;
|
||||
import net.minecraft.recipe.RecipeType;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
public class EndRecipeManager {
|
||||
private static final Map<RecipeType<?>, Map<Identifier, Recipe<?>>> RECIPES = Maps.newHashMap();
|
||||
|
||||
public static void addRecipe(RecipeType<?> type, Recipe<?> recipe) {
|
||||
Map<Identifier, Recipe<?>> list = RECIPES.get(type);
|
||||
if (list == null) {
|
||||
list = Maps.newHashMap();
|
||||
RECIPES.put(type, list);
|
||||
}
|
||||
list.put(recipe.getId(), recipe);
|
||||
}
|
||||
|
||||
public static Map<RecipeType<?>, Map<Identifier, Recipe<?>>> getMap(Map<RecipeType<?>, Map<Identifier, Recipe<?>>> recipes) {
|
||||
Map<RecipeType<?>, Map<Identifier, Recipe<?>>> result = Maps.newHashMap();
|
||||
|
||||
for (RecipeType<?> type : recipes.keySet()) {
|
||||
Map<Identifier, Recipe<?>> typeList = Maps.newHashMap();
|
||||
typeList.putAll(recipes.get(type));
|
||||
result.put(type, typeList);
|
||||
}
|
||||
|
||||
for (RecipeType<?> type : RECIPES.keySet()) {
|
||||
Map<Identifier, Recipe<?>> list = RECIPES.get(type);
|
||||
if (list != null) {
|
||||
Map<Identifier, Recipe<?>> typeList = result.get(type);
|
||||
list.forEach((id, recipe) -> {
|
||||
if (!typeList.containsKey(id))
|
||||
typeList.put(id, recipe);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
93
src/main/java/ru/betterend/mixin/recipe/RecipeBuilder.java
Normal file
93
src/main/java/ru/betterend/mixin/recipe/RecipeBuilder.java
Normal file
|
@ -0,0 +1,93 @@
|
|||
package ru.betterend.mixin.recipe;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.recipe.CraftingRecipe;
|
||||
import net.minecraft.recipe.Ingredient;
|
||||
import net.minecraft.recipe.RecipeType;
|
||||
import net.minecraft.recipe.ShapedRecipe;
|
||||
import net.minecraft.recipe.ShapelessRecipe;
|
||||
import net.minecraft.tag.Tag;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.collection.DefaultedList;
|
||||
import ru.betterend.BetterEnd;
|
||||
|
||||
public class RecipeBuilder {
|
||||
private final String name;
|
||||
private final Item output;
|
||||
|
||||
private String group = "";
|
||||
private RecipeType<?> type = RecipeType.CRAFTING;
|
||||
private boolean shaped = true;
|
||||
private String[] shape = new String[] {"#"};
|
||||
private Map<Character, Ingredient> materialKeys = Maps.newHashMap();
|
||||
private int count;
|
||||
|
||||
public RecipeBuilder(String name, Item output) {
|
||||
this.name = name;
|
||||
this.output = output;
|
||||
}
|
||||
|
||||
public RecipeBuilder(String name, Block output) {
|
||||
this.name = name;
|
||||
this.output = output.asItem();
|
||||
}
|
||||
|
||||
public RecipeBuilder setGroup(String group) {
|
||||
this.group = group;
|
||||
return this;
|
||||
}
|
||||
|
||||
public RecipeBuilder setShape(String[] shape) {
|
||||
this.shape = shape;
|
||||
return this;
|
||||
}
|
||||
|
||||
public RecipeBuilder addMaterial(char key, Item value) {
|
||||
materialKeys.put(key, Ingredient.ofItems(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
public RecipeBuilder addMaterial(char key, Block value) {
|
||||
materialKeys.put(key, Ingredient.ofItems(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
public RecipeBuilder addMaterial(char key, Tag<Item> value) {
|
||||
materialKeys.put(key, Ingredient.fromTag(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
public RecipeBuilder setOutputCount(int count) {
|
||||
this.count = count;
|
||||
return this;
|
||||
}
|
||||
|
||||
private DefaultedList<Ingredient> getMaterials(int width, int height) {
|
||||
DefaultedList<Ingredient> materials = DefaultedList.ofSize(width * height, Ingredient.EMPTY);
|
||||
for (String line: shape) {
|
||||
for (int i = 0; i < width; i++) {
|
||||
char c = line.charAt(i);
|
||||
Ingredient material = materialKeys.get(c);
|
||||
materials.add(material == null ? Ingredient.EMPTY : material);
|
||||
}
|
||||
}
|
||||
return materials;
|
||||
}
|
||||
|
||||
public void build() {
|
||||
int height = shape.length;
|
||||
int width = shape[0].length();
|
||||
ItemStack result = new ItemStack(output, count);
|
||||
Identifier id = new Identifier(BetterEnd.MOD_ID, name);
|
||||
DefaultedList<Ingredient> materials = getMaterials(width, height);
|
||||
|
||||
CraftingRecipe recipe = shaped ? new ShapedRecipe(id, group, width, height, materials, result) : new ShapelessRecipe(id, group, result, materials);
|
||||
EndRecipeManager.addRecipe(type, recipe);
|
||||
}
|
||||
}
|
|
@ -6,10 +6,12 @@ import net.minecraft.item.Item;
|
|||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import ru.betterend.BetterEnd;
|
||||
import ru.betterend.blocks.BlockEndstoneDust;
|
||||
import ru.betterend.blocks.BlockWetMycelium;
|
||||
import ru.betterend.tab.CreativeTab;
|
||||
|
||||
public class BlockRegistry {
|
||||
public static final Block ENDSTONE_DUST = registerBlock("endstone_dust", new BlockEndstoneDust());
|
||||
public static final Block WET_MYCELIUM = registerBlock("wet_mycelium", new BlockWetMycelium());
|
||||
|
||||
public static void register() {}
|
||||
|
|
|
@ -59,7 +59,7 @@ public class BiomeMap
|
|||
pz = pz / 2 + i;
|
||||
}
|
||||
|
||||
ChunkPos cpos = new ChunkPos(MHelper.floor((double) x / BiomeChunk.WIDTH), MHelper.floor((double) z / BiomeChunk.WIDTH));
|
||||
ChunkPos cpos = new ChunkPos(MHelper.floor(x / BiomeChunk.WIDTH), MHelper.floor(z / BiomeChunk.WIDTH));
|
||||
BiomeChunk chunk = MAPS.get(cpos);
|
||||
if (chunk == null)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue