mirror of
https://github.com/FatherToast/SpecialMobs.git
synced 2025-04-25 06:45:11 +00:00
Syringe + simple item data gen stuff
This commit is contained in:
parent
00f6912c6d
commit
d9d0cd8dbf
6 changed files with 105 additions and 2 deletions
|
@ -1,6 +1,7 @@
|
|||
package fathertoast.specialmobs.common.core.register;
|
||||
|
||||
import fathertoast.specialmobs.common.core.SpecialMobs;
|
||||
import fathertoast.specialmobs.common.item.SyringeItem;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.item.Item;
|
||||
|
@ -10,9 +11,18 @@ import net.minecraftforge.fml.RegistryObject;
|
|||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class SMItems {
|
||||
|
||||
public static final DeferredRegister<Item> REGISTRY = DeferredRegister.create( ForgeRegistries.ITEMS, SpecialMobs.MOD_ID );
|
||||
public static final List<RegistryObject<? extends Item>> SIMPLE_ITEMS = new ArrayList<>();
|
||||
|
||||
|
||||
public static final RegistryObject<Item> SYRINGE = registerSimpleItem("syringe", SyringeItem::new);
|
||||
|
||||
|
||||
/** Registers an entity type's spawn egg item to the deferred register. */
|
||||
public static <T extends Entity> RegistryObject<ForgeSpawnEggItem> registerSpawnEgg(
|
||||
|
@ -22,4 +32,10 @@ public class SMItems {
|
|||
new ForgeSpawnEggItem( entityType, eggBaseColor, eggSpotsColor, new Item.Properties().tab( ItemGroup.TAB_MISC ) )
|
||||
);
|
||||
}
|
||||
|
||||
public static <T extends Item> RegistryObject<T> registerSimpleItem(String name, Supplier<T> itemSupplier) {
|
||||
RegistryObject<T> regObject = REGISTRY.register(name, itemSupplier);
|
||||
SIMPLE_ITEMS.add(regObject);
|
||||
return regObject;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
package fathertoast.specialmobs.common.item;
|
||||
|
||||
import fathertoast.specialmobs.common.bestiary.SpecialMob;
|
||||
import fathertoast.specialmobs.common.util.References;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Rarity;
|
||||
import net.minecraft.potion.EffectInstance;
|
||||
import net.minecraft.potion.Effects;
|
||||
import net.minecraft.util.*;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class SyringeItem extends Item {
|
||||
|
||||
public SyringeItem() {
|
||||
super(new Item.Properties().stacksTo(1).rarity(Rarity.UNCOMMON).defaultDurability(10).setNoRepair());
|
||||
}
|
||||
|
||||
@SpecialMob.LanguageProvider
|
||||
public static String[] getTranslations( String langKey ) {
|
||||
return References.translations( langKey, "Syringe",
|
||||
"", "", "", "", "", "" );//TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResult<ItemStack> use(World world, PlayerEntity player, Hand hand) {
|
||||
ItemStack usedItem = player.getItemInHand(hand);
|
||||
|
||||
if (!world.isClientSide) {
|
||||
if (player.hasEffect(Effects.MOVEMENT_SPEED)) {
|
||||
return ActionResult.pass(usedItem);
|
||||
}
|
||||
else {
|
||||
player.addEffect(new EffectInstance(Effects.MOVEMENT_SPEED, 300, 2));
|
||||
player.addEffect(new EffectInstance(Effects.CONFUSION, 400));
|
||||
world.playSound(null, player.getX(), player.getY(), player.getZ(), SoundEvents.BEE_STING, SoundCategory.PLAYERS, 0.9F, 1.0F);
|
||||
usedItem.hurtAndBreak(1, player, (entity) -> {
|
||||
entity.broadcastBreakEvent(hand);
|
||||
});
|
||||
return ActionResult.success(usedItem);
|
||||
}
|
||||
}
|
||||
return ActionResult.fail(usedItem);
|
||||
}
|
||||
}
|
|
@ -7,6 +7,7 @@ import fathertoast.specialmobs.datagen.loot.LootTableBuilder;
|
|||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.ai.attributes.AttributeModifierMap;
|
||||
import net.minecraft.item.Item;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
import java.lang.annotation.Annotation;
|
||||
|
@ -80,7 +81,18 @@ public final class AnnotationHelper {
|
|||
throw new RuntimeException( "Entity class for " + species.name + " has invalid language provider method", ex );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** Gets the translations from a mod item. Throws an exception if anything goes wrong. */
|
||||
public static String[] getTranslations(Item item) {
|
||||
try {
|
||||
return (String[]) getMethod( item.getClass(), SpecialMob.LanguageProvider.class )
|
||||
.invoke( null, item.getDescriptionId() );
|
||||
}
|
||||
catch( NoSuchMethodException | InvocationTargetException | IllegalAccessException ex ) {
|
||||
throw new RuntimeException( "Item class for " + item.getRegistryName() + " has invalid language provider method", ex );
|
||||
}
|
||||
}
|
||||
|
||||
/** Builds a loot table from a special mob species. Throws an exception if anything goes wrong. */
|
||||
public static LootTableBuilder buildLootTable( MobFamily.Species<?> species ) {
|
||||
try {
|
||||
|
|
|
@ -2,10 +2,15 @@ package fathertoast.specialmobs.datagen;
|
|||
|
||||
import fathertoast.specialmobs.common.bestiary.MobFamily;
|
||||
import fathertoast.specialmobs.common.core.SpecialMobs;
|
||||
import fathertoast.specialmobs.common.core.register.SMItems;
|
||||
import net.minecraft.data.DataGenerator;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.model.generators.ItemModelProvider;
|
||||
import net.minecraftforge.common.data.ExistingFileHelper;
|
||||
import net.minecraftforge.fml.RegistryObject;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class SMItemModelProvider extends ItemModelProvider {
|
||||
|
||||
|
@ -19,5 +24,13 @@ public class SMItemModelProvider extends ItemModelProvider {
|
|||
final ResourceLocation spawnEggParent = modLoc( ITEM_FOLDER + "/template_sm_spawn_egg" );
|
||||
for( MobFamily.Species<?> species : MobFamily.getAllSpecies() )
|
||||
withExistingParent( species.spawnEgg.getId().getPath(), spawnEggParent );
|
||||
|
||||
// Simple items
|
||||
for(RegistryObject<? extends Item> regObject : SMItems.SIMPLE_ITEMS) {
|
||||
String name = Objects.requireNonNull(regObject.getId()).getPath();
|
||||
|
||||
withExistingParent(name, mcLoc("item/generated"))
|
||||
.texture("layer0", modLoc(ITEM_FOLDER + "/" + name));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,10 +2,14 @@ package fathertoast.specialmobs.datagen;
|
|||
|
||||
import fathertoast.specialmobs.common.bestiary.MobFamily;
|
||||
import fathertoast.specialmobs.common.core.SpecialMobs;
|
||||
import fathertoast.specialmobs.common.core.register.SMItems;
|
||||
import fathertoast.specialmobs.common.util.AnnotationHelper;
|
||||
import fathertoast.specialmobs.common.util.References;
|
||||
import net.minecraft.data.DataGenerator;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraftforge.common.ForgeSpawnEggItem;
|
||||
import net.minecraftforge.common.data.LanguageProvider;
|
||||
import net.minecraftforge.fml.RegistryObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
@ -51,7 +55,19 @@ public class SMLanguageProvider extends LanguageProvider {
|
|||
translationList.add( speciesTranslations );
|
||||
translationList.add( spawnEggTranslations );
|
||||
}
|
||||
|
||||
|
||||
// Items
|
||||
for (RegistryObject<Item> regObject : SMItems.REGISTRY.getEntries()) {
|
||||
Item item = regObject.get();
|
||||
|
||||
// Lazy method of avoiding duplicate entries for now
|
||||
if (item instanceof ForgeSpawnEggItem) {
|
||||
continue;
|
||||
}
|
||||
final String[] itemTranslations = AnnotationHelper.getTranslations(regObject.get());
|
||||
translationList.add(itemTranslations);
|
||||
}
|
||||
|
||||
TRANSLATIONS = translationList.toArray( new String[0][0] );
|
||||
|
||||
// Assign all specific locales to the translation we want to use
|
||||
|
|
BIN
src/main/resources/assets/specialmobs/textures/item/syringe.png
Normal file
BIN
src/main/resources/assets/specialmobs/textures/item/syringe.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 252 B |
Loading…
Add table
Reference in a new issue