fix sweetBerryBushLike plant item register error

This commit is contained in:
yyc12345 2021-05-04 15:00:54 +08:00
parent 74fe0fd9da
commit d8d90c3cb4
3 changed files with 60 additions and 36 deletions

View File

@ -1,6 +1,15 @@
package net.yyc12345.teyvatcraft.blocks; package net.yyc12345.teyvatcraft.blocks;
import java.util.Random;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.Fertilizable;
import net.minecraft.block.Material;
import net.minecraft.block.PlantBlock;
import net.minecraft.block.SweetBerryBushBlock; import net.minecraft.block.SweetBerryBushBlock;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
@ -8,21 +17,31 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemConvertible; import net.minecraft.item.ItemConvertible;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.Items; import net.minecraft.item.Items;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.BlockSoundGroup;
import net.minecraft.sound.SoundCategory; import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents; import net.minecraft.sound.SoundEvents;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.IntProperty;
import net.minecraft.state.property.Properties;
import net.minecraft.util.ActionResult; import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand; import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.BlockView;
import net.minecraft.world.World; import net.minecraft.world.World;
public class TeyvatSweetBerryBushLikePlantBlock extends SweetBerryBushBlock { public class TeyvatSweetBerryBushLikePlantBlock extends SweetBerryBushBlock {
private Item droppedItem; private Item droppedItem;
public TeyvatSweetBerryBushLikePlantBlock(Settings settings, Item droppedItem) { public TeyvatSweetBerryBushLikePlantBlock() {
super(settings); super(FabricBlockSettings.of(Material.PLANT).noCollision().breakInstantly().sounds(BlockSoundGroup.SWEET_BERRY_BUSH));
this.droppedItem = droppedItem; }
public void setDroppedItem(Item item) {
droppedItem = item;
} }
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
@ -52,3 +71,4 @@ public class TeyvatSweetBerryBushLikePlantBlock extends SweetBerryBushBlock {
return super.onUse(state, world, pos, player, hand, hit); return super.onUse(state, world, pos, player, hand, hit);
} }
} }

View File

@ -22,8 +22,8 @@ public class BlocksManager {
public static final Block WHITE_IRON_CHUNK_ORE = new OreBlock(getOreBlockSettings(2, 3.0f)); public static final Block WHITE_IRON_CHUNK_ORE = new OreBlock(getOreBlockSettings(2, 3.0f));
public static final Block IRON_CHUNK_ORE = new OreBlock(getOreBlockSettings(1, 3.0f)); public static final Block IRON_CHUNK_ORE = new OreBlock(getOreBlockSettings(1, 3.0f));
public static final Block STARSILVER_ORE = new OreBlock(getOreBlockSettings(1, 2.0f)); public static final Block STARSILVER_ORE = new OreBlock(getOreBlockSettings(1, 2.0f));
public static final Block NOCTILUCOUS_JADE = new OreBlock(getOreBlockSettings(1, 3.0f)); public static final Block NOCTILUCOUS_JADE_ORE = new OreBlock(getOreBlockSettings(1, 3.0f));
public static final Block COR_LAPIS = new OreBlock(getOreBlockSettings(1, 3.0f)); public static final Block COR_LAPIS_ORE = new OreBlock(getOreBlockSettings(1, 3.0f));
// ==================== crops // ==================== crops
public static final Block RICE = new TeyvatCropBlock(); public static final Block RICE = new TeyvatCropBlock();
@ -35,21 +35,21 @@ public class BlocksManager {
// flower & sweet berry bush like plant // flower & sweet berry bush like plant
public static final Block CALLA_LILY = new TeyvatFlowerLikePlantBlock(); public static final Block CALLA_LILY = new TeyvatFlowerLikePlantBlock();
public static final Block DANDELION_SEED = new TeyvatFlowerLikePlantBlock(); public static final Block DANDELION_SEED = new TeyvatFlowerLikePlantBlock();
public static final Block JUEYUN_CHILI = new TeyvatSweetBerryBushLikePlantBlock(ItemsManager.JUEYUN_CHILI); public static final Block JUEYUN_CHILI = new TeyvatSweetBerryBushLikePlantBlock();
public static final Block SMALL_LAMP_GRASS = new TeyvatFlowerLikePlantBlock(); public static final Block SMALL_LAMP_GRASS = new TeyvatFlowerLikePlantBlock();
public static final Block MINT = new TeyvatFlowerLikePlantBlock(); public static final Block MINT = new TeyvatFlowerLikePlantBlock();
public static final Block SWEET_FLOWER = new TeyvatFlowerLikePlantBlock(); public static final Block SWEET_FLOWER = new TeyvatFlowerLikePlantBlock();
public static final Block BERRY = new TeyvatSweetBerryBushLikePlantBlock(ItemsManager.BERRY); public static final Block BERRY = new TeyvatSweetBerryBushLikePlantBlock();
public static final Block SNAPDRAGON = new TeyvatFlowerLikePlantBlock(); public static final Block SNAPDRAGON = new TeyvatFlowerLikePlantBlock();
public static final Block MATSUTAKE = new TeyvatFlowerLikePlantBlock(); public static final Block MATSUTAKE = new TeyvatFlowerLikePlantBlock();
public static final Block HORSETAIL = new TeyvatFlowerLikePlantBlock(); public static final Block HORSETAIL = new TeyvatFlowerLikePlantBlock();
public static final Block CECILIA = new TeyvatFlowerLikePlantBlock(); public static final Block CECILIA = new TeyvatFlowerLikePlantBlock();
public static final Block GLAZE_LILY = new TeyvatFlowerLikePlantBlock(); public static final Block GLAZE_LILY = new TeyvatFlowerLikePlantBlock();
public static final Block PHILANEMO_MUSHROOM = new TeyvatFlowerLikePlantBlock(); public static final Block PHILANEMO_MUSHROOM = new TeyvatFlowerLikePlantBlock();
public static final Block SILK_FLOWER = new TeyvatSweetBerryBushLikePlantBlock(ItemsManager.SILK_FLOWER); public static final Block SILK_FLOWER = new TeyvatSweetBerryBushLikePlantBlock();
public static final Block VALBERRY = new TeyvatSweetBerryBushLikePlantBlock(ItemsManager.VALBERRY); public static final Block VALBERRY = new TeyvatSweetBerryBushLikePlantBlock();
public static final Block WINDWHEEL_ASTER = new TeyvatFlowerLikePlantBlock(); public static final Block WINDWHEEL_ASTER = new TeyvatFlowerLikePlantBlock();
public static final Block WOLFHOOK = new TeyvatSweetBerryBushLikePlantBlock(ItemsManager.WOLFHOOK); public static final Block WOLFHOOK = new TeyvatSweetBerryBushLikePlantBlock();
public static final Block QINGXIN = new TeyvatFlowerLikePlantBlock(); public static final Block QINGXIN = new TeyvatFlowerLikePlantBlock();
@ -63,10 +63,15 @@ public class BlocksManager {
Registry.register(Registry.BLOCK, new Identifier("teyvatcraft", name), bl); //register block self Registry.register(Registry.BLOCK, new Identifier("teyvatcraft", name), bl); //register block self
} }
private static void registerTeyvatPlant(Block bl, String name) { private static void registerTeyvatFlowerLikePlant(Block bl, String name) {
//BlockRenderLayerMap.INSTANCE.putBlock(bl, RenderLayer.getCutoutMipped()); // set transparent display mode BlockRenderLayerMap.INSTANCE.putBlock(bl, RenderLayer.getCutoutMipped()); // set transparent display mode
Registry.register(Registry.BLOCK, new Identifier("teyvatcraft", name), bl); Registry.register(Registry.BLOCK, new Identifier("teyvatcraft", name), bl);
} }
private static void registerTeyvatSweetBerryBushLikePlant(Block bl, String name, Item droppedItem) {
BlockRenderLayerMap.INSTANCE.putBlock(bl, RenderLayer.getCutoutMipped()); // set transparent display mode
Registry.register(Registry.BLOCK, new Identifier("teyvatcraft", name), bl);
((TeyvatSweetBerryBushLikePlantBlock)bl).setDroppedItem(droppedItem);
}
public static void RegisterAll() { public static void RegisterAll() {
Registry.register(Registry.BLOCK, new Identifier("teyvatcraft", "magical_crystal_chunk_ore"), MAGICAL_CRYSTAL_CHUNK_ORE); Registry.register(Registry.BLOCK, new Identifier("teyvatcraft", "magical_crystal_chunk_ore"), MAGICAL_CRYSTAL_CHUNK_ORE);
@ -74,8 +79,8 @@ public class BlocksManager {
Registry.register(Registry.BLOCK, new Identifier("teyvatcraft", "white_iron_chunk_ore"), WHITE_IRON_CHUNK_ORE); Registry.register(Registry.BLOCK, new Identifier("teyvatcraft", "white_iron_chunk_ore"), WHITE_IRON_CHUNK_ORE);
Registry.register(Registry.BLOCK, new Identifier("teyvatcraft", "iron_chunk_ore"), IRON_CHUNK_ORE); Registry.register(Registry.BLOCK, new Identifier("teyvatcraft", "iron_chunk_ore"), IRON_CHUNK_ORE);
Registry.register(Registry.BLOCK, new Identifier("teyvatcraft", "starsilver_ore"), STARSILVER_ORE); Registry.register(Registry.BLOCK, new Identifier("teyvatcraft", "starsilver_ore"), STARSILVER_ORE);
Registry.register(Registry.BLOCK, new Identifier("teyvatcraft", "noctilucous_jade_ore"), NOCTILUCOUS_JADE); Registry.register(Registry.BLOCK, new Identifier("teyvatcraft", "noctilucous_jade_ore"), NOCTILUCOUS_JADE_ORE);
Registry.register(Registry.BLOCK, new Identifier("teyvatcraft", "cor_lapis_ore"), COR_LAPIS); Registry.register(Registry.BLOCK, new Identifier("teyvatcraft", "cor_lapis_ore"), COR_LAPIS_ORE);
// crops // crops
registerCrop(RICE, ItemsManager.RICE_SEED, "rice"); registerCrop(RICE, ItemsManager.RICE_SEED, "rice");
@ -85,24 +90,24 @@ public class BlocksManager {
registerCrop(RADISH, ItemsManager.RADISH, "radish"); registerCrop(RADISH, ItemsManager.RADISH, "radish");
// flower & sweet berry bush like plant // flower & sweet berry bush like plant
registerTeyvatPlant(CALLA_LILY, "calla_lily"); registerTeyvatFlowerLikePlant(CALLA_LILY, "calla_lily");
registerTeyvatPlant(DANDELION_SEED, "dandelion_seed"); registerTeyvatFlowerLikePlant(DANDELION_SEED, "dandelion_seed");
registerTeyvatPlant(JUEYUN_CHILI, "jueyun_chili"); registerTeyvatSweetBerryBushLikePlant(JUEYUN_CHILI, "jueyun_chili", ItemsManager.JUEYUN_CHILI);
registerTeyvatPlant(SMALL_LAMP_GRASS, "small_lamp_grass"); registerTeyvatFlowerLikePlant(SMALL_LAMP_GRASS, "small_lamp_grass");
registerTeyvatPlant(MINT, "mint"); registerTeyvatFlowerLikePlant(MINT, "mint");
registerTeyvatPlant(SWEET_FLOWER, "sweet_flower"); registerTeyvatFlowerLikePlant(SWEET_FLOWER, "sweet_flower");
registerTeyvatPlant(BERRY, "berry"); registerTeyvatSweetBerryBushLikePlant(BERRY, "berry", ItemsManager.BERRY);
registerTeyvatPlant(SNAPDRAGON, "snapdragon"); registerTeyvatFlowerLikePlant(SNAPDRAGON, "snapdragon");
registerTeyvatPlant(MATSUTAKE, "matsutake"); registerTeyvatFlowerLikePlant(MATSUTAKE, "matsutake");
registerTeyvatPlant(HORSETAIL, "horsetail"); registerTeyvatFlowerLikePlant(HORSETAIL, "horsetail");
registerTeyvatPlant(CECILIA, "cecilia"); registerTeyvatFlowerLikePlant(CECILIA, "cecilia");
registerTeyvatPlant(GLAZE_LILY, "glaze_lily"); registerTeyvatFlowerLikePlant(GLAZE_LILY, "glaze_lily");
registerTeyvatPlant(PHILANEMO_MUSHROOM, "philanemo_mushroom"); registerTeyvatFlowerLikePlant(PHILANEMO_MUSHROOM, "philanemo_mushroom");
registerTeyvatPlant(SILK_FLOWER, "silk_flower"); registerTeyvatSweetBerryBushLikePlant(SILK_FLOWER, "silk_flower", ItemsManager.SILK_FLOWER);
registerTeyvatPlant(VALBERRY, "valberry"); registerTeyvatSweetBerryBushLikePlant(VALBERRY, "valberry", ItemsManager.VALBERRY);
registerTeyvatPlant(WINDWHEEL_ASTER, "windwheel_aster"); registerTeyvatFlowerLikePlant(WINDWHEEL_ASTER, "windwheel_aster");
registerTeyvatPlant(WOLFHOOK, "wolfhook"); registerTeyvatSweetBerryBushLikePlant(WOLFHOOK, "wolfhook", ItemsManager.WOLFHOOK);
registerTeyvatPlant(QINGXIN, "qingxin"); registerTeyvatFlowerLikePlant(QINGXIN, "qingxin");
} }

View File

@ -388,9 +388,9 @@ public class ItemsManager {
Registry.register(Registry.ITEM, new Identifier("teyvatcraft", "starsilver_ore"), Registry.register(Registry.ITEM, new Identifier("teyvatcraft", "starsilver_ore"),
new BlockItem(BlocksManager.STARSILVER_ORE, new Item.Settings().group(ITEMGROUP_MISC))); new BlockItem(BlocksManager.STARSILVER_ORE, new Item.Settings().group(ITEMGROUP_MISC)));
Registry.register(Registry.ITEM, new Identifier("teyvatcraft", "noctilucous_jade_ore"), Registry.register(Registry.ITEM, new Identifier("teyvatcraft", "noctilucous_jade_ore"),
new BlockItem(BlocksManager.NOCTILUCOUS_JADE, new Item.Settings().group(ITEMGROUP_MISC))); new BlockItem(BlocksManager.NOCTILUCOUS_JADE_ORE, new Item.Settings().group(ITEMGROUP_MISC)));
Registry.register(Registry.ITEM, new Identifier("teyvatcraft", "cor_lapis_ore"), Registry.register(Registry.ITEM, new Identifier("teyvatcraft", "cor_lapis_ore"),
new BlockItem(BlocksManager.COR_LAPIS, new Item.Settings().group(ITEMGROUP_MISC))); new BlockItem(BlocksManager.COR_LAPIS_ORE, new Item.Settings().group(ITEMGROUP_MISC)));
// crops & plants // crops & plants
registerAsCompostableItem("rice", RICE, false); registerAsCompostableItem("rice", RICE, false);
@ -402,7 +402,7 @@ public class ItemsManager {
Registry.register(Registry.ITEM, new Identifier("teyvatcraft", "calla_lily"), CALLA_LILY); Registry.register(Registry.ITEM, new Identifier("teyvatcraft", "calla_lily"), CALLA_LILY);
Registry.register(Registry.ITEM, new Identifier("teyvatcraft", "dandelion_seed"), DANDELION_SEED); Registry.register(Registry.ITEM, new Identifier("teyvatcraft", "dandelion_seed"), DANDELION_SEED);
Registry.register(Registry.ITEM, new Identifier("teyvatcraft", "jueyun_chili"), JUEYUN_CHILI);/* Registry.register(Registry.ITEM, new Identifier("teyvatcraft", "jueyun_chili"), JUEYUN_CHILI);
Registry.register(Registry.ITEM, new Identifier("teyvatcraft", "small_lamp_grass"), SMALL_LAMP_GRASS); Registry.register(Registry.ITEM, new Identifier("teyvatcraft", "small_lamp_grass"), SMALL_LAMP_GRASS);
Registry.register(Registry.ITEM, new Identifier("teyvatcraft", "mint"), MINT); Registry.register(Registry.ITEM, new Identifier("teyvatcraft", "mint"), MINT);
Registry.register(Registry.ITEM, new Identifier("teyvatcraft", "pepper"), PEPPER); Registry.register(Registry.ITEM, new Identifier("teyvatcraft", "pepper"), PEPPER);
@ -451,7 +451,6 @@ public class ItemsManager {
Registry.register(Registry.ITEM, new Identifier("teyvatcraft", "wolfhook"), WOLFHOOK); Registry.register(Registry.ITEM, new Identifier("teyvatcraft", "wolfhook"), WOLFHOOK);
Registry.register(Registry.ITEM, new Identifier("teyvatcraft", "qingxin"), QINGXIN); Registry.register(Registry.ITEM, new Identifier("teyvatcraft", "qingxin"), QINGXIN);
Registry.register(Registry.ITEM, new Identifier("teyvatcraft", "starconch"), STARCONCH); Registry.register(Registry.ITEM, new Identifier("teyvatcraft", "starconch"), STARCONCH);
*/
// drops // drops
Registry.register(Registry.ITEM, new Identifier("teyvatcraft", "agnidus_agate_sliver"), AGNIDUS_AGATE_SLIVER); Registry.register(Registry.ITEM, new Identifier("teyvatcraft", "agnidus_agate_sliver"), AGNIDUS_AGATE_SLIVER);