Skip to content

Commit

Permalink
Move coremod drops from GT5 (#934)
Browse files Browse the repository at this point in the history
* Move coremod drops from GT5

* Update dependencies.gradle

* Fix Galacticraft crash

---------

Co-authored-by: boubou19 <[email protected]>
  • Loading branch information
kuba6000 and boubou19 authored Aug 15, 2024
1 parent 4570e7a commit 303c5a0
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 2 deletions.
1 change: 1 addition & 0 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -207,6 +220,32 @@ public void onMobDrops(LivingDropsEvent pEvent) {
}
}

@Optional.Method(modid = "mobsinfo")
@Override
public void provideExtraDropsInformation(@NotNull String entityString, @NotNull ArrayList<MobDrop> 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<EntityItem> pDropList) {
try {
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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<ItemStack> 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();
}
}
}
2 changes: 2 additions & 0 deletions src/main/resources/assets/dreamcraft/lang/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 303c5a0

Please sign in to comment.