Items
This page shows further customization you can use on the framework of custom items.
Events
If you have already made a custom item class it will look something like this:
import com.jewishbanana.uiframework.utils.ItemBuilder;
import com.jewishbanana.uiframework.items.GenericItem;
public class GreenLightsaber extends GenericItem {
//DO NOT add arguments to the constructor this needs to strictly have only an ItemStack argument passed which will be the custom item on initialization when it is detected
public GreenLightsaber(ItemStack item) {
super(item);
}
//this is the UIF item builder that is passed for the items creation, this has a few builder blocks you can explore but for now we keep it simple
//you can also just pass directly ItemBuilder.create(ItemStack) if you want to create an ItemStack first and pass it through
//the assembleLore(id) will just automatically set up the lore with UIF default item lore template including info on abilities, stats, and enchants I HIGHLY RECOMMEND USING THIS TEMPLATE
@Override
public ItemBuilder createItem() {
return ItemBuilder.create(Material.GOLDEN_SWORD).registerName(UIFUtils.convertString("(hex:#1fe615)Green Lightsaber")).assembleLore(id).setCustomModelData(7000).build();
}
}
But for more advanced customization you can actually override methods before abilities activate or are attempted to activate. Let me show you an example of what I mean with this lightsaber item class example, let's say we have an ability bound to when they interact with right-click but we want to have a passive effect when they left-click that will spawn some particles where they swing the lightsaber:
import com.jewishbanana.uiframework.utils.ItemBuilder;
import com.jewishbanana.uiframework.items.GenericItem;
public class GreenLightsaber extends GenericItem {
public GreenLightsaber(ItemStack item) {
super(item);
}
//this will override the GenericItem classes interacted method meaning you can control directly what happens when a player interacts with your custom item
//here I add a cool slash effect when they swing with left click
public void interacted(PlayerInteractEvent event) {
if (event.getAction() == Action.LEFT_CLICK_AIR) {
Vector axis = event.getPlayer().getEyeLocation().getDirection().multiply(0.3);
Location playerLoc = event.getPlayer().getLocation().add(0,1.3,0);
Location front = playerLoc.clone().add(axis);
Vector vec = new Vector(axis.getZ(), axis.getY(), -axis.getX()).normalize().multiply(1.5);
vec.rotateAroundAxis(axis, Utils.random().nextDouble()*360);
Vector finalAngle = Utils.getVectorTowards(front.clone().add(vec), front).multiply(0.15);
int[] tick = {0};
new RepeatingTask(0, 1) {
@Override
public void run() {
for (int i=0; i < 3; i++) {
front.getWorld().spawnParticle(Particle.END_ROD, playerLoc.clone().add(Utils.getVectorTowards(playerLoc, front.clone().add(vec)).multiply(1.3)), 1, 0, 0, 0, 0.015);
vec.add(finalAngle);
}
if (tick[0]++ >= 4)
cancel();
}
};
}
//this super method is important because the actual method in the GenericItem class will activate any abilities that may exist on the item with the event
//make sure to call this super method when you override one of the GenericItem methods or else abilities won't activate
super.interacted(event);
}
@Override
public ItemBuilder createItem() {
return ItemBuilder.create(Material.GOLDEN_SWORD).registerName(UIFUtils.convertString("(hex:#1fe615)Green Lightsaber")).assembleLore(id).setCustomModelData(7000).build();
}
}
Now let's see what it looks like in-game:
Here are all the methods you can override inside your custom item class:
public void interacted(PlayerInteractEvent event) {
switch (event.getAction()) {
case LEFT_CLICK_BLOCK:
id.simulateAction(Ability.Action.LEFT_CLICK_BLOCK, event, this);
if(event.getPlayer().isSneaking())
id.simulateAction(Ability.Action.SHIFT_LEFT_CLICK_BLOCK, event, this);
case LEFT_CLICK_AIR:
id.simulateAction(Ability.Action.LEFT_CLICK, event, this);
if(event.getPlayer().isSneaking())
id.simulateAction(Ability.Action.SHIFT_LEFT_CLICK, event, this);
break;
case RIGHT_CLICK_BLOCK:
id.simulateAction(Ability.Action.RIGHT_CLICK_BLOCK, event, this);
if(event.getPlayer().isSneaking())
id.simulateAction(Ability.Action.SHIFT_RIGHT_CLICK_BLOCK, event, this);
case RIGHT_CLICK_AIR:
id.simulateAction(Ability.Action.RIGHT_CLICK, event, this);
if(event.getPlayer().isSneaking())
id.simulateAction(Ability.Action.SHIFT_RIGHT_CLICK, event, this);
break;
default:
break;
}
}
public void hitEntity(EntityDamageByEntityEvent event) {
double damage = id.getDamage();
if (event.getDamager() instanceof LivingEntity) {
LivingEntity entity = (LivingEntity) event.getDamager();
double enchantDamage = UIFUtils.getEnchantDamage(item, (event.getEntity() instanceof LivingEntity ? (LivingEntity) event.getEntity() : null));
if (entity.hasPotionEffect(PotionEffectType.INCREASE_DAMAGE))
damage += entity.getPotionEffect(PotionEffectType.INCREASE_DAMAGE).getAmplifier() * 3.0;
if (event.getDamager() instanceof Player) {
double cooldown = ((Player) event.getDamager()).getAttackCooldown();
damage *= 0.2 + ((cooldown * cooldown) * 0.8);
damage += (enchantDamage * cooldown);
}
if (event.getEntity() instanceof LivingEntity && entity.getFallDistance() > 0.0 && !entity.isOnGround() && !entity.isClimbing() && !entity.isInWater() && !entity.hasPotionEffect(PotionEffectType.BLINDNESS) && !entity.hasPotionEffect(PotionEffectType.SLOW_FALLING)
&& !entity.isInsideVehicle() && !(entity instanceof Player && (((Player) entity).isSprinting() || ((Player) entity).getAttackCooldown() < 0.9)))
damage *= 1.5;
}
event.setDamage(damage);
id.simulateAction(Action.HIT_ENTITY, event, this);
}
public void wasHit(EntityDamageByEntityEvent event) {
id.simulateAction(Action.WAS_HIT, event, this);
}
public void projectileThrown(ProjectileLaunchEvent event) {
id.simulateAction(Action.WAS_THROWN, event, this);
}
public void projectileHit(ProjectileHitEvent event) {
id.simulateAction(Action.PROJECTILE_HIT, event, this);
}
public void shotBow(EntityShootBowEvent event) {
id.simulateAction(Action.SHOT_BOW, event, this);
}
Getting items
To get an ItemType you should use:
ItemType type = ItemType.getItemType(String name);
To get an items GenericItem class you can simply use:
GenericItem genericItem = GenericItem.getItemBase(ItemStack stack);
This will return null if there is no attached GenericItem class. If you want to swap the ItemStack for a GenericItem instance simply use:
GenericItem genericItem;
genericItem.setItem(ItemStack item);
Last updated