This commit is contained in:
paulevsGitch 2020-09-23 21:40:23 +03:00
parent 2bc84f65a1
commit ea7cca31d5
15 changed files with 341 additions and 4 deletions

View 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));
}
}

View 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;
}
}

View file

@ -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));
}

View file

@ -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;

View file

@ -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();
}
}

View file

@ -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;
}
}

View 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);
}
}

View file

@ -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() {}

View file

@ -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)
{

View file

@ -0,0 +1,70 @@
{
"variants": {
"": [
{ "model": "betterend:block/endstone_dust" },
{ "model": "betterend:block/endstone_dust", "y": 90 },
{ "model": "betterend:block/endstone_dust", "y": 180 },
{ "model": "betterend:block/endstone_dust", "y": 270 },
{ "model": "betterend:block/endstone_dust", "x": 90 },
{ "model": "betterend:block/endstone_dust", "x": 90, "y": 90 },
{ "model": "betterend:block/endstone_dust", "x": 90, "y": 180 },
{ "model": "betterend:block/endstone_dust", "x": 90, "y": 270 },
{ "model": "betterend:block/endstone_dust", "x": 180 },
{ "model": "betterend:block/endstone_dust", "x": 180, "y": 90 },
{ "model": "betterend:block/endstone_dust", "x": 180, "y": 180 },
{ "model": "betterend:block/endstone_dust", "x": 180, "y": 270 },
{ "model": "betterend:block/endstone_dust", "x": 270 },
{ "model": "betterend:block/endstone_dust", "x": 270, "y": 90 },
{ "model": "betterend:block/endstone_dust", "x": 270, "y": 180 },
{ "model": "betterend:block/endstone_dust", "x": 270, "y": 270 },
{ "model": "betterend:block/endstone_dust", "z": 90 },
{ "model": "betterend:block/endstone_dust", "z": 90, "y": 90 },
{ "model": "betterend:block/endstone_dust", "z": 90, "y": 180 },
{ "model": "betterend:block/endstone_dust", "z": 90, "y": 270 },
{ "model": "betterend:block/endstone_dust", "z": 90, "x": 90 },
{ "model": "betterend:block/endstone_dust", "z": 90, "x": 90, "y": 90 },
{ "model": "betterend:block/endstone_dust", "z": 90, "x": 90, "y": 180 },
{ "model": "betterend:block/endstone_dust", "z": 90, "x": 90, "y": 270 },
{ "model": "betterend:block/endstone_dust", "z": 90, "x": 180 },
{ "model": "betterend:block/endstone_dust", "z": 90, "x": 180, "y": 90 },
{ "model": "betterend:block/endstone_dust", "z": 90, "x": 180, "y": 180 },
{ "model": "betterend:block/endstone_dust", "z": 90, "x": 180, "y": 270 },
{ "model": "betterend:block/endstone_dust", "z": 90, "x": 270 },
{ "model": "betterend:block/endstone_dust", "z": 90, "x": 270, "y": 90 },
{ "model": "betterend:block/endstone_dust", "z": 90, "x": 270, "y": 180 },
{ "model": "betterend:block/endstone_dust", "z": 90, "x": 270, "y": 270 },
{ "model": "betterend:block/endstone_dust", "z": 180 },
{ "model": "betterend:block/endstone_dust", "z": 180, "y": 90 },
{ "model": "betterend:block/endstone_dust", "z": 180, "y": 180 },
{ "model": "betterend:block/endstone_dust", "z": 180, "y": 270 },
{ "model": "betterend:block/endstone_dust", "z": 180, "x": 90 },
{ "model": "betterend:block/endstone_dust", "z": 180, "x": 90, "y": 90 },
{ "model": "betterend:block/endstone_dust", "z": 180, "x": 90, "y": 180 },
{ "model": "betterend:block/endstone_dust", "z": 180, "x": 90, "y": 270 },
{ "model": "betterend:block/endstone_dust", "z": 180, "x": 180 },
{ "model": "betterend:block/endstone_dust", "z": 180, "x": 180, "y": 90 },
{ "model": "betterend:block/endstone_dust", "z": 180, "x": 180, "y": 180 },
{ "model": "betterend:block/endstone_dust", "z": 180, "x": 180, "y": 270 },
{ "model": "betterend:block/endstone_dust", "z": 180, "x": 270 },
{ "model": "betterend:block/endstone_dust", "z": 180, "x": 270, "y": 90 },
{ "model": "betterend:block/endstone_dust", "z": 180, "x": 270, "y": 180 },
{ "model": "betterend:block/endstone_dust", "z": 180, "x": 270, "y": 270 },
{ "model": "betterend:block/endstone_dust", "z": 270 },
{ "model": "betterend:block/endstone_dust", "z": 270, "y": 90 },
{ "model": "betterend:block/endstone_dust", "z": 270, "y": 180 },
{ "model": "betterend:block/endstone_dust", "z": 270, "y": 270 },
{ "model": "betterend:block/endstone_dust", "z": 270, "x": 90 },
{ "model": "betterend:block/endstone_dust", "z": 270, "x": 90, "y": 90 },
{ "model": "betterend:block/endstone_dust", "z": 270, "x": 90, "y": 180 },
{ "model": "betterend:block/endstone_dust", "z": 270, "x": 90, "y": 270 },
{ "model": "betterend:block/endstone_dust", "z": 270, "x": 180 },
{ "model": "betterend:block/endstone_dust", "z": 270, "x": 180, "y": 90 },
{ "model": "betterend:block/endstone_dust", "z": 270, "x": 180, "y": 180 },
{ "model": "betterend:block/endstone_dust", "z": 270, "x": 180, "y": 270 },
{ "model": "betterend:block/endstone_dust", "z": 270, "x": 270 },
{ "model": "betterend:block/endstone_dust", "z": 270, "x": 270, "y": 90 },
{ "model": "betterend:block/endstone_dust", "z": 270, "x": 270, "y": 180 },
{ "model": "betterend:block/endstone_dust", "z": 270, "x": 270, "y": 270 }
]
}
}

View file

@ -0,0 +1,5 @@
{
"itemGroup.betterend.items": "Better End",
"block.betterend.wet_mycelium": "Wet Mycelium",
"block.betterend.endstone_dust": "End Stone Dust"
}

View file

@ -0,0 +1,5 @@
{
"itemGroup.betterend.items": "Улучшенный Край",
"block.betterend.wet_mycelium": "Влажный мицелий",
"block.betterend.endstone_dust": "Эндерняковая пыль"
}

View file

@ -0,0 +1,6 @@
{
"parent": "block/cube_all",
"textures": {
"all": "betterend:block/endstone_dust"
}
}

View file

@ -0,0 +1,3 @@
{
"parent": "betterend:block/endstone_dust"
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB