Jump to content

[1.15.2] Turning Ghasts and Vexes into undead and Lightning Strikes on Skeletons


Cryotron

Recommended Posts

Hello,

 

I've asked an advice for adding the Wither Mages in the Nether Fortress... and I succeeded. Adding an event is something I'm now used to. Hopefully I can do so to add world events like Nevermine did. Now, it is then I believed that I can move on to something more complicated.

 

I've looked into it from the origin of Extended Entity Properties (IEEP) and it is depreciated in favor of capabilities. It seems capabilities can do something that is not really ordinary to the game such as adding a mana bar or an extra resource that players need to track (as I've seen plethora of examples that capabilities are added to players). As the title suggests, the objective is to add a creature attribute and other non-primitive data type objects to the existing entities created by vanilla Minecraft. In the other words, I'd like to add something like:

- Adding Undead Creature Attribute onto Ghasts (Since they are ghosts...)

- Adding Undead Creature Attribute onto Vexes (Since they are also ghosts...)

- Adding Demon Creature Attribute onto Piglins and Hoglins (Demons don't exist, it will be a mod made attribute. I plan to update this mod when 1.16 releases)

- Adding OnStruckByLightning onto Vanilla Skeletons into Skeletal Mages (Skeleton -> Skeleton Mage with Fire Res for 8 seconds)

- Adding OnStruckByLightning onto Pillager or Vindicators into Warlocks (Warlocks are not implemented but you get the idea. They're basically the Illager Version of Witches)

- Adding OnStruckByLightning onto Foxes into Nine-Tailed Demon Fox (In the mod sequel)

 

So far, I only know a capability that involves around primitive data types such as integers. I think adding a mana bar is pretty straightforward. But when it comes to object related, it gets pretty hectic depending on the NBT. I checked on the referenced folder and these are the following NBTs available to the game and some of them are not even a primitive data types I'm familiar with: Byte, ByteArrays, Collections, Compound, CompressedStreamTools, Doubles, Ends, Floats, Integer, IntegerArray, JsonTo, Lists, Long, LongArray, Shorts and Strings. 

 

I'm using an example for Ghasts. For them, the NBTs are: Explosion Power, Silent, NoAI, CustomName, AbsorptionAmount, Invulnerable, PersistenceRequired, Fire, PortalCooldown, Air, UUID, ID and Passengers... So my question is that it is even possible to add a creatureAttribute.UNDEAD to Ghasts? It's kind of like adding a new method of an existing entity instead of overwriting an existing one.

 

I made a new project to test the capability of a Ghast and these are the files:

 

capabilitytest.java(Main file)

package com.cryotron.capabilitytest;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import com.cryotron.capabilitytest.capability.interfaces.IGhastCapability;
import com.cryotron.capabilitytest.instances.GhastInstance;

import net.minecraftforge.common.capabilities.CapabilityManager;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;

// The value here should match an entry in the META-INF/mods.toml file
@Mod(CapabilityTest.MODID)
public class CapabilityTest
{
    public static final String MODID = "capabilitytest";
    public static final Logger LOGGER = LogManager.getLogger(MODID);
    
    public CapabilityTest()
    {
        LOGGER.info("\"Hello World\" -Capability Test");
        final IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
        modEventBus.addListener(this::onCommonSetup);

    }

    private void onCommonSetup(FMLCommonSetupEvent e)
    {
    	CapabilityManager.INSTANCE.register(IGhastCapability.class, new GhastInstance.Storage(), GhastInstance::new);
    }
}

 

ForgeSubscriber.java

package com.cryotron.capabilitytest;

import com.cryotron.capabilitytest.capability.interfaces.IGhastCapability;
import com.cryotron.capabilitytest.capability.GhastCapability;

import net.minecraft.entity.Entity;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.event.AttachCapabilitiesEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

@Mod.EventBusSubscriber(modid = CapabilityTest.MODID, bus = Mod.EventBusSubscriber.Bus.FORGE)
public class ForgeSubscriber {
	private static final ResourceLocation GHAST_UPDATE = new ResourceLocation(CapabilityTest.MODID, "ghast");

    @SubscribeEvent
    public static void onAttachGhast(AttachCapabilitiesEvent<Entity> e)
    {
    	if (e.getObject().getEntity() instanceof IGhastCapability) e.addCapability(GHAST_UPDATE, new GhastCapability());
    }
}

 

EventBusSubscriber.java

package com.cryotron.capabilitytest;

import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.registries.IForgeRegistryEntry;

@Mod.EventBusSubscriber(modid = CapabilityTest.MODID, bus = Mod.EventBusSubscriber.Bus.MOD)
public class EventBusSubscriber {
    public static <T extends IForgeRegistryEntry<T>> T setup(final T entry, final String name) {
        return setup(entry, new ResourceLocation(CapabilityTest.MODID, name));
    }

    public static <T extends IForgeRegistryEntry<T>> T setup(final T entry, final ResourceLocation registryName) {
        entry.setRegistryName(registryName);
        return entry;
    }
}

 

GhastInstance.java (This is the part that I think I have trouble with)

package com.cryotron.capabilitytest.instances;

import javax.annotation.Nullable;

import com.cryotron.capabilitytest.capability.interfaces.IGhastCapability;

import net.minecraft.entity.CreatureAttribute;
import net.minecraft.nbt.INBT;
import net.minecraft.nbt.IntNBT;
import net.minecraft.util.Direction;
import net.minecraftforge.common.capabilities.Capability;

public class GhastInstance implements IGhastCapability {

	@Override
	public CreatureAttribute getCreatureAttribute() {
		// TODO Auto-generated method stub
		return CreatureAttribute.UNDEAD;
	}

	@Override
	public void updateCreatureAttribute(CreatureAttribute GhastAttribute) {
		// TODO Auto-generated method stub
		GhastAttribute = CreatureAttribute.UNDEAD;
		
	}
	
    public static class Storage implements Capability.IStorage<IGhastCapability>
    {
        @Nullable
        @Override
        public INBT writeNBT(Capability<IGhastCapability> capability, IGhastCapability instance, Direction side) 
        { 
        	return (INBT) instance.getCreatureAttribute(); 
        }

        @Override
        public void readNBT(Capability<IGhastCapability> capability, IGhastCapability instance, Direction side, INBT nbt) 
        { 
        	instance.updateCreatureAttribute(null); // This is the part where I need to put a specific type of NBT to read it.
        }
    }

}

 

GhastCapability.java

package com.cryotron.capabilitytest.capability;

import javax.annotation.Nonnull;

import com.cryotron.capabilitytest.capability.interfaces.IGhastCapability;

import net.minecraft.nbt.IntNBT; //Originally it is IntNBT. Anywhere it has /*Object NBT Type*/ used to be integer NBT types.
import net.minecraft.util.Direction;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.CapabilityInject;
import net.minecraftforge.common.capabilities.ICapabilitySerializable;
import net.minecraftforge.common.util.LazyOptional;

public class GhastCapability implements ICapabilitySerializable</*Object NBT Type*/> {
	
    @CapabilityInject(IGhastCapability.class)
    public static final Capability<IGhastCapability> GHAST_PROPERTIES = null;

    private LazyOptional<IGhastCapability> instance = LazyOptional.of(GHAST_PROPERTIES::getDefaultInstance);

    @Nonnull
	@Override
	public <T> LazyOptional<T> getCapability(Capability<T> cap, Direction side) {
		// TODO Auto-generated method stub
		return GHAST_PROPERTIES.orEmpty(cap, instance);
	}


    @Override
    public void deserializeNBT(/*Object NBT Type*/ nbt) { 
    	GHAST_PROPERTIES.getStorage().readNBT(GHAST_PROPERTIES, instance.orElseThrow(() -> new IllegalArgumentException("LazyOptional cannot be empty!")), null, nbt); 
    }

  //Ignore the format for a second since we're not dealing with an NBT with an integer.
    @Override
    public /*Object NBT Type*/ serializeNBT() { 
    	return (/*Object NBT Type*/) GHAST_PROPERTIES.getStorage().writeNBT(GHAST_PROPERTIES, instance.orElseThrow(() -> new IllegalArgumentException("LazyOptional cannot be empty!")), null); 
    }
  
}

 

IGhastCapability.java

package com.cryotron.capabilitytest.capability.interfaces;

import net.minecraft.entity.CreatureAttribute;

public interface IGhastCapability {
	
	CreatureAttribute getCreatureAttribute();
	
	void updateCreatureAttribute(CreatureAttribute GhastAttribute);
}

 

My biggest question is: Is it possible to add a capability on a non-player entity this way that doesn't involve around integer or string but with objects? I'm pretty sure I need to fully grasp this concept before adding a capability on each item in this mod that involves around Gem Socketing. That would be my next big thing... Could any of the experts shed a light on this?

Edited by Cryotron
Link to comment
Share on other sites

20 minutes ago, diesieben07 said:

I think you are misunderstanding what capabilities are.

Capabilities first and foremost allow things (entities, tile entities, etc.) to expose a capability, such as "I have an inventory" (that would be CapabilityItemHandler#ITEM_HANDLER_CAPABILITY).

Additionally, Forge fires an event (AttachCapabilitiesEvent) that allows you to attach additional capabilities to things that are "not your own" (e.g. to add a capability to a vanilla entity). Since capabilities can also store data, you can use this to store additional data on vanilla entities.

 

What you want to do however seems to be changing an existing property about vanilla entities, correct?

Yes. I wish to add Creature Attributes onto Ghasts and Vexes and an outcome when a Skeleton gets struck by lightning. Does the event AttachCapabilitiesEvent allow as such?

I'm still scratching my head of capabilities in terms of functionality.

 

EDIT: I'll look into AttachCapabilitiesEvent and see what comes out of it.

Edited by Cryotron
Link to comment
Share on other sites

3 minutes ago, diesieben07 said:

It does not. Did you read what I explained above? ?

 

Why do you want to change the CreatureAttribute? There is no easy way to do so.

 

You can use EntityStruckByLightningEvent for this.

The Lightning Event seems doable then. :D

 

I think I misunderstood your 3rd sentence on a capability that adds something that's "not my own" such as adding a capability to a vanilla entity. Like adding a mana pool, socketed items, energy, etc. I kind of took it as property can be used as a capability since IEEP has been depreciated in favor of capabilities which is something I'm not fully familiar with. 

 

The reason why I want to make Ghasts and Vexes undead because it conceptually makes sense. They are incorporeal creatures (But hey, it's Minecraft so it's whatever I guess xD). Worst case is that I would probably leave them alone or use events to "replace" the list of entities that spawns in a dimension or what evokers summon. The most feasible way is to just leave them be. :L

 

But if there is a way to turn the Ghasts and Vexes into undead, I'm happy to read it thoroughly. I would like to update vanilla mobs that makes it synergize with my mod: E.G. Smite works on Demons in 1.16 update where Piglins would be Demons later.

Link to comment
Share on other sites

Just now, diesieben07 said:

The question is which effect are you trying to achieve by making them undead?

Potion of Healing harms them.

Potion of Harming heals them.

Extra damage taken from Smite.

Withers do not attack them. 

Immune to Poison and Regen.

 

This would make Vexes a bit more feasible to deal with using Splash Potions of Healing.

The Ghast however...... I mean I guess I really don't have to make them undead. :P

Link to comment
Share on other sites

Like diesieben said, I don't think there's an easy way to do this that would justify the minor change in gameplay this would be, but it's up to you. For more complex tasks and attributes I wanted my vanilla mobs to have, I've instead replaced some of the vanilla mobs altogether.

Link to comment
Share on other sites

8 minutes ago, Turtledove said:

Like diesieben said, I don't think there's an easy way to do this that would justify the minor change in gameplay this would be, but it's up to you. For more complex tasks and attributes I wanted my vanilla mobs to have, I've instead replaced some of the vanilla mobs altogether.

I see, alright. I'll leave them be for now. Thank you Turtle and Diesieben. :D

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.