More pots (WIP)
This commit is contained in:
parent
287e25bbcf
commit
13e5e9e088
13 changed files with 145 additions and 30 deletions
|
@ -3,66 +3,63 @@ package ru.betterend.blocks;
|
|||
import com.google.common.collect.Lists;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.mojang.math.Matrix4f;
|
||||
import com.mojang.math.Quaternion;
|
||||
import com.mojang.math.Transformation;
|
||||
import com.mojang.math.Vector3f;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.block.model.MultiVariant;
|
||||
import net.minecraft.client.renderer.block.model.Variant;
|
||||
import net.minecraft.client.renderer.block.model.BlockModel;
|
||||
import net.minecraft.client.resources.model.ModelResourceLocation;
|
||||
import net.minecraft.client.resources.model.UnbakedModel;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.packs.resources.Resource;
|
||||
import net.minecraft.server.packs.resources.ResourceManager;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
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.Level;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.StateDefinition;
|
||||
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.Shapes;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import ru.bclib.blocks.BaseBlockNotFull;
|
||||
import ru.bclib.client.models.ModelsHelper;
|
||||
import ru.bclib.client.models.ModelsHelper.MultiPartBuilder;
|
||||
import ru.bclib.client.models.PatternsHelper;
|
||||
import ru.bclib.client.render.BCLRenderLayer;
|
||||
import ru.bclib.interfaces.IPostInit;
|
||||
import ru.bclib.interfaces.IRenderTyped;
|
||||
import ru.bclib.interfaces.ISpetialItem;
|
||||
import ru.bclib.util.BlocksHelper;
|
||||
import ru.bclib.util.JsonFactory;
|
||||
import ru.bclib.util.MHelper;
|
||||
import ru.betterend.BetterEnd;
|
||||
import ru.betterend.client.models.Patterns;
|
||||
import ru.betterend.interfaces.PottablePlant;
|
||||
import ru.betterend.registry.EndBlocks;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
public class FlowerPotBlock extends BaseBlockNotFull implements IRenderTyped {
|
||||
private static final VoxelShape SHAPE = Block.box(4, 4, 4, 12, 12, 12);
|
||||
public class FlowerPotBlock extends BaseBlockNotFull implements IRenderTyped, IPostInit {
|
||||
private static final VoxelShape SHAPE = Block.box(4, 0, 4, 12, 8, 12);
|
||||
private static final IntegerProperty PLANT_ID = EndBlockProperties.PLANT_ID;
|
||||
private final ResourceLocation[] blocks;
|
||||
private static VoxelShape[] plantBoxes;
|
||||
private static Block[] blocks;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
private UnbakedModel source;
|
||||
|
||||
public FlowerPotBlock(Block source) {
|
||||
super(FabricBlockSettings.copyOf(source));
|
||||
List<ResourceLocation> blocks = Lists.newArrayList();
|
||||
EndBlocks.getModBlocks().forEach(block -> {
|
||||
if (block instanceof PottablePlant && block.getStateDefinition().getProperties().isEmpty()) {
|
||||
blocks.add(Registry.BLOCK.getKey(block));
|
||||
}
|
||||
});
|
||||
this.blocks = blocks.toArray(new ResourceLocation[] {});
|
||||
this.registerDefaultState(this.defaultBlockState().setValue(PLANT_ID, 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -71,6 +68,54 @@ public class FlowerPotBlock extends BaseBlockNotFull implements IRenderTyped {
|
|||
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
|
||||
@Environment(EnvType.CLIENT)
|
||||
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);
|
||||
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);
|
||||
for (int i = 0; i < blocks.length; i++) {
|
||||
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");
|
||||
if (Minecraft.getInstance().getResourceManager().hasResource(objSource)) {
|
||||
objSource = new ResourceLocation(modelPath.getNamespace(), "block/potted_" + modelPath.getPath());
|
||||
|
@ -114,7 +159,8 @@ public class FlowerPotBlock extends BaseBlockNotFull implements IRenderTyped {
|
|||
|
||||
@Override
|
||||
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
|
||||
|
|
|
@ -19,6 +19,7 @@ import ru.bclib.recipes.GridRecipe;
|
|||
import ru.bclib.util.TagHelper;
|
||||
import ru.betterend.BetterEnd;
|
||||
import ru.betterend.blocks.EndPedestal;
|
||||
import ru.betterend.blocks.FlowerPotBlock;
|
||||
import ru.betterend.blocks.basis.StoneLanternBlock;
|
||||
import ru.betterend.config.Configs;
|
||||
import ru.betterend.recipe.CraftingRecipes;
|
||||
|
@ -44,6 +45,7 @@ public class StoneMaterial {
|
|||
public final Block brick_slab;
|
||||
public final Block brick_wall;
|
||||
public final Block furnace;
|
||||
public final Block flowerPot;
|
||||
|
||||
public StoneMaterial(String name, 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_wall = EndBlocks.registerBlock(name + "_bricks_wall", new BaseWallBlock(bricks));
|
||||
furnace = EndBlocks.registerBlock(name + "_furnace", new BaseFurnaceBlock(bricks));
|
||||
flowerPot = EndBlocks.registerBlock(name + "_flower_pot", new FlowerPotBlock(bricks));
|
||||
|
||||
// Recipes //
|
||||
GridRecipe.make(BetterEnd.MOD_ID, name + "_bricks", bricks).checkConfig(Configs.RECIPE_CONFIG).setOutputCount(4).setShape("##", "##").addMaterial('#', stone).setGroup("end_bricks").build();
|
||||
|
|
|
@ -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_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_FLOWER_POT = BetterEnd.makeID("patterns/block/flower_pot.json");
|
||||
|
||||
//Item Models
|
||||
public final static ResourceLocation ITEM_WALL = BetterEnd.makeID("patterns/item/pattern_wall.json");
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package ru.betterend.mixin.client;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
import net.minecraft.client.resources.sounds.AbstractSoundInstance;
|
||||
import net.minecraft.client.resources.sounds.SoundInstance;
|
||||
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.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import ru.bclib.api.BiomeAPI;
|
||||
import ru.betterend.client.ClientOptions;
|
||||
import ru.betterend.world.biome.EndBiome;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
|
@ -41,7 +44,7 @@ public abstract class MusicTrackerMixin {
|
|||
public void be_onTick(CallbackInfo info) {
|
||||
if (ClientOptions.blendBiomeMusic()) {
|
||||
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 (srcVolume < 0) {
|
||||
srcVolume = currentMusic.getVolume();
|
||||
|
@ -80,8 +83,11 @@ public abstract class MusicTrackerMixin {
|
|||
}
|
||||
}
|
||||
|
||||
private boolean be_isInEnd() {
|
||||
return minecraft.level != null && minecraft.level.dimension().equals(Level.END);
|
||||
private boolean be_isCorrectBiome() {
|
||||
if (minecraft.level == null) {
|
||||
return false;
|
||||
}
|
||||
return BiomeAPI.getRenderBiome(minecraft.level.getBiome(minecraft.player.blockPosition())) instanceof EndBiome;
|
||||
}
|
||||
|
||||
private boolean be_shouldChangeSound(Music musicSound) {
|
||||
|
|
|
@ -191,6 +191,7 @@ public class EndBlocks extends BlocksRegistry {
|
|||
public static final Block BRIMSTONE = registerBlock("brimstone", new BrimstoneBlock());
|
||||
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 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_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());
|
||||
|
||||
// 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());
|
||||
|
||||
private static BlocksRegistry BLOCKS_REGISTRY;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue