Pottable crops and fixes
This commit is contained in:
parent
7ba38c4b27
commit
868e983282
43 changed files with 536 additions and 53 deletions
|
@ -5,7 +5,6 @@ import net.minecraft.world.level.block.state.properties.BooleanProperty;
|
|||
import net.minecraft.world.level.block.state.properties.EnumProperty;
|
||||
import net.minecraft.world.level.block.state.properties.IntegerProperty;
|
||||
import ru.bclib.blocks.BlockProperties;
|
||||
import ru.bclib.blocks.properties.StringProperty;
|
||||
import ru.betterend.registry.EndPortals;
|
||||
|
||||
public class EndBlockProperties extends BlockProperties {
|
||||
|
@ -14,8 +13,8 @@ public class EndBlockProperties extends BlockProperties {
|
|||
public static final EnumProperty<CactusBottom> CACTUS_BOTTOM = EnumProperty.create("bottom", CactusBottom.class);
|
||||
|
||||
public static final IntegerProperty PORTAL = IntegerProperty.create("portal", 0, EndPortals.getCount());
|
||||
public static final IntegerProperty PLANT_ID = IntegerProperty.create("plant_id", 0, 127);
|
||||
public static final IntegerProperty SOIL_ID = IntegerProperty.create("soil_id", 0, 10);
|
||||
public static final IntegerProperty PLANT_ID = IntegerProperty.create("plant_id", 0, 63);
|
||||
public static final IntegerProperty SOIL_ID = IntegerProperty.create("soil_id", 0, 15);
|
||||
public static final BooleanProperty HAS_ITEM = BooleanProperty.create("has_item");
|
||||
|
||||
public enum PedestalState implements StringRepresentable {
|
||||
|
|
|
@ -56,4 +56,9 @@ public class FlamaeaBlock extends EndPlantBlock implements ISpetialItem {
|
|||
public boolean canPlaceOnWater() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addToPot() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
package ru.betterend.blocks;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.mojang.math.Transformation;
|
||||
|
@ -18,8 +16,6 @@ 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.PackResources;
|
||||
import net.minecraft.server.packs.PackType;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
|
@ -30,7 +26,6 @@ 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.LeavesBlock;
|
||||
import net.minecraft.world.level.block.SaplingBlock;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.StateDefinition;
|
||||
|
@ -41,35 +36,25 @@ import net.minecraft.world.phys.shapes.Shapes;
|
|||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
import ru.bclib.blocks.BaseBlockNotFull;
|
||||
import ru.bclib.client.models.BasePatterns;
|
||||
import ru.bclib.client.models.BlockModelProvider;
|
||||
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.betterend.BetterEnd;
|
||||
import ru.betterend.blocks.basis.EndTerrainBlock;
|
||||
import ru.betterend.blocks.basis.PottableLeavesBlock;
|
||||
import ru.betterend.client.models.Patterns;
|
||||
import ru.betterend.config.Configs;
|
||||
import ru.betterend.interfaces.PottablePlant;
|
||||
import ru.betterend.interfaces.PottableTerrain;
|
||||
import ru.betterend.registry.EndBlocks;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.SplittableRandom;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class FlowerPotBlock extends BaseBlockNotFull implements IRenderTyped, IPostInit {
|
||||
private static final IntegerProperty PLANT_ID = EndBlockProperties.PLANT_ID;
|
||||
|
@ -121,10 +106,10 @@ public class FlowerPotBlock extends BaseBlockNotFull implements IRenderTyped, IP
|
|||
}
|
||||
|
||||
EndBlocks.getModBlocks().forEach(block -> {
|
||||
if (block instanceof PottablePlant && canBeAdded(block)) {
|
||||
if (block instanceof PottablePlant && ((PottablePlant) block).addToPot()) {//&& canBeAdded(block)) {
|
||||
processBlock(plants, block, "flower_pots.plants", reservedPlantsIDs);
|
||||
}
|
||||
else if (block instanceof EndTerrainBlock) {
|
||||
else if (block instanceof PottableTerrain) {
|
||||
processBlock(soils, block, "flower_pots.soils", reservedSoilIDs);
|
||||
}
|
||||
});
|
||||
|
@ -154,22 +139,6 @@ public class FlowerPotBlock extends BaseBlockNotFull implements IRenderTyped, IP
|
|||
return max;
|
||||
}
|
||||
|
||||
private boolean canBeAdded(Block block) {
|
||||
if (block instanceof SaplingBlock) {
|
||||
return true;
|
||||
}
|
||||
else if (block instanceof PottableLeavesBlock) {
|
||||
return true;
|
||||
}
|
||||
else if (block instanceof ISpetialItem) {
|
||||
return !((ISpetialItem) block).canPlaceOnWater();
|
||||
}
|
||||
else if (block.getStateDefinition().getProperties().isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void processBlock(Block[] target, Block block, String path, Map<String, Integer> idMap) {
|
||||
ResourceLocation location = Registry.BLOCK.getKey(block);
|
||||
if (idMap.containsKey(location.getPath())) {
|
||||
|
@ -194,7 +163,7 @@ public class FlowerPotBlock extends BaseBlockNotFull implements IRenderTyped, IP
|
|||
}
|
||||
ItemStack itemStack = player.getItemInHand(hand);
|
||||
int soilID = state.getValue(SOIL_ID);
|
||||
if (soilID == 0 || soils[soilID - 1] == null) {
|
||||
if (soilID == 0 || soilID > soils.length || soils[soilID - 1] == null) {
|
||||
if (!(itemStack.getItem() instanceof BlockItem)) {
|
||||
return InteractionResult.PASS;
|
||||
}
|
||||
|
@ -210,12 +179,12 @@ public class FlowerPotBlock extends BaseBlockNotFull implements IRenderTyped, IP
|
|||
|
||||
int plantID = state.getValue(PLANT_ID);
|
||||
if (itemStack.isEmpty()) {
|
||||
if (plantID > 0 && plantID <= plants.length) {
|
||||
if (plantID > 0 && plantID <= plants.length && plants[plantID - 1] != null) {
|
||||
BlocksHelper.setWithUpdate(level, pos, state.setValue(PLANT_ID, 0));
|
||||
player.addItem(new ItemStack(plants[plantID - 1]));
|
||||
return InteractionResult.SUCCESS;
|
||||
}
|
||||
if (soilID > 0 && soilID <= soils.length) {
|
||||
if (soilID > 0 && soilID <= soils.length && soils[soilID - 1] != null) {
|
||||
BlocksHelper.setWithUpdate(level, pos, state.setValue(SOIL_ID, 0));
|
||||
player.addItem(new ItemStack(soils[soilID - 1]));
|
||||
}
|
||||
|
@ -295,14 +264,38 @@ public class FlowerPotBlock extends BaseBlockNotFull implements IRenderTyped, IP
|
|||
objSource = new ResourceLocation(modelPath.getNamespace(), "blockstates/" + modelPath.getPath() + ".json");
|
||||
JsonObject obj = JsonFactory.getJsonObject(objSource);
|
||||
if (obj != null) {
|
||||
JsonElement variants = obj.get("variants").getAsJsonObject().get("");
|
||||
JsonElement variants = obj.get("variants");
|
||||
JsonElement list = null;
|
||||
String path = null;
|
||||
|
||||
if (variants == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (variants.isJsonArray()) {
|
||||
path = variants.getAsJsonArray().get(0).getAsJsonObject().get("model").getAsString();
|
||||
list = variants.getAsJsonArray().get(0);
|
||||
}
|
||||
else if (variants.isJsonObject()) {
|
||||
list = variants.getAsJsonObject().get(((PottablePlant) plants[i]).getPottedState());
|
||||
}
|
||||
|
||||
if (list == null) {
|
||||
BetterEnd.LOGGER.warning("Incorrect json for pot plant " + objSource + ", no matching variants");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (list.isJsonArray()) {
|
||||
path = list.getAsJsonArray().get(0).getAsJsonObject().get("model").getAsString();
|
||||
}
|
||||
else {
|
||||
path = variants.getAsJsonObject().get("model").getAsString();
|
||||
path = list.getAsJsonObject().get("model").getAsString();
|
||||
}
|
||||
|
||||
if (path == null) {
|
||||
BetterEnd.LOGGER.warning("Incorrect json for pot plant " + objSource + ", no matching variants");
|
||||
continue;
|
||||
}
|
||||
|
||||
model.part(new ResourceLocation(path)).setTransformation(offset).setCondition(state -> state.getValue(PLANT_ID) == compareID).add();
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -2,6 +2,8 @@ package ru.betterend.blocks;
|
|||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.BlockPos.MutableBlockPos;
|
||||
|
@ -401,4 +403,10 @@ public class NeonCactusPlantBlock extends BaseBlockNotFull implements SimpleWate
|
|||
public boolean canPlantOn(Block block) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Environment(EnvType.CLIENT)
|
||||
public String getPottedState() {
|
||||
return "bottom=moss,shape=top,facing=up";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,11 +6,11 @@ import net.minecraft.world.level.block.Block;
|
|||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.phys.shapes.CollisionContext;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
import ru.bclib.blocks.BaseCropBlock;
|
||||
import ru.betterend.blocks.basis.PottableCropBlock;
|
||||
import ru.betterend.registry.EndBlocks;
|
||||
import ru.betterend.registry.EndItems;
|
||||
|
||||
public class ShadowBerryBlock extends BaseCropBlock {
|
||||
public class ShadowBerryBlock extends PottableCropBlock {
|
||||
private static final VoxelShape SHAPE = Block.box(1, 0, 1, 15, 8, 15);
|
||||
|
||||
public ShadowBerryBlock() {
|
||||
|
|
|
@ -2,6 +2,8 @@ package ru.betterend.blocks;
|
|||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
|
||||
import net.minecraft.core.BlockPos;
|
||||
|
@ -103,4 +105,10 @@ public class SmallJellyshroomBlock extends BaseAttachedBlock implements IRenderT
|
|||
public boolean canPlantOn(Block block) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Environment(EnvType.CLIENT)
|
||||
public String getPottedState() {
|
||||
return "facing=up";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,4 +36,9 @@ public class EndPlantBlock extends BasePlantBlock implements PottablePlant {
|
|||
public boolean canPlantOn(Block block) {
|
||||
return isTerrain(block.defaultBlockState());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addToPot() {
|
||||
return getStateDefinition().getProperties().isEmpty();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,8 +3,9 @@ package ru.betterend.blocks.basis;
|
|||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.material.MaterialColor;
|
||||
import ru.bclib.blocks.BaseTerrainBlock;
|
||||
import ru.betterend.interfaces.PottableTerrain;
|
||||
|
||||
public class EndTerrainBlock extends BaseTerrainBlock {
|
||||
public class EndTerrainBlock extends BaseTerrainBlock implements PottableTerrain {
|
||||
public EndTerrainBlock(MaterialColor color) {
|
||||
super(Blocks.END_STONE, color);
|
||||
}
|
||||
|
|
|
@ -3,9 +3,9 @@ package ru.betterend.blocks.basis;
|
|||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.material.MaterialColor;
|
||||
import ru.bclib.blocks.TripleTerrainBlock;
|
||||
import ru.betterend.interfaces.PottableTerrain;
|
||||
|
||||
public class EndTripleTerrain extends TripleTerrainBlock {
|
||||
|
||||
public class EndTripleTerrain extends TripleTerrainBlock implements PottableTerrain {
|
||||
public EndTripleTerrain(MaterialColor color) {
|
||||
super(Blocks.END_STONE, color);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
package ru.betterend.blocks.basis;
|
||||
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import ru.bclib.blocks.BaseCropBlock;
|
||||
import ru.betterend.interfaces.PottablePlant;
|
||||
|
||||
public class PottableCropBlock extends BaseCropBlock implements PottablePlant {
|
||||
private final Block[] terrain;
|
||||
|
||||
public PottableCropBlock(Item drop, Block... terrain) {
|
||||
super(drop, terrain);
|
||||
this.terrain = terrain;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPlantOn(Block block) {
|
||||
for (Block ter: terrain) {
|
||||
if (block == ter) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPottedState() {
|
||||
return "age=3";
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue