working disabled_recipes list
This commit is contained in:
		
							parent
							
								
									43b806a0b3
								
							
						
					
					
						commit
						5b15d7d55a
					
				| @ -1,9 +1,12 @@ | ||||
| package com.jenny.magic; | ||||
| 
 | ||||
| import com.jenny.magic.blocks.blocks; | ||||
| import com.jenny.magic.blocks.conditions.conditions; | ||||
| import com.jenny.magic.blocks.entities.blockEntities; | ||||
| import com.jenny.magic.config.ConfigServer; | ||||
| import com.jenny.magic.entities.entities; | ||||
| import com.jenny.magic.items.items; | ||||
| import net.minecraftforge.api.distmarker.Dist; | ||||
| import com.mojang.logging.LogUtils; | ||||
| import net.minecraftforge.common.MinecraftForge; | ||||
| import net.minecraftforge.eventbus.api.IEventBus; | ||||
| import net.minecraftforge.eventbus.api.SubscribeEvent; | ||||
| @ -11,29 +14,39 @@ import net.minecraftforge.fml.ModLoadingContext; | ||||
| import net.minecraftforge.fml.common.Mod; | ||||
| import net.minecraftforge.fml.config.ModConfig; | ||||
| import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; | ||||
| import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; | ||||
| import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; | ||||
| import org.slf4j.Logger; | ||||
| 
 | ||||
| // The value here should match an entry in the META-INF/mods.toml file | ||||
| @Mod(Magic.MODID) | ||||
| public class Magic { | ||||
|     public static final String MODID = "magic"; | ||||
|     private static final Logger LOGGER = LogUtils.getLogger(); | ||||
| 
 | ||||
|     public Magic() { | ||||
|         IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus(); | ||||
|         MinecraftForge.EVENT_BUS.register(this); | ||||
|         ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, ConfigServer.SPEC, "magic-server.toml"); | ||||
| 
 | ||||
|         entities.register(modEventBus); | ||||
|         items.register(modEventBus); | ||||
|         blocks.register(modEventBus); | ||||
|         blockEntities.register(modEventBus); | ||||
|         creativeTab.register(modEventBus); | ||||
|         ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, ConfigServer.SPEC, "magic-server.toml"); | ||||
|     } | ||||
| 
 | ||||
