-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
添加药水效果的自动注册功能
- Loading branch information
Showing
8 changed files
with
103 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 12 additions & 1 deletion
13
src/main/java/com/gensokyo/nucleardelight/datagenerator/DataGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,24 @@ | ||
package com.gensokyo.nucleardelight.datagenerator; | ||
|
||
import com.gensokyo.nucleardelight.NuclearDelight; | ||
import net.minecraft.data.PackOutput; | ||
import net.minecraft.world.item.Item; | ||
import net.minecraftforge.common.data.ExistingFileHelper; | ||
import net.minecraftforge.data.event.GatherDataEvent; | ||
import net.minecraftforge.eventbus.api.SubscribeEvent; | ||
import net.minecraftforge.fml.common.Mod; | ||
import net.minecraftforge.registries.RegistryObject; | ||
|
||
import java.util.List; | ||
|
||
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD) | ||
public class DataGenerator { | ||
@SubscribeEvent | ||
public static void dataGen(GatherDataEvent event) { | ||
// event.getGenerator().addProvider(); | ||
PackOutput packOutput = event.getGenerator().getPackOutput(); | ||
ExistingFileHelper existingFileHelper = event.getExistingFileHelper(); | ||
|
||
List<Item> items = NuclearDelight.RegisteredItems.stream().map(RegistryObject::get).toList(); | ||
event.getGenerator().addProvider(true, new SingleTextureItemModelGenerator(items, packOutput, existingFileHelper)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/main/java/com/gensokyo/nucleardelight/register/AutoRegistryObject.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.gensokyo.nucleardelight.register; | ||
|
||
import net.minecraftforge.registries.DeferredRegister; | ||
import net.minecraftforge.registries.RegistryObject; | ||
|
||
import java.util.function.Supplier; | ||
|
||
public class AutoRegistryObject<T> { | ||
private final Supplier<T> supplier; | ||
private RegistryObject<T> object; | ||
|
||
public AutoRegistryObject(Supplier<T> supplier) { | ||
this.supplier = supplier; | ||
} | ||
|
||
public void register(DeferredRegister<T> register, String name) { | ||
object = register.register(name, supplier); | ||
} | ||
|
||
public T get() { | ||
return object.get(); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/com/gensokyo/nucleardelight/world/effect/MobEffects.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.gensokyo.nucleardelight.world.effect; | ||
|
||
import com.gensokyo.nucleardelight.register.AutoRegistryObject; | ||
import net.minecraft.world.effect.MobEffect; | ||
|
||
public class MobEffects { | ||
public static final AutoRegistryObject<MobEffect> VOMITING = new AutoRegistryObject<>(VomitingMobEffect::new); | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/com/gensokyo/nucleardelight/world/effect/VomitingMobEffect.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.gensokyo.nucleardelight.world.effect; | ||
|
||
import net.minecraft.world.effect.MobEffect; | ||
import net.minecraft.world.effect.MobEffectCategory; | ||
import net.minecraft.world.effect.MobEffectInstance; | ||
import net.minecraft.world.effect.MobEffects; | ||
import net.minecraft.world.entity.LivingEntity; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class VomitingMobEffect extends MobEffect { | ||
|
||
protected VomitingMobEffect() { | ||
super(MobEffectCategory.HARMFUL, 0xA6A03A); | ||
} | ||
|
||
@Override | ||
public void applyEffectTick(@NotNull LivingEntity entity, int level) { | ||
if (!entity.hasEffect(MobEffects.CONFUSION)) { | ||
entity.addEffect(new MobEffectInstance(MobEffects.CONFUSION, | ||
entity.getEffect(com.gensokyo.nucleardelight.world.effect.MobEffects.VOMITING.get()).getDuration(), 1)); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean isDurationEffectTick(int p_19455_, int p_19456_) { | ||
return true; | ||
} | ||
} |
31 changes: 3 additions & 28 deletions
31
src/main/java/com/gensokyo/nucleardelight/world/food/Foods.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,16 @@ | ||
package com.gensokyo.nucleardelight.world.food; | ||
|
||
import com.gensokyo.nucleardelight.NuclearDelight; | ||
import com.gensokyo.nucleardelight.Utils; | ||
import com.gensokyo.nucleardelight.world.effect.MobEffects; | ||
import com.mojang.logging.LogUtils; | ||
import net.minecraft.world.effect.MobEffectInstance; | ||
import net.minecraft.world.effect.MobEffects; | ||
import net.minecraft.world.food.FoodProperties; | ||
import net.minecraft.world.item.Item; | ||
import org.slf4j.Logger; | ||
|
||
import java.lang.reflect.Field; | ||
import java.lang.reflect.Modifier; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.function.Supplier; | ||
|
||
public class Foods { | ||
private static final Logger LOGGER = LogUtils.getLogger(); | ||
|
||
// public static List<Item> FOODS = List.of(); | ||
// | ||
// public static List<Item> getFoods() { | ||
// return FOODS; | ||
// } | ||
|
||
public static final FoodProperties EXAMPLE_FOOD = new FoodProperties.Builder().alwaysEat() | ||
.effect(() -> new MobEffectInstance(MobEffects.REGENERATION, 100, 1), 1.0F) | ||
public static final FoodProperties APPLE_JAM_JAR = new FoodProperties.Builder().alwaysEat() | ||
.effect(() -> new MobEffectInstance(MobEffects.VOMITING.get(), 1000, 1), 1.0F) | ||
.nutrition(1) | ||
.saturationMod(2f).build(); | ||
|
||
public static void Initializing() { | ||
LOGGER.debug("Initializing Foods"); | ||
Map<String, FoodProperties> staticFinalFieldsNameAndValue = Utils.getStaticFinalFieldsNameAndValue(Foods.class, FoodProperties.class); | ||
staticFinalFieldsNameAndValue.forEach((name, value) -> { | ||
String id = name.toLowerCase(); | ||
Supplier<Item> itemSupplier = () -> new Item(new Item.Properties().food(value)); | ||
NuclearDelight.ITEMS.register(id, itemSupplier); | ||
}); | ||
} | ||
} |