Publish a fixed OTEMod. Deaths were causing items to not drop
This commit is contained in:
parent
52a9f68f39
commit
ecedb3a54e
4 changed files with 92 additions and 60 deletions
|
@ -3,7 +3,7 @@
|
|||
org.gradle.jvmargs=-Xmx8G
|
||||
org.gradle.daemon=false
|
||||
|
||||
my_version=1.3.7.0306230213
|
||||
my_version=1.3.7.0306230423
|
||||
my_modgroup=dev.zontreck.otemod
|
||||
my_modid=otemod
|
||||
|
||||
|
|
|
@ -52,8 +52,60 @@ public class EventHandler {
|
|||
public static void playerDied(LivingDeathEvent event)
|
||||
{
|
||||
if(!(event.getEntity() instanceof Player))return;
|
||||
|
||||
Profile profile;
|
||||
try {
|
||||
ChatHelpers.broadcast(new TextComponent(DeathMessages.getRandomDeathMessage(Profile.get_profile_of(event.getEntity().getStringUUID()), event.getSource().getEntity())), event.getEntity().level.getServer());
|
||||
profile = Profile.get_profile_of(event.getEntity().getStringUUID());
|
||||
} catch (UserProfileNotYetExistsException e) {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
profile.deaths++;
|
||||
profile.commit();
|
||||
if(!OTEServerConfig.ENABLE_PLAYER_HEAD_DROPS.get())
|
||||
{
|
||||
return;
|
||||
}
|
||||
int looting=0;
|
||||
//ServerPlayer killedPlayer = (ServerPlayer)ent;
|
||||
if(event.getEntity() instanceof Player){
|
||||
ServerPlayer pla = profile.player;
|
||||
looting = ItemUtils.getEnchantmentLevel(Enchantments.MOB_LOOTING, pla.getMainHandItem());
|
||||
|
||||
}
|
||||
|
||||
// Calculate chance
|
||||
double base_chance = OTEServerConfig.CHANCE_OF_PLAYER_HEAD.get();
|
||||
base_chance += looting;
|
||||
base_chance *= 100;
|
||||
|
||||
Random rng = new Random();
|
||||
double num = rng.nextDouble(0,100000);
|
||||
if(num <= base_chance)
|
||||
{
|
||||
|
||||
ItemStack head = HeadUtilities.get(profile.username).setHoverName(ChatHelpers.macro(profile.nickname+"'s Head"));
|
||||
LoreContainer lore = new LoreContainer(head);
|
||||
LoreEntry entry = new LoreEntry();
|
||||
entry.text = ChatHelpers.macroize("!dark_green!Player: " + profile.name_color+profile.username);
|
||||
entry.bold=true;
|
||||
lore.miscData.LoreData.add(entry);
|
||||
|
||||
entry = new LoreEntry();
|
||||
entry.text = ChatHelpers.macroize("!Dark_Purple!Date: !Dark_Red![0]", Date.from(Instant.now()).toString());
|
||||
lore.miscData.LoreData.add(entry);
|
||||
|
||||
entry = new LoreEntry();
|
||||
entry.text = ChatHelpers.macroize("!Dark_Purple!Total Deaths: !Dark_Red![0]", String.valueOf(profile.deaths));
|
||||
lore.miscData.LoreData.add(entry);
|
||||
lore.commitLore();
|
||||
|
||||
|
||||
event.getEntity().spawnAtLocation(head);
|
||||
}
|
||||
|
||||
try {
|
||||
ChatHelpers.broadcast(new TextComponent(DeathMessages.getRandomDeathMessage(Profile.get_profile_of(event.getEntity().getStringUUID()), event.getSource())), event.getEntity().level.getServer());
|
||||
} catch (UserProfileNotYetExistsException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
|
@ -97,59 +149,6 @@ public class EventHandler {
|
|||
}
|
||||
}
|
||||
|
||||
if(killedentity instanceof Player)
|
||||
{
|
||||
Profile profile;
|
||||
try {
|
||||
profile = Profile.get_profile_of(killedentity.getStringUUID());
|
||||
} catch (UserProfileNotYetExistsException e) {
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
profile.deaths++;
|
||||
profile.commit();
|
||||
if(!OTEServerConfig.ENABLE_PLAYER_HEAD_DROPS.get())
|
||||
{
|
||||
return;
|
||||
}
|
||||
int looting=0;
|
||||
//ServerPlayer killedPlayer = (ServerPlayer)ent;
|
||||
if(ent instanceof Player){
|
||||
ServerPlayer pla = (ServerPlayer)ent;
|
||||
looting = ItemUtils.getEnchantmentLevel(Enchantments.MOB_LOOTING, pla.getMainHandItem());
|
||||
|
||||
}
|
||||
|
||||
// Calculate chance
|
||||
double base_chance = OTEServerConfig.CHANCE_OF_PLAYER_HEAD.get();
|
||||
base_chance += looting;
|
||||
base_chance *= 100;
|
||||
|
||||
Random rng = new Random();
|
||||
double num = rng.nextDouble(0,100000);
|
||||
if(num <= base_chance)
|
||||
{
|
||||
|
||||
ItemStack head = HeadUtilities.get(killedentity.getName().getContents()).setHoverName(ChatHelpers.macro(profile.nickname+"'s Head"));
|
||||
LoreContainer lore = new LoreContainer(head);
|
||||
LoreEntry entry = new LoreEntry();
|
||||
entry.text = ChatHelpers.macroize("!dark_green!Player: " + profile.name_color+profile.username);
|
||||
entry.bold=true;
|
||||
lore.miscData.LoreData.add(entry);
|
||||
|
||||
entry = new LoreEntry();
|
||||
entry.text = ChatHelpers.macroize("!Dark_Purple!Date: !Dark_Red![0]", Date.from(Instant.now()).toString());
|
||||
lore.miscData.LoreData.add(entry);
|
||||
|
||||
entry = new LoreEntry();
|
||||
entry.text = ChatHelpers.macroize("!Dark_Purple!Total Deaths: !Dark_Red![0]", String.valueOf(profile.deaths));
|
||||
lore.miscData.LoreData.add(entry);
|
||||
lore.commitLore();
|
||||
|
||||
|
||||
ev.getDrops().add(new ItemEntity(killedentity.level, killedentity.getX(), killedentity.getY(), killedentity.getZ(), head));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,24 +6,48 @@ import java.util.Random;
|
|||
|
||||
import dev.zontreck.libzontreck.profiles.Profile;
|
||||
import dev.zontreck.libzontreck.util.ChatHelpers;
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
|
||||
public class DeathMessages {
|
||||
private static final List<String> messages;
|
||||
private static final List<String> messages_falling;
|
||||
|
||||
static{
|
||||
messages=new ArrayList<>();
|
||||
messages.add("!Dark_Red!On their [0] death, [1] was reduced to a jittering flesh pile");
|
||||
messages.add("!Dark_Red![1] experienced their [0] death, while running away in fear from [2]");
|
||||
messages_falling = new ArrayList<>();
|
||||
messages.add("!Dark_Red!On their [0] death, [1]!Dark_Red! was reduced to a jittering flesh pile");
|
||||
messages.add("!Dark_Red![1]!Dark_Red! experienced their [0] death, while running away in fear from [2]");
|
||||
messages.add("!Dark_Red![1] was eaten alive by [2]");
|
||||
messages.add("!Dark_Red!For their [0] death, [1] got a little bit too careless!");
|
||||
messages.add("!Dark_Red!For their [0] death, [1]!Dark_Red! got a little bit too careless!");
|
||||
|
||||
messages_falling.add("!Dark_Red![1]!Dark_Red! clearly had the delusion they could fly.... their [0] death says otherwise.");
|
||||
messages_falling.add("!Dark_Red![1]!Dark_Red! tried flying, but forgot their wings");
|
||||
}
|
||||
|
||||
public static String getRandomDeathMessage(Profile playerWhoDied, Entity runningFrom)
|
||||
public static String getRandomDeathMessage(Profile playerWhoDied, DamageSource source)
|
||||
{
|
||||
Random rng = new Random();
|
||||
int msg = rng.nextInt(0, messages.size()-1);
|
||||
String sourceName="";
|
||||
if(source.isCreativePlayer())
|
||||
{
|
||||
sourceName = "A godlike player";
|
||||
}
|
||||
if(source.isFall())
|
||||
{
|
||||
msg = rng.nextInt(0,messages_falling.size()-1);
|
||||
return ChatHelpers.macroize(messages_falling.get(msg), String.valueOf(playerWhoDied.deaths), playerWhoDied.name_color + playerWhoDied.nickname);
|
||||
}
|
||||
|
||||
return ChatHelpers.macroize(messages.get(msg), String.valueOf(playerWhoDied.deaths), playerWhoDied.name_color + playerWhoDied.nickname, runningFrom.getName().getContents());
|
||||
if(source.getEntity() != null)
|
||||
{
|
||||
if(sourceName.equals(""))
|
||||
{
|
||||
sourceName = source.getEntity().getName().getContents();
|
||||
}
|
||||
} else sourceName = "an imaginary zombie!";
|
||||
|
||||
return ChatHelpers.macroize(messages.get(msg), String.valueOf(playerWhoDied.deaths), playerWhoDied.name_color + playerWhoDied.nickname, sourceName);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
package dev.zontreck.otemod.implementation;
|
||||
|
||||
public class Messages {
|
||||
public static final String OTE_PREFIX;
|
||||
|
||||
static{
|
||||
OTE_PREFIX = "!Dark_Gray![!Dark_Purple!OTE!Dark_Gray!] ";
|
||||
}
|
||||
}
|
Reference in a new issue