|     @Mod.EventBusSubscriber(modid = MODID, bus = Mod.EventBusSubscriber.Bus.MOD, value = Dist.CLIENT) | ||||
|     public static class ClientModEvents { | ||||
|     @Mod.EventBusSubscriber(modid = MODID, bus = Mod.EventBusSubscriber.Bus.MOD) | ||||
|     public static class ModEvents { | ||||
| 
 | ||||
|         @SubscribeEvent | ||||
|         public static void onClientSetup(FMLClientSetupEvent event) { | ||||
|             entities.registerRenderers(); | ||||
|         } | ||||
| 
 | ||||
|         @SubscribeEvent | ||||
|         public static void onCommonSetup(FMLCommonSetupEvent event) { | ||||
|             conditions.register(); | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
							
								
								
									
										39
									
								
								src/main/java/com/jenny/magic/blocks/AntiSpawner.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								src/main/java/com/jenny/magic/blocks/AntiSpawner.java
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,39 @@ | ||||
| package com.jenny.magic.blocks; | ||||
| 
 | ||||
| import com.jenny.magic.blocks.entities.AntiSpawnerBE; | ||||
| import com.jenny.magic.blocks.entities.blockEntities; | ||||
| import net.minecraft.core.BlockPos; | ||||
| import net.minecraft.world.level.Level; | ||||
| import net.minecraft.world.level.block.BaseEntityBlock; | ||||
| import net.minecraft.world.level.block.Block; | ||||
| import net.minecraft.world.level.block.entity.BlockEntity; | ||||
| import net.minecraft.world.level.block.entity.BlockEntityTicker; | ||||
| import net.minecraft.world.level.block.entity.BlockEntityType; | ||||
| import net.minecraft.world.level.block.state.BlockState; | ||||
| import net.minecraft.world.phys.shapes.VoxelShape; | ||||
| import org.jetbrains.annotations.NotNull; | ||||
| import org.jetbrains.annotations.Nullable; | ||||
| 
 | ||||
| public class AntiSpawner extends BaseEntityBlock { | ||||
|     public static final VoxelShape SHAPE = Block.box(0, 0, 0, 16, 16, 16); | ||||
| 
 | ||||
|     protected AntiSpawner(Properties pProperties) { | ||||
|         super(pProperties); | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public @Nullable BlockEntity newBlockEntity(BlockPos pPos, BlockState pState) { | ||||
|         return new AntiSpawnerBE(pPos, pState); | ||||
|     } | ||||
| 
 | ||||
|     @Nullable | ||||
|     @Override | ||||
|     public <T extends BlockEntity> BlockEntityTicker<T> getTicker(@NotNull Level pLevel, @NotNull BlockState pState, @NotNull BlockEntityType<T> pBlockEntityType) { | ||||
|         if (pLevel.isClientSide()) { | ||||
|             return null; | ||||
|         } | ||||
| 
 | ||||
|         return createTickerHelper(pBlockEntityType, blockEntities.ANTI_SPAWNER_BE.get(), | ||||
|                 (pLevel1, pPos, pState1, pBlockEntity) -> pBlockEntity.tick(pLevel1, pPos, pState1)); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										26
									
								
								src/main/java/com/jenny/magic/blocks/blocks.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								src/main/java/com/jenny/magic/blocks/blocks.java
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,26 @@ | ||||
| package com.jenny.magic.blocks; | ||||
| 
 | ||||
| import com.jenny.magic.items.BlockItemTooltip; | ||||
| import net.minecraft.world.item.Item; | ||||
| import net.minecraft.world.level.block.Block; | ||||
| import net.minecraft.world.level.block.state.BlockBehaviour; | ||||
| import net.minecraftforge.eventbus.api.IEventBus; | ||||
| import net.minecraftforge.registries.DeferredRegister; | ||||
| import net.minecraftforge.registries.ForgeRegistries; | ||||
| import net.minecraftforge.registries.RegistryObject; | ||||
| 
 | ||||
| import static com.jenny.magic.Magic.MODID; | ||||
| 
 | ||||
| public class blocks { | ||||
|     public static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, MODID); | ||||
|     public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, MODID); | ||||
| 
 | ||||
|     public static final RegistryObject<Block> ANTI_SPAWNER = BLOCKS.register("anti_spawner", () -> new AntiSpawner(BlockBehaviour.Properties.of().strength(10.0F, 15.0F))); | ||||
|     public static final RegistryObject<Item> ANTI_SPAWNER_ITEM = ITEMS.register("anti_spawner", () -> new BlockItemTooltip(ANTI_SPAWNER.get(), new Item.Properties())); | ||||
| 
 | ||||
| 
 | ||||
|     public static void register(IEventBus bus) { | ||||
|         BLOCKS.register(bus); | ||||
|         ITEMS.register(bus); | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,40 @@ | ||||
| package com.jenny.magic.blocks.conditions; | ||||
| 
 | ||||
| import com.google.gson.JsonObject; | ||||
| import net.minecraft.resources.ResourceLocation; | ||||
| import net.minecraftforge.common.ForgeConfigSpec; | ||||
| import net.minecraftforge.common.crafting.conditions.ICondition; | ||||
| import net.minecraftforge.common.crafting.conditions.IConditionSerializer; | ||||
| 
 | ||||
| import java.util.List; | ||||
| 
 | ||||
| import static com.jenny.magic.Magic.MODID; | ||||
| 
 | ||||
| public class ConfigCondition implements IConditionSerializer<ConfigCondition>, ICondition { | ||||
|     public ForgeConfigSpec.ConfigValue<List<String>> list; | ||||
|     public String name; | ||||
| 
 | ||||
|     public ConfigCondition(String name, ForgeConfigSpec.ConfigValue<List<String>> configListDisabled) { | ||||
|         this.list = configListDisabled; | ||||
|         this.name = name; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public void write(JsonObject json, ConfigCondition value) { | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public ConfigCondition read(JsonObject json) { | ||||
|         return this; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public ResourceLocation getID() { | ||||
|         return new ResourceLocation(MODID, name); | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public boolean test(IContext context) { | ||||
|         return list.get().contains(name); | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,27 @@ | ||||
| package com.jenny.magic.blocks.conditions; | ||||
| 
 | ||||
| import com.jenny.magic.blocks.blocks; | ||||
| import com.jenny.magic.config.ConfigServer; | ||||
| import com.jenny.magic.items.items; | ||||
| import net.minecraft.world.item.Item; | ||||
| import net.minecraftforge.common.crafting.CraftingHelper; | ||||
| import net.minecraftforge.registries.RegistryObject; | ||||
| 
 | ||||
| import java.util.ArrayList; | ||||
| import java.util.List; | ||||
| 
 | ||||
| public class conditions { | ||||
|     public static void register() { | ||||
|         for (RegistryObject<Item> item : items()) { | ||||
|             String name = item.get().toString(); | ||||
|             System.out.println("test123: " + name); | ||||
|             CraftingHelper.register(new ConfigCondition(name, ConfigServer.C_DISABLED_LIST)); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     private static List<RegistryObject<Item>> items() { | ||||
|         ArrayList<RegistryObject<Item>> l = new ArrayList<>(items.ITEMS.getEntries().stream().toList()); | ||||
|         l.addAll(blocks.ITEMS.getEntries().stream().toList()); | ||||
|         return l; | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,30 @@ | ||||
| package com.jenny.magic.blocks.entities; | ||||
| 
 | ||||
| import net.minecraft.core.BlockPos; | ||||
| import net.minecraft.world.entity.Entity; | ||||
| import net.minecraft.world.entity.MobSpawnType; | ||||
| import net.minecraft.world.entity.monster.Monster; | ||||
| import net.minecraft.world.level.Level; | ||||
| import net.minecraft.world.level.block.entity.BlockEntity; | ||||
| import net.minecraft.world.level.block.state.BlockState; | ||||
| import net.minecraft.world.phys.AABB; | ||||
| 
 | ||||
| public class AntiSpawnerBE extends BlockEntity { | ||||
|     protected final AABB area; | ||||
| 
 | ||||
|     public AntiSpawnerBE(BlockPos pPos, BlockState pBlockState) { | ||||
|         super(blockEntities.ANTI_SPAWNER_BE.get(), pPos, pBlockState); | ||||
|         area = new AABB(this.getBlockPos()).inflate(32); | ||||
|     } | ||||
| 
 | ||||
|     public void tick(Level pLevel, BlockPos pPos, BlockState pState) { | ||||
|         if (!pLevel.isClientSide) { | ||||
|             for (Entity e : pLevel.getEntities(null, area)) { | ||||
|                 if (e instanceof Monster && ((Monster) e).getSpawnType() == MobSpawnType.NATURAL) { | ||||
|                     e.remove(Entity.RemovalReason.KILLED); | ||||
|                     e.remove(Entity.RemovalReason.KILLED); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,24 @@ | ||||
| package com.jenny.magic.blocks.entities; | ||||
| 
 | ||||
| import com.jenny.magic.blocks.blocks; | ||||
| import net.minecraft.world.level.block.entity.BlockEntityType; | ||||
| import net.minecraftforge.eventbus.api.IEventBus; | ||||
| import net.minecraftforge.registries.DeferredRegister; | ||||
| import net.minecraftforge.registries.ForgeRegistries; | ||||
| import net.minecraftforge.registries.RegistryObject; | ||||
| 
 | ||||
| import static com.jenny.magic.Magic.MODID; | ||||
| 
 | ||||
| public class blockEntities { | ||||
|     public static final DeferredRegister<BlockEntityType<?>> BLOCK_ENTITIES = | ||||
|             DeferredRegister.create(ForgeRegistries.BLOCK_ENTITY_TYPES, MODID); | ||||
| 
 | ||||
|     public static void register(IEventBus bus) { | ||||
|         BLOCK_ENTITIES.register(bus); | ||||
|     }    public static final RegistryObject<BlockEntityType<AntiSpawnerBE>> ANTI_SPAWNER_BE = | ||||
|             BLOCK_ENTITIES.register("anti_spawner_be", () -> | ||||
|                     BlockEntityType.Builder.of(AntiSpawnerBE::new, | ||||
|                             blocks.ANTI_SPAWNER.get()).build(null)); | ||||
| 
 | ||||
| 
 | ||||
| } | ||||
| @ -3,12 +3,16 @@ package com.jenny.magic.config; | ||||
| import net.minecraftforge.common.ForgeConfigSpec; | ||||
| import net.minecraftforge.fml.common.Mod; | ||||
| 
 | ||||
| import java.util.ArrayList; | ||||
| import java.util.List; | ||||
| 
 | ||||
| import static com.jenny.magic.Magic.MODID; | ||||
| 
 | ||||
| @Mod.EventBusSubscriber(modid = MODID, bus = Mod.EventBusSubscriber.Bus.MOD) | ||||
| public class ConfigServer { | ||||
|     public static final ForgeConfigSpec SPEC; | ||||
|     public static final ForgeConfigSpec.ConfigValue<Integer> C_TELEPORT_SCROLL_RANGE, C_TELEPORT_SCROLL_RANGE_RANDOM; | ||||
|     public static final ForgeConfigSpec.ConfigValue<List<String>> C_DISABLED_LIST; | ||||
|     private static final ForgeConfigSpec.Builder BUILDER = new ForgeConfigSpec.Builder(); | ||||
| 
 | ||||
|     static { | ||||
| @ -18,7 +22,20 @@ public class ConfigServer { | ||||
|         C_TELEPORT_SCROLL_RANGE_RANDOM = | ||||
|                 BUILDER.comment("maximum range for all teleport scrolls with random targets") | ||||
|                         .defineInRange("scroll_teleport_random_range", 30000000, 0, 30000000); | ||||
| 
 | ||||
|         C_DISABLED_LIST = | ||||
|                 BUILDER.comment("add any items (without mod ID) from this mod to this list to disable their recipes") | ||||
|                         .define("disabled_items", defaultListDisabled()); | ||||
|         SPEC = BUILDER.build(); | ||||
|     } | ||||
| 
 | ||||
|     public static boolean isRecipeDisabled(String item) { | ||||
|         return C_DISABLED_LIST.get().contains(item); | ||||
|     } | ||||
| 
 | ||||
|     private static List<String> defaultListDisabled() { | ||||
|         List<String> l = new ArrayList<>(); | ||||
|         l.add("item_1"); | ||||
|         l.add("item_2"); | ||||
|         return l; | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -1,5 +1,6 @@ | ||||
| package com.jenny.magic; | ||||
| 
 | ||||
| import com.jenny.magic.blocks.blocks; | ||||
| import com.jenny.magic.items.items; | ||||
| import net.minecraft.core.registries.Registries; | ||||
| import net.minecraft.network.chat.Component; | ||||
| @ -18,6 +19,7 @@ import static com.jenny.magic.Magic.MODID; | ||||
| public class creativeTab { | ||||
|     public static final DeferredRegister<CreativeModeTab> CREATIVE_MODE_TABS = DeferredRegister.create(Registries.CREATIVE_MODE_TAB, MODID); | ||||
|     public static final RegistryObject<CreativeModeTab> CREATIVE_TAB = CREATIVE_MODE_TABS.register(MODID, () -> CreativeModeTab.builder().withTabsBefore(CreativeModeTabs.SPAWN_EGGS).icon(() -> items.WAND_HURTFUL.get().getDefaultInstance()).displayItems((parameters, output) -> { | ||||
|         output.acceptAll(Arrays.stream(getBlocks()).toList()); | ||||
|         output.acceptAll(Arrays.stream(getItems()).toList()); | ||||
|     }).title(Component.literal("Magic")).build()); | ||||
| 
 | ||||
| @ -34,4 +36,14 @@ public class creativeTab { | ||||
|         } | ||||
|         return ret; | ||||
|     } | ||||
| 
 | ||||
|     public static ItemStack[] getBlocks() { | ||||
|         ItemStack[] ret = new ItemStack[blocks.ITEMS.getEntries().size()]; | ||||
|         int i = 0; | ||||
|         for (RegistryObject<Item> item : blocks.ITEMS.getEntries()) { | ||||
|             ret[i] = item.get().getDefaultInstance(); | ||||
|             i++; | ||||
|         } | ||||
|         return ret; | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -18,5 +18,6 @@ public class DataGenerators { | ||||
|         PackOutput packOutput = generator.getPackOutput(); | ||||
|         ExistingFileHelper existingFileHelper = event.getExistingFileHelper(); | ||||
|         generator.addProvider(event.includeClient(), new ModItemModelProvider(packOutput, existingFileHelper)); | ||||
|         generator.addProvider(event.includeClient(), new ModBlockStateProvider(packOutput, existingFileHelper)); | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,86 @@ | ||||
| package com.jenny.magic.datagen; | ||||
| 
 | ||||
| import com.jenny.magic.blocks.blocks; | ||||
| import net.minecraft.data.PackOutput; | ||||
| import net.minecraft.resources.ResourceLocation; | ||||
| import net.minecraft.world.level.block.Block; | ||||
| import net.minecraftforge.client.model.generators.BlockStateProvider; | ||||
| import net.minecraftforge.client.model.generators.ConfiguredModel; | ||||
| import net.minecraftforge.client.model.generators.ModelFile; | ||||
| import net.minecraftforge.common.data.ExistingFileHelper; | ||||
| import net.minecraftforge.registries.ForgeRegistries; | ||||
| import net.minecraftforge.registries.RegistryObject; | ||||
| import org.jetbrains.annotations.NotNull; | ||||
| 
 | ||||
| import java.util.Objects; | ||||
| 
 | ||||
| import static com.jenny.magic.Magic.MODID; | ||||
| 
 | ||||
| public class ModBlockStateProvider extends BlockStateProvider { | ||||
|     public ModBlockStateProvider(PackOutput output, ExistingFileHelper exFileHelper) { | ||||
|         super(output, MODID, exFileHelper); | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     protected void registerStatesAndModels() { | ||||
|         test(blocks.ANTI_SPAWNER); | ||||
|         //blockWithItem(blocks.ANTI_SPAWNER); | ||||
|     } | ||||
| 
 | ||||
|     private void test(@NotNull RegistryObject<Block> blockRegistryObject) { | ||||
|         Block block = blockRegistryObject.get(); | ||||
|         ModelFile model = cube(block); | ||||
|         this.getVariantBuilder(block).forAllStates(blockState -> ConfiguredModel.builder().modelFile(model).build()); | ||||
|         simpleBlockItem(block, model); | ||||
|     } | ||||
| 
 | ||||
|     private void blockWithItem(@NotNull RegistryObject<Block> blockRegistryObject) { | ||||
|         simpleBlockWithItem(blockRegistryObject.get(), cubeAll(blockRegistryObject.get())); | ||||
|     } | ||||
| 
 | ||||
|     private void SideTop(@NotNull RegistryObject<Block> blockRegistryObject) { | ||||
|         simpleBlockWithItem(blockRegistryObject.get(), topSide(blockRegistryObject.get())); | ||||
|     } | ||||
| 
 | ||||
|     private void blockItem(@NotNull RegistryObject<Block> blockRegistryObject) { | ||||
|         simpleBlockItem(blockRegistryObject.get(), new ModelFile.UncheckedModelFile(MODID + | ||||
|                 ":block/" + Objects.requireNonNull(ForgeRegistries.BLOCKS.getKey(blockRegistryObject.get())).getPath())); | ||||
|     } | ||||
| 
 | ||||
|     private void topBottom2Sides(@NotNull RegistryObject<Block> blockRegistryObject) { | ||||
|         simpleBlockWithItem(blockRegistryObject.get(), northEastTopBottom(blockRegistryObject.get())); | ||||
|     } | ||||
| 
 | ||||
|     private ResourceLocation key(Block block) { | ||||
|         return ForgeRegistries.BLOCKS.getKey(block); | ||||
|     } | ||||
| 
 | ||||
|     private @NotNull String name(Block block) { | ||||
|         return key(block).getPath(); | ||||
|     } | ||||
| 
 | ||||
|     private ResourceLocation extend(@NotNull ResourceLocation rl, String suffix) { | ||||
|         return new ResourceLocation(rl.getNamespace(), rl.getPath() + suffix); | ||||
|     } | ||||
| 
 | ||||
|     public void sideTopBottom(@NotNull RegistryObject<Block> blockRegistryObject) { | ||||
|         Block block = blockRegistryObject.get(); | ||||
|         ModelFile model = models().cubeBottomTop(name(block), extend(blockTexture(block), "_side"), extend(blockTexture(block), "_bottom"), extend(blockTexture(block), "_top")); | ||||
|         this.getVariantBuilder(block).forAllStates(blockState -> ConfiguredModel.builder().modelFile(model).build()); | ||||
|         simpleBlockItem(block, model); | ||||
|     } | ||||
| 
 | ||||
|     public ModelFile northEastTopBottom(Block block) { | ||||
|         return models().cube(name(block), extend(blockTexture(block), "_bottom"), extend(blockTexture(block), "_top"), extend(blockTexture(block), "_nw"), extend(blockTexture(block), "_se"), extend(blockTexture(block), "_se"), extend(blockTexture(block), "_nw")).texture("particle", extend(blockTexture(block), "_se")); | ||||
|     } | ||||
| 
 | ||||
|     public ModelFile cube(Block block) { | ||||
|         return models().cubeAll(name(block), blockTexture(block)); | ||||
|     } | ||||
| 
 | ||||
|     public ModelFile topSide(Block block) { | ||||
|         return models().cubeColumn(name(block), extend(blockTexture(block), "_side"), extend(blockTexture(block), "_top")); | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
| } | ||||
							
								
								
									
										32
									
								
								src/main/java/com/jenny/magic/items/BlockItemTooltip.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								src/main/java/com/jenny/magic/items/BlockItemTooltip.java
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,32 @@ | ||||
| package com.jenny.magic.items; | ||||
| 
 | ||||
| import net.minecraft.ChatFormatting; | ||||
| import net.minecraft.network.chat.Component; | ||||
| import net.minecraft.network.chat.MutableComponent; | ||||
| import net.minecraft.world.item.BlockItem; | ||||
| import net.minecraft.world.item.ItemStack; | ||||
| import net.minecraft.world.item.TooltipFlag; | ||||
| import net.minecraft.world.level.Level; | ||||
| import net.minecraft.world.level.block.Block; | ||||
| import org.jetbrains.annotations.NotNull; | ||||
| import org.jetbrains.annotations.Nullable; | ||||
| 
 | ||||
| import java.util.List; | ||||
| 
 | ||||
| import static com.jenny.magic.Magic.MODID; | ||||
| 
 | ||||
| public class BlockItemTooltip extends BlockItem { | ||||
|     public BlockItemTooltip(Block pBlock, Properties pProperties) { | ||||
|         super(pBlock, pProperties); | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public void appendHoverText(@NotNull ItemStack pStack, @Nullable Level pLevel, @NotNull List<Component> pTooltipComponents, @NotNull TooltipFlag pIsAdvanced) { | ||||
|         String key = String.format("tooltip.%s.%s", MODID, this); | ||||
|         MutableComponent toolTip = Component.translatable(key); | ||||
|         if (!toolTip.getString().equals(key)) { | ||||
|             pTooltipComponents.add(toolTip.withStyle(ChatFormatting.DARK_BLUE)); | ||||
|             super.appendHoverText(pStack, pLevel, pTooltipComponents, pIsAdvanced); | ||||
|         } | ||||
|     } | ||||
| } | ||||
							
								
								
									
										67
									
								
								src/main/java/com/jenny/magic/items/TeleportScrollBiome.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										67
									
								
								src/main/java/com/jenny/magic/items/TeleportScrollBiome.java
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,67 @@ | ||||
| package com.jenny.magic.items; | ||||
| 
 | ||||
| import com.mojang.datafixers.util.Pair; | ||||
| import net.minecraft.ChatFormatting; | ||||
| import net.minecraft.core.BlockPos; | ||||
| import net.minecraft.core.Holder; | ||||
| import net.minecraft.network.chat.Component; | ||||
| import net.minecraft.server.level.ServerLevel; | ||||
| import net.minecraft.world.InteractionHand; | ||||
| import net.minecraft.world.InteractionResult; | ||||
| import net.minecraft.world.InteractionResultHolder; | ||||
| import net.minecraft.world.entity.player.Player; | ||||
| import net.minecraft.world.item.ItemStack; | ||||
| import net.minecraft.world.item.context.UseOnContext; | ||||
| import net.minecraft.world.level.Level; | ||||
| import net.minecraft.world.level.biome.Biome; | ||||
| import org.jetbrains.annotations.NotNull; | ||||
| 
 | ||||
| import java.util.Objects; | ||||
| import java.util.function.Predicate; | ||||
| 
 | ||||
| import static com.jenny.magic.Magic.MODID; | ||||
| 
 | ||||
| public class TeleportScrollBiome extends BaseItem { | ||||
|     private final Biome biome; | ||||
|     private final ChatFormatting color; | ||||
| 
 | ||||
|     public TeleportScrollBiome(Properties pProperties, Biome biome, ChatFormatting color) { | ||||
|         super(pProperties); | ||||
|         this.biome = biome; | ||||
|         this.color = color; | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public @NotNull InteractionResultHolder<ItemStack> use(@NotNull Level pLevel, @NotNull Player pPlayer, @NotNull InteractionHand pUsedHand) { | ||||
|         use(pPlayer, pPlayer.getItemInHand(pUsedHand)); | ||||
|         return InteractionResultHolder.success(pPlayer.getItemInHand(pUsedHand)); | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) { | ||||
|         use(pContext.getPlayer(), pContext.getItemInHand()); | ||||
|         return InteractionResult.SUCCESS; | ||||
|     } | ||||
| 
 | ||||
|     protected void use(@NotNull Player player, ItemStack itemStack) { | ||||
|         if (!player.level().isClientSide) { | ||||
|             Predicate<Holder<Biome>> predicate = new Predicate<Holder<Biome>>() { | ||||
|                 @Override | ||||
|                 public boolean test(@NotNull Holder<Biome> biomeHolder) { | ||||
|                     return Objects.equals(biomeHolder.get().toString(), biome.toString()); | ||||
|                 } | ||||
|             }; | ||||
|             Pair<BlockPos, Holder<Biome>> pair = ((ServerLevel) player.level()).findClosestBiome3d(predicate, player.blockPosition(), 69000, 32, 64); | ||||
|             if (pair == null) { | ||||
|                 MessageBiomeNotFound(player); | ||||
|             } else { | ||||
|                 player.teleportTo(pair.getFirst().getX(), pair.getFirst().getY(), pair.getFirst().getZ()); | ||||
|             } | ||||
|         } | ||||
|         itemStack.shrink(1); | ||||
|     } | ||||
| 
 | ||||
|     protected void MessageBiomeNotFound(Player player) { | ||||
|         player.sendSystemMessage(Component.translatable(String.format("message.%s.scroll_teleport_biome.not_found", MODID))); | ||||
|     } | ||||
| } | ||||
| @ -0,0 +1,71 @@ | ||||
| package com.jenny.magic.items; | ||||
| 
 | ||||
| import com.mojang.datafixers.util.Pair; | ||||
| import net.minecraft.core.BlockPos; | ||||
| import net.minecraft.core.Holder; | ||||
| import net.minecraft.nbt.CompoundTag; | ||||
| import net.minecraft.resources.ResourceLocation; | ||||
| import net.minecraft.server.level.ServerLevel; | ||||
| import net.minecraft.world.InteractionHand; | ||||
| import net.minecraft.world.InteractionResult; | ||||
| import net.minecraft.world.InteractionResultHolder; | ||||
| import net.minecraft.world.entity.player.Player; | ||||
| import net.minecraft.world.item.ItemStack; | ||||
| import net.minecraft.world.item.context.UseOnContext; | ||||
| import net.minecraft.world.level.Level; | ||||
| import net.minecraft.world.level.biome.Biome; | ||||
| import net.minecraftforge.registries.ForgeRegistries; | ||||
| import org.jetbrains.annotations.NotNull; | ||||
| 
 | ||||
| import java.util.Collection; | ||||
| import java.util.Objects; | ||||
| import java.util.function.Predicate; | ||||
| 
 | ||||
| public class TeleportScrollRandomBiome extends BaseItem { | ||||
|     public TeleportScrollRandomBiome(Properties pProperties) { | ||||
|         super(pProperties); | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public @NotNull InteractionResultHolder<ItemStack> use(@NotNull Level pLevel, @NotNull Player pPlayer, @NotNull InteractionHand pUsedHand) { | ||||
|         use(pPlayer, pPlayer.getItemInHand(pUsedHand)); | ||||
|         return InteractionResultHolder.success(pPlayer.getItemInHand(pUsedHand)); | ||||
|     } | ||||
| 
 | ||||
|     @Override | ||||
|     public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) { | ||||
|         use(pContext.getPlayer(), pContext.getItemInHand()); | ||||
|         return InteractionResult.SUCCESS; | ||||
|     } | ||||
| 
 | ||||
|     protected void use(@NotNull Player player, ItemStack itemStack) { | ||||
|         if (!player.level().isClientSide && itemStack.getTag() != null && itemStack.getTag().contains("teleport_biome")) { | ||||
|             Biome biome = ForgeRegistries.BIOMES.getValue(ResourceLocation.parse(itemStack.getTag().getString("teleport_biome"))); | ||||
|             Predicate<Holder<Biome>> predicate = new Predicate<Holder<Biome>>() { | ||||
|                 @Override | ||||
|                 public boolean test(@NotNull Holder<Biome> biomeHolder) { | ||||
|                     return Objects.equals(biomeHolder.get().toString(), biome.toString()); | ||||
|                 } | ||||
|             }; | ||||
|             Pair<BlockPos, Holder<Biome>> pair = ((ServerLevel) player.level()).findClosestBiome3d(predicate, player.blockPosition(), 69000, 32, 64); | ||||
|             if (pair == null) { | ||||
|                 System.out.println("error: biome not found"); | ||||
|             } else { | ||||
|                 player.teleportTo(pair.getFirst().getX(), pair.getFirst().getY(), pair.getFirst().getZ()); | ||||
|             } | ||||
|         } else { | ||||
|             setBiome(player.level(), itemStack); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     protected void setBiome(Level level, ItemStack itemStack) { | ||||
|         //ForgeRegistries.BIOMES.getEntries().stream().toList().get().; | ||||
|         Collection<Biome> list = ForgeRegistries.BIOMES.getValues(); | ||||
|         //String biomeStr = list.get(level.getRandom().nextInt(list.size())).toString(); | ||||
| 
 | ||||
|         CompoundTag compoundTag = itemStack.getTag(); | ||||
|         compoundTag = compoundTag != null ? compoundTag : new CompoundTag(); | ||||
|         //compoundTag.putString("teleport_biome", biomeStr); | ||||
|         itemStack.setTag(compoundTag); | ||||
|     } | ||||
| } | ||||
| @ -14,6 +14,7 @@ public class items { | ||||
|     public static final RegistryObject<Item> SCROLL_TELEPORT = ITEMS.register("scroll_teleport", () -> new TeleportScrollPersistent(new Item.Properties().stacksTo(1))); | ||||
|     public static final RegistryObject<Item> SCROLL_TELEPORT_BRITTLE = ITEMS.register("scroll_teleport_brittle", () -> new TeleportScrollConsumable(new Item.Properties().stacksTo(16))); | ||||
|     public static final RegistryObject<Item> SCROLL_TELEPORT_RANDOM = ITEMS.register("scroll_teleport_random", () -> new TeleportScrollRandom(new Item.Properties().stacksTo(1))); | ||||
|     public static final RegistryObject<Item> SCROLL_TELEPORT_RANDOM_BIOME = ITEMS.register("scroll_teleport_random_biome", () -> new TeleportScrollRandomBiome(new Item.Properties().stacksTo(16))); | ||||
| 
 | ||||
| 
 | ||||
|     public static void register(IEventBus bus) { | ||||
|  | ||||
							
								
								
									
										
											BIN
										
									
								
								src/main/resources/assets/magic/textures/block/anti_spawner.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								src/main/resources/assets/magic/textures/block/anti_spawner.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 97 B | 
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 97 B | 
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 97 B | 
							
								
								
									
										21
									
								
								src/main/resources/data/magic/recipes/wand_hurtful_test.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								src/main/resources/data/magic/recipes/wand_hurtful_test.json
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,21 @@ | ||||
| { | ||||
|   "type": "minecraft:crafting_shapeless", | ||||
|   "category": "combat", | ||||
|   "ingredients": [ | ||||
|     { | ||||
|       "item": "minecraft:stick" | ||||
|     }, | ||||
|     { | ||||
|       "item": "minecraft:diamond" | ||||
|     } | ||||
|   ], | ||||
|   "result": { | ||||
|     "item": "magic:wand_hurtful" | ||||
|   }, | ||||
|   "conditions": [ | ||||
|     { | ||||
|       "type": "magic:wand_hurtful", | ||||
|       "mod": "magic" | ||||
|     } | ||||
|   ] | ||||
| } | ||||
| @ -1,7 +1,7 @@ | ||||
| { | ||||
|   "required": true, | ||||
|   "minVersion": "0.8", | ||||
|   "package": "com.jenny.magic.mixin", | ||||
|   "package": "com.jenny.magic.mixins", | ||||
|   "compatibilityLevel": "JAVA_8", | ||||
|   "refmap": "magic.refmap.json", | ||||
|   "mixins": [ | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user