mirror of
https://github.com/GTNewHorizons/EnderCore.git
synced 2026-11-21 12:32:15 +00:00
tterrag1098/ttCore#36 Fix CME in autosmelt enchant
This commit is contained in:
1 parent
e8a5c364e2
commit
ed0828871c
1 file changed
+58
-72
@@ -19,86 +19,72 @@ import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
@Handler(HandlerType.FORGE)
|
||||
public class AutoSmeltHandler {
|
||||
|
||||
@SubscribeEvent
|
||||
public void handleBlockBreak(BlockEvent.HarvestDropsEvent event)
|
||||
{
|
||||
if (!event.world.isRemote && event.harvester != null)
|
||||
{
|
||||
ItemStack held = event.harvester.getCurrentEquippedItem();
|
||||
if (held != null)
|
||||
{
|
||||
int level = getAutoSmeltLevel(held);
|
||||
int fortune = EnchantmentHelper.getEnchantmentLevel(Enchantment.fortune.effectId, held);
|
||||
@SubscribeEvent
|
||||
public void handleBlockBreak(BlockEvent.HarvestDropsEvent event) {
|
||||
if (!event.world.isRemote && event.harvester != null) {
|
||||
ItemStack held = event.harvester.getCurrentEquippedItem();
|
||||
if (held != null) {
|
||||
int level = getAutoSmeltLevel(held);
|
||||
int fortune = EnchantmentHelper.getEnchantmentLevel(Enchantment.fortune.effectId, held);
|
||||
|
||||
if (level >= 0)
|
||||
{
|
||||
for (ItemStack stack : event.drops)
|
||||
{
|
||||
if (stack != null && !event.isSilkTouching)
|
||||
{
|
||||
if (FurnaceRecipes.smelting().getSmeltingResult(stack) != null)
|
||||
{
|
||||
ItemStack furnaceStack = FurnaceRecipes.smelting().getSmeltingResult(stack).copy();
|
||||
//Fortune stuffs
|
||||
if (fortune > 0 && ConfigHandler.allowAutoSmeltWithFortune)
|
||||
furnaceStack.stackSize *= (event.world.rand.nextInt(fortune + 1) + 1);
|
||||
if (level >= 0) {
|
||||
for (int i = 0; i < event.drops.size(); i++) {
|
||||
{
|
||||
ItemStack stack = event.drops.get(i);
|
||||
if (stack != null && !event.isSilkTouching) {
|
||||
if (FurnaceRecipes.smelting().getSmeltingResult(stack) != null) {
|
||||
ItemStack furnaceStack = FurnaceRecipes.smelting().getSmeltingResult(stack).copy();
|
||||
//Fortune stuffs
|
||||
if (fortune > 0 && ConfigHandler.allowAutoSmeltWithFortune)
|
||||
furnaceStack.stackSize *= (event.world.rand.nextInt(fortune + 1) + 1);
|
||||
|
||||
event.drops.remove(stack);
|
||||
event.drops.add(furnaceStack);
|
||||
event.drops.set(i, furnaceStack);
|
||||
|
||||
//XP (adapted vanilla code)
|
||||
int i = furnaceStack.stackSize;
|
||||
float f = FurnaceRecipes.smelting().func_151398_b(furnaceStack);
|
||||
int j;
|
||||
//XP (adapted vanilla code)
|
||||
int xp = furnaceStack.stackSize;
|
||||
float f = FurnaceRecipes.smelting().func_151398_b(furnaceStack);
|
||||
int j;
|
||||
|
||||
if (f == 0.0F)
|
||||
{
|
||||
i = 0;
|
||||
}
|
||||
else if (f < 1.0F)
|
||||
{
|
||||
j = MathHelper.floor_float((float) i * f);
|
||||
if (f == 0.0F) {
|
||||
xp = 0;
|
||||
} else if (f < 1.0F) {
|
||||
j = MathHelper.floor_float((float) xp * f);
|
||||
|
||||
if (j < MathHelper.ceiling_float_int((float) i * f) && (float) Math.random() < (float) i * f - (float) j)
|
||||
{
|
||||
++j;
|
||||
}
|
||||
if (j < MathHelper.ceiling_float_int((float) xp * f) && (float) Math.random() < (float) xp * f - (float) j) {
|
||||
++j;
|
||||
}
|
||||
|
||||
i = j;
|
||||
}
|
||||
xp = j;
|
||||
}
|
||||
|
||||
while (i > 0)
|
||||
{
|
||||
j = EntityXPOrb.getXPSplit(i);
|
||||
i -= j;
|
||||
event.world.spawnEntityInWorld(new EntityXPOrb(event.world, event.x, event.y + 0.5, event.z, j));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
while (xp > 0) {
|
||||
j = EntityXPOrb.getXPSplit(xp);
|
||||
xp -= j;
|
||||
event.world.spawnEntityInWorld(new EntityXPOrb(event.world, event.x, event.y + 0.5, event.z, j));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private int getAutoSmeltLevel(ItemStack tool)
|
||||
{
|
||||
if (tool == null)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
private int getAutoSmeltLevel(ItemStack tool) {
|
||||
if (tool == null) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
Map<Integer, Integer> enchants = EnchantmentHelper.getEnchantments(tool);
|
||||
for (int i : enchants.keySet())
|
||||
{
|
||||
Enchantment enchant = Enchantment.enchantmentsList[i];
|
||||
if (enchant == EnchantAutoSmelt.INSTANCE)
|
||||
{
|
||||
return enchants.get(i);
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
Map<Integer, Integer> enchants = EnchantmentHelper.getEnchantments(tool);
|
||||
for (int i : enchants.keySet()) {
|
||||
Enchantment enchant = Enchantment.enchantmentsList[i];
|
||||
if (enchant == EnchantAutoSmelt.INSTANCE) {
|
||||
return enchants.get(i);
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user