From 303c5a018b6826d8d96cb3f1123e921f8f9cc9e8 Mon Sep 17 00:00:00 2001 From: Jakub <53441451+kuba6000@users.noreply.github.com> Date: Thu, 15 Aug 2024 18:48:08 +0200 Subject: [PATCH] Move coremod drops from GT5 (#934) * Move coremod drops from GT5 * Update dependencies.gradle * Fix Galacticraft crash --------- Co-authored-by: boubou19 --- dependencies.gradle | 1 + .../modcustomdrops/CustomDropsHandler.java | 75 ++++++++++++++++++- .../assets/dreamcraft/lang/en_US.lang | 2 + 3 files changed, 76 insertions(+), 2 deletions(-) diff --git a/dependencies.gradle b/dependencies.gradle index 1b14bdc4a..feddca165 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -24,6 +24,7 @@ dependencies { compileOnly("com.github.GTNewHorizons:Galacticraft:3.2.1-GTNH:dev") { transitive = false } compileOnly("com.github.GTNewHorizons:ForestryMC:4.9.7:dev") { transitive = false } compileOnly("com.github.GTNewHorizons:DetravScannerMod:1.8.1:dev") { transitive = false } + compileOnlyApi("com.github.GTNewHorizons:Mobs-Info:0.4.1-GTNH:dev") runtimeOnlyNonPublishable rfg.deobf("curse.maven:biomes-o-plenty-220318:2499612") runtimeOnlyNonPublishable("com.github.GTNewHorizons:WailaHarvestability:1.2.1-GTNH:dev") diff --git a/src/main/java/com/dreammaster/modcustomdrops/CustomDropsHandler.java b/src/main/java/com/dreammaster/modcustomdrops/CustomDropsHandler.java index 356d871d5..09232195f 100644 --- a/src/main/java/com/dreammaster/modcustomdrops/CustomDropsHandler.java +++ b/src/main/java/com/dreammaster/modcustomdrops/CustomDropsHandler.java @@ -12,27 +12,40 @@ import javax.xml.bind.Marshaller; import javax.xml.bind.Unmarshaller; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLiving; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.JsonToNBT; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.StatCollector; +import net.minecraft.world.World; import net.minecraftforge.common.DimensionManager; import net.minecraftforge.common.util.FakePlayer; import net.minecraftforge.event.entity.living.LivingDropsEvent; +import org.jetbrains.annotations.NotNull; + import com.dreammaster.lib.Refstrings; import com.dreammaster.main.MainRegistry; +import com.kuba6000.mobsinfo.api.IChanceModifier; +import com.kuba6000.mobsinfo.api.IMobExtraInfoProvider; +import com.kuba6000.mobsinfo.api.MobDrop; +import com.kuba6000.mobsinfo.api.MobRecipe; +import cpw.mods.fml.common.Optional; import cpw.mods.fml.common.eventhandler.SubscribeEvent; import eu.usrv.yamcore.auxiliary.ItemDescriptor; import eu.usrv.yamcore.auxiliary.LogHelper; import eu.usrv.yamcore.auxiliary.PlayerChatHelper; import eu.usrv.yamcore.persisteddata.PersistedDataBase; +import io.netty.buffer.ByteBuf; import thaumcraft.common.lib.FakeThaumcraftPlayer; -public class CustomDropsHandler { +@Optional.Interface(iface = "com.kuba6000.mobsinfo.api.IMobExtraInfoProvider", modid = "mobsinfo") +public class CustomDropsHandler implements IMobExtraInfoProvider { private LogHelper _mLogger = MainRegistry.Logger; private String _mConfigFileName; @@ -207,6 +220,32 @@ public void onMobDrops(LivingDropsEvent pEvent) { } } + @Optional.Method(modid = "mobsinfo") + @Override + public void provideExtraDropsInformation(@NotNull String entityString, @NotNull ArrayList drops, + @NotNull MobRecipe recipe) { + CustomDrops.CustomDrop customDrop = _mCustomDrops.FindDropEntry(recipe.entity); + if (customDrop == null) return; + for (CustomDrops.CustomDrop.Drop drop : customDrop.getDrops()) { + ItemStack stack = ItemDescriptor.fromString(drop.getItemName()).getItemStackwNBT(1, drop.mTag); + if (stack == null) continue; + double chance = drop.getChance() / 100d; + if (drop.getIsRandomAmount()) { + chance *= MobDrop.getChanceBasedOnFromTo(1, drop.getAmount()); + } else { + stack.stackSize = drop.getAmount(); + } + MobDrop mobDrop = MobDrop.create(stack).withChance(chance).withHardPlayerRestriction(); + if (drop.getLimitedDropCount() > 0) { + mobDrop.clampChance(); + mobDrop.withChanceModifiers( + new IChanceModifier.NormalChance(mobDrop.chance / 100d), + new LimitedDropCountModifier(drop.getLimitedDropCount())); + } + drops.add(mobDrop); + } + } + private void HandleCustomDrops(CustomDrops.CustomDrop tCustomDrop, EntityLivingBase tEntity, EntityPlayer tEP, ArrayList pDropList) { try { @@ -242,7 +281,7 @@ private void HandleCustomDrops(CustomDrops.CustomDrop tCustomDrop, EntityLivingB } if (dr.getIsRandomAmount()) { - tFinalAmount = Math.max(1, MainRegistry.Rnd.nextInt(dr.getAmount() + 1)); + tFinalAmount = MainRegistry.Rnd.nextInt(dr.getAmount()) + 1; } ItemStack tDropStack = ItemDescriptor.fromString(dr.getItemName()) @@ -274,4 +313,36 @@ public void toggleDeathInfoForPlayer(EntityPlayer pEP) { PlayerChatHelper.SendInfo(pEP, "Death-Debug is now enabled"); } } + + private static class LimitedDropCountModifier implements IChanceModifier { + + int limit; + + LimitedDropCountModifier() {} + + LimitedDropCountModifier(int limit) { + this.limit = limit; + } + + @Override + public String getDescription() { + return StatCollector.translateToLocalFormatted("dreamcraft.mobsinfocompat.limitedropcount", limit); + } + + @Override + public double apply(double chance, @NotNull World world, @NotNull List drops, Entity attacker, + EntityLiving victim) { + return 0; + } + + @Override + public void writeToByteBuf(ByteBuf byteBuf) { + byteBuf.writeInt(limit); + } + + @Override + public void readFromByteBuf(ByteBuf byteBuf) { + limit = byteBuf.readInt(); + } + } } diff --git a/src/main/resources/assets/dreamcraft/lang/en_US.lang b/src/main/resources/assets/dreamcraft/lang/en_US.lang index 088140d45..6c1dcfcb8 100644 --- a/src/main/resources/assets/dreamcraft/lang/en_US.lang +++ b/src/main/resources/assets/dreamcraft/lang/en_US.lang @@ -1771,3 +1771,5 @@ item.tconstruct.manual.weaponry.crossbow=\n\nCrossbow:\nThose pesky metals are s item.tconstruct.manual.weaponry.projectiles=Projectiles\nFor these projectiles goes: The heavier the projectile, the more damage carries through armor.\n\nArrows:\nThe bread and butter of every ranger. Arrows can be built from many different materials. It needs an arrow head, a shaft and a fletching.\nThe choice of materials allows a balance between damage, arrow-count, accuracy and fragility. The head material is crucial for its weight.\nA fragile arrow has a chance to break on impact with terrain. Arrows always break when they hit a target, however the reinforced trait gives a chance for the arrow to survive the impact. item.tconstruct.manual.weaponry.part_materials=\n\nValid Shaft Materials:\n* Stick\n* Sugarcane\n* Bone\n* Blaze Rod\n\nValid Fletching Materials:\n* Leaves\n* Slimeleaves\n* Feathers\n* Slime item.tconstruct.manual.weaponry.bolts=\n\nBolts:\nCrafting bolts is a delicate process. First you need a core in the form of a tool rod.\nTake this tool rod to a smeltery and put it into a Casting Table. Pour some metal onto it to coat the tip with a more damaging material.\nAfter this process, add a fletching and your bolts are ready to be used.\n\nSince the bolts consist of a harder core and tip they carry more weight than regular arrows, making them perfect to fight armored targets. + +dreamcraft.mobsinfocompat.limitedropcount=Drops only %s times per person