More pots (WIP)

This commit is contained in:
paulevsGitch 2021-07-11 13:24:04 +03:00
parent 287e25bbcf
commit 13e5e9e088
13 changed files with 145 additions and 30 deletions

View file

@ -3,66 +3,63 @@ package ru.betterend.blocks;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.mojang.math.Matrix4f;
import com.mojang.math.Quaternion;
import com.mojang.math.Transformation; import com.mojang.math.Transformation;
import com.mojang.math.Vector3f; import com.mojang.math.Vector3f;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.block.model.MultiVariant; import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.client.renderer.block.model.Variant;
import net.minecraft.client.resources.model.ModelResourceLocation; import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.client.resources.model.UnbakedModel; import net.minecraft.client.resources.model.UnbakedModel;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.resources.Resource; import net.minecraft.world.InteractionHand;
import net.minecraft.server.packs.resources.ResourceManager; import net.minecraft.world.InteractionResult;
import net.minecraft.util.Mth; import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition; import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.IntegerProperty; import net.minecraft.world.level.block.state.properties.IntegerProperty;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape; import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.Nullable;
import ru.bclib.blocks.BaseBlockNotFull; import ru.bclib.blocks.BaseBlockNotFull;
import ru.bclib.client.models.ModelsHelper; import ru.bclib.client.models.ModelsHelper;
import ru.bclib.client.models.ModelsHelper.MultiPartBuilder; import ru.bclib.client.models.ModelsHelper.MultiPartBuilder;
import ru.bclib.client.models.PatternsHelper;
import ru.bclib.client.render.BCLRenderLayer; import ru.bclib.client.render.BCLRenderLayer;
import ru.bclib.interfaces.IPostInit;
import ru.bclib.interfaces.IRenderTyped; import ru.bclib.interfaces.IRenderTyped;
import ru.bclib.interfaces.ISpetialItem;
import ru.bclib.util.BlocksHelper;
import ru.bclib.util.JsonFactory; import ru.bclib.util.JsonFactory;
import ru.bclib.util.MHelper; import ru.betterend.client.models.Patterns;
import ru.betterend.BetterEnd;
import ru.betterend.interfaces.PottablePlant; import ru.betterend.interfaces.PottablePlant;
import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndBlocks;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Optional;
public class FlowerPotBlock extends BaseBlockNotFull implements IRenderTyped { public class FlowerPotBlock extends BaseBlockNotFull implements IRenderTyped, IPostInit {
private static final VoxelShape SHAPE = Block.box(4, 4, 4, 12, 12, 12); private static final VoxelShape SHAPE = Block.box(4, 0, 4, 12, 8, 12);
private static final IntegerProperty PLANT_ID = EndBlockProperties.PLANT_ID; private static final IntegerProperty PLANT_ID = EndBlockProperties.PLANT_ID;
private final ResourceLocation[] blocks; private static VoxelShape[] plantBoxes;
private static Block[] blocks;
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
private UnbakedModel source; private UnbakedModel source;
public FlowerPotBlock(Block source) { public FlowerPotBlock(Block source) {
super(FabricBlockSettings.copyOf(source)); super(FabricBlockSettings.copyOf(source));
List<ResourceLocation> blocks = Lists.newArrayList(); this.registerDefaultState(this.defaultBlockState().setValue(PLANT_ID, 0));
EndBlocks.getModBlocks().forEach(block -> {
if (block instanceof PottablePlant && block.getStateDefinition().getProperties().isEmpty()) {
blocks.add(Registry.BLOCK.getKey(block));
}
});
this.blocks = blocks.toArray(new ResourceLocation[] {});
} }
@Override @Override
@ -71,6 +68,54 @@ public class FlowerPotBlock extends BaseBlockNotFull implements IRenderTyped {
builder.add(PLANT_ID); builder.add(PLANT_ID);
} }
@Override
public void postInit() {
if (this.blocks != null) {
return;
}
List<Block> blocks = Lists.newArrayList();
EndBlocks.getModBlocks().forEach(block -> {
if (block instanceof PottablePlant && block.getStateDefinition().getProperties().isEmpty()) {
if (!(block instanceof ISpetialItem) || !((ISpetialItem) block).canPlaceOnWater()) {
blocks.add(block);
}
}
});
FlowerPotBlock.blocks = blocks.toArray(new Block[] {});
FlowerPotBlock.plantBoxes = new VoxelShape[FlowerPotBlock.blocks.length];
for (int i = 0; i < FlowerPotBlock.blocks.length; i++) {
Block block = FlowerPotBlock.blocks[i];
VoxelShape shape = block.getShape(block.defaultBlockState(), null, BlockPos.ZERO, CollisionContext.empty());
plantBoxes[i] = Shapes.or(SHAPE, shape.move(0.25, 0.5, 0.25));
}
}
@Override
public InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
if (level.isClientSide) {
return InteractionResult.CONSUME;
}
ItemStack itemStack = player.getItemInHand(hand);
if (!(itemStack.getItem() instanceof BlockItem)) {
return InteractionResult.PASS;
}
BlockItem item = (BlockItem) itemStack.getItem();
for (int i = 0; i < blocks.length; i++) {
if (item.getBlock() == blocks[i]) {
BlocksHelper.setWithUpdate(level, pos, state.setValue(PLANT_ID, i + 1));
return InteractionResult.SUCCESS;
}
}
return InteractionResult.PASS;
}
@Override
@Environment(EnvType.CLIENT)
public BlockModel getItemModel(ResourceLocation blockId) {
Optional<String> pattern = PatternsHelper.createJson(Patterns.BLOCK_FLOWER_POT, blockId);
return ModelsHelper.fromPattern(pattern);
}
@Override @Override
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) { public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
@ -81,11 +126,11 @@ public class FlowerPotBlock extends BaseBlockNotFull implements IRenderTyped {
} }
MultiPartBuilder model = MultiPartBuilder.create(stateDefinition); MultiPartBuilder model = MultiPartBuilder.create(stateDefinition);
model.part(new ResourceLocation("block/flower_pot")).add(); model.part(new ModelResourceLocation(stateId.getNamespace(), stateId.getPath(), "inventory")).add();
Transformation offset = new Transformation(new Vector3f(0, 0.5F, 0), null, null, null); Transformation offset = new Transformation(new Vector3f(0, 0.5F, 0), null, null, null);
for (int i = 0; i < blocks.length; i++) { for (int i = 0; i < blocks.length; i++) {
final int compareID = i + 1; final int compareID = i + 1;
ResourceLocation modelPath = blocks[i]; ResourceLocation modelPath = Registry.BLOCK.getKey(blocks[i]);
ResourceLocation objSource = new ResourceLocation(modelPath.getNamespace(), "block/potted_" + modelPath.getPath() + ".json"); ResourceLocation objSource = new ResourceLocation(modelPath.getNamespace(), "block/potted_" + modelPath.getPath() + ".json");
if (Minecraft.getInstance().getResourceManager().hasResource(objSource)) { if (Minecraft.getInstance().getResourceManager().hasResource(objSource)) {
objSource = new ResourceLocation(modelPath.getNamespace(), "block/potted_" + modelPath.getPath()); objSource = new ResourceLocation(modelPath.getNamespace(), "block/potted_" + modelPath.getPath());
@ -114,7 +159,8 @@ public class FlowerPotBlock extends BaseBlockNotFull implements IRenderTyped {
@Override @Override
public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) { public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) {
return SHAPE; int id = state.getValue(PLANT_ID);
return id > 0 && id <= blocks.length ? plantBoxes[id - 1] : SHAPE;
} }
@Override @Override

View file

@ -19,6 +19,7 @@ import ru.bclib.recipes.GridRecipe;
import ru.bclib.util.TagHelper; import ru.bclib.util.TagHelper;
import ru.betterend.BetterEnd; import ru.betterend.BetterEnd;
import ru.betterend.blocks.EndPedestal; import ru.betterend.blocks.EndPedestal;
import ru.betterend.blocks.FlowerPotBlock;
import ru.betterend.blocks.basis.StoneLanternBlock; import ru.betterend.blocks.basis.StoneLanternBlock;
import ru.betterend.config.Configs; import ru.betterend.config.Configs;
import ru.betterend.recipe.CraftingRecipes; import ru.betterend.recipe.CraftingRecipes;
@ -44,6 +45,7 @@ public class StoneMaterial {
public final Block brick_slab; public final Block brick_slab;
public final Block brick_wall; public final Block brick_wall;
public final Block furnace; public final Block furnace;
public final Block flowerPot;
public StoneMaterial(String name, MaterialColor color) { public StoneMaterial(String name, MaterialColor color) {
FabricBlockSettings material = FabricBlockSettings.copyOf(Blocks.END_STONE).materialColor(color); FabricBlockSettings material = FabricBlockSettings.copyOf(Blocks.END_STONE).materialColor(color);
@ -65,6 +67,7 @@ public class StoneMaterial {
brick_slab = EndBlocks.registerBlock(name + "_bricks_slab", new BaseSlabBlock(bricks)); brick_slab = EndBlocks.registerBlock(name + "_bricks_slab", new BaseSlabBlock(bricks));
brick_wall = EndBlocks.registerBlock(name + "_bricks_wall", new BaseWallBlock(bricks)); brick_wall = EndBlocks.registerBlock(name + "_bricks_wall", new BaseWallBlock(bricks));
furnace = EndBlocks.registerBlock(name + "_furnace", new BaseFurnaceBlock(bricks)); furnace = EndBlocks.registerBlock(name + "_furnace", new BaseFurnaceBlock(bricks));
flowerPot = EndBlocks.registerBlock(name + "_flower_pot", new FlowerPotBlock(bricks));
// Recipes // // Recipes //
GridRecipe.make(BetterEnd.MOD_ID, name + "_bricks", bricks).checkConfig(Configs.RECIPE_CONFIG).setOutputCount(4).setShape("##", "##").addMaterial('#', stone).setGroup("end_bricks").build(); GridRecipe.make(BetterEnd.MOD_ID, name + "_bricks", bricks).checkConfig(Configs.RECIPE_CONFIG).setOutputCount(4).setShape("##", "##").addMaterial('#', stone).setGroup("end_bricks").build();

View file

@ -74,6 +74,7 @@ public class Patterns {
public final static ResourceLocation BLOCK_FURNACE_LIT = BetterEnd.makeID("patterns/block/furnace_glow.json"); public final static ResourceLocation BLOCK_FURNACE_LIT = BetterEnd.makeID("patterns/block/furnace_glow.json");
public final static ResourceLocation BLOCK_TOP_SIDE_BOTTOM = BetterEnd.makeID("patterns/block/top_side_bottom.json"); public final static ResourceLocation BLOCK_TOP_SIDE_BOTTOM = BetterEnd.makeID("patterns/block/top_side_bottom.json");
public final static ResourceLocation BLOCK_PATH = BetterEnd.makeID("patterns/block/path.json"); public final static ResourceLocation BLOCK_PATH = BetterEnd.makeID("patterns/block/path.json");
public final static ResourceLocation BLOCK_FLOWER_POT = BetterEnd.makeID("patterns/block/flower_pot.json");
//Item Models //Item Models
public final static ResourceLocation ITEM_WALL = BetterEnd.makeID("patterns/item/pattern_wall.json"); public final static ResourceLocation ITEM_WALL = BetterEnd.makeID("patterns/item/pattern_wall.json");

View file

@ -1,6 +1,7 @@
package ru.betterend.mixin.client; package ru.betterend.mixin.client;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.client.resources.sounds.AbstractSoundInstance; import net.minecraft.client.resources.sounds.AbstractSoundInstance;
import net.minecraft.client.resources.sounds.SoundInstance; import net.minecraft.client.resources.sounds.SoundInstance;
import net.minecraft.client.sounds.MusicManager; import net.minecraft.client.sounds.MusicManager;
@ -13,7 +14,9 @@ import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import ru.bclib.api.BiomeAPI;
import ru.betterend.client.ClientOptions; import ru.betterend.client.ClientOptions;
import ru.betterend.world.biome.EndBiome;
import java.util.Random; import java.util.Random;
@ -41,7 +44,7 @@ public abstract class MusicTrackerMixin {
public void be_onTick(CallbackInfo info) { public void be_onTick(CallbackInfo info) {
if (ClientOptions.blendBiomeMusic()) { if (ClientOptions.blendBiomeMusic()) {
Music musicSound = minecraft.getSituationalMusic(); Music musicSound = minecraft.getSituationalMusic();
if (be_checkNullSound(musicSound) && volume > 0 && be_isInEnd() && be_shouldChangeSound(musicSound)) { if (be_checkNullSound(musicSound) && volume > 0 && be_shouldChangeSound(musicSound) && be_isCorrectBiome()) {
if (volume > 0) { if (volume > 0) {
if (srcVolume < 0) { if (srcVolume < 0) {
srcVolume = currentMusic.getVolume(); srcVolume = currentMusic.getVolume();
@ -80,8 +83,11 @@ public abstract class MusicTrackerMixin {
} }
} }
private boolean be_isInEnd() { private boolean be_isCorrectBiome() {
return minecraft.level != null && minecraft.level.dimension().equals(Level.END); if (minecraft.level == null) {
return false;
}
return BiomeAPI.getRenderBiome(minecraft.level.getBiome(minecraft.player.blockPosition())) instanceof EndBiome;
} }
private boolean be_shouldChangeSound(Music musicSound) { private boolean be_shouldChangeSound(Music musicSound) {

View file

@ -191,6 +191,7 @@ public class EndBlocks extends BlocksRegistry {
public static final Block BRIMSTONE = registerBlock("brimstone", new BrimstoneBlock()); public static final Block BRIMSTONE = registerBlock("brimstone", new BrimstoneBlock());
public static final Block SULPHUR_CRYSTAL = registerBlock("sulphur_crystal", new SulphurCrystalBlock()); public static final Block SULPHUR_CRYSTAL = registerBlock("sulphur_crystal", new SulphurCrystalBlock());
public static final Block MISSING_TILE = registerBlock("missing_tile", new MissingTileBlock()); public static final Block MISSING_TILE = registerBlock("missing_tile", new MissingTileBlock());
public static final Block ENDSTONE_FLOWER_POT = registerBlock("endstone_flower_pot", new FlowerPotBlock(Blocks.END_STONE));
public static final Block FLAVOLITE_RUNED = registerBlock("flavolite_runed", new RunedFlavolite(false)); public static final Block FLAVOLITE_RUNED = registerBlock("flavolite_runed", new RunedFlavolite(false));
public static final Block FLAVOLITE_RUNED_ETERNAL = registerBlock("flavolite_runed_eternal", new RunedFlavolite(true)); public static final Block FLAVOLITE_RUNED_ETERNAL = registerBlock("flavolite_runed_eternal", new RunedFlavolite(true));
@ -424,7 +425,6 @@ public class EndBlocks extends BlocksRegistry {
public static final Block AETERNIUM_ANVIL = registerBlock("aeternium_anvil", new AeterniumAnvil()); public static final Block AETERNIUM_ANVIL = registerBlock("aeternium_anvil", new AeterniumAnvil());
// Technical // Technical
public static final Block ENDSTONE_FLOWER_POT = registerBlock("endstone_flower_pot", new FlowerPotBlock(Blocks.END_STONE));
public static final Block END_PORTAL_BLOCK = registerEndBlockOnly("end_portal_block", new EndPortalBlock()); public static final Block END_PORTAL_BLOCK = registerEndBlockOnly("end_portal_block", new EndPortalBlock());
private static BlocksRegistry BLOCKS_REGISTRY; private static BlocksRegistry BLOCKS_REGISTRY;

View file

@ -0,0 +1,59 @@
{
"__comment": "Designed by Paulevs with Cubik Studio - https://cubik.studio",
"parent": "block/block",
"textures": {
"particle": "betterend:block/%texture%",
"texture": "betterend:block/%texture%"
},
"elements": [
{
"__comment": "Box1",
"from": [ 4, 7, 4 ],
"to": [ 12, 8, 12 ],
"faces": {
"down": { "uv": [ 4, 4, 12, 12 ], "texture": "#texture" },
"up": { "uv": [ 8, 0, 16, 8 ], "texture": "#texture" },
"north": { "uv": [ 0, 0, 8, 1 ], "texture": "#texture" },
"south": { "uv": [ 0, 0, 8, 1 ], "texture": "#texture" },
"west": { "uv": [ 0, 0, 8, 1 ], "texture": "#texture" },
"east": { "uv": [ 0, 0, 8, 1 ], "texture": "#texture" }
}
},
{
"__comment": "Box1",
"from": [ 5, 0, 5 ],
"to": [ 11, 1, 11 ],
"faces": {
"down": { "uv": [ 9, 9, 15, 15 ], "texture": "#texture", "cullface": "down" },
"north": { "uv": [ 1, 7, 7, 8 ], "texture": "#texture" },
"south": { "uv": [ 1, 7, 7, 8 ], "texture": "#texture" },
"west": { "uv": [ 1, 7, 7, 8 ], "texture": "#texture" },
"east": { "uv": [ 1, 7, 7, 8 ], "texture": "#texture" }
}
},
{
"__comment": "Box1",
"from": [ 4, 1, 4 ],
"to": [ 12, 6, 12 ],
"faces": {
"down": { "uv": [ 8, 8, 16, 16 ], "texture": "#texture" },
"up": { "uv": [ 8, 0, 16, 8 ], "texture": "#texture" },
"north": { "uv": [ 0, 2, 8, 7 ], "texture": "#texture" },
"south": { "uv": [ 0, 2, 8, 7 ], "texture": "#texture" },
"west": { "uv": [ 0, 2, 8, 7 ], "texture": "#texture" },
"east": { "uv": [ 0, 2, 8, 7 ], "texture": "#texture" }
}
},
{
"__comment": "Box1",
"from": [ 4.5, 6, 4.5 ],
"to": [ 11.5, 7, 11.5 ],
"faces": {
"north": { "uv": [ 1, 1, 8, 2 ], "texture": "#texture" },
"south": { "uv": [ 1, 1, 8, 2 ], "texture": "#texture" },
"west": { "uv": [ 1, 1, 8, 2 ], "texture": "#texture" },
"east": { "uv": [ 1, 1, 8, 2 ], "texture": "#texture" }
}
}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 263 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 280 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 298 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 263 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 270 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 538 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 263 B