Merge branch 'master' into dumpbutton

This commit is contained in:
Martin Robertz authored and GitHub committed 2026-04-05 20:01:49 +02:00
commit 4a0135beb1
3 files changed
+119 -20

No files matched your search

@@ -1,11 +1,11 @@
package tconstruct.items.tools;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Queue;
import java.util.Set;
import java.util.SortedSet;
import java.util.Stack;
import java.util.TreeSet;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
@@ -118,41 +118,48 @@ public class LumberAxe extends AOEHarvestTool {
public static boolean detectTree(World world, int pX, int pY, int pZ) {
Stack<ChunkPosition> candidates = new Stack<>();
SortedSet<ChunkPosition> visited = new TreeSet<>(Comparator.comparingInt((ChunkPosition a) -> a.chunkPosY));
Set<ChunkPosition> wood = new HashSet<>();
Set<ChunkPosition> nonWood = new HashSet<>();
candidates.add(new ChunkPosition(pX, pY, pZ));
while (!candidates.isEmpty()) {
ChunkPosition candidate = candidates.pop();
if (wood.contains(candidate) || nonWood.contains(candidate)) {
continue;
}
int curX = candidate.chunkPosX, curY = candidate.chunkPosY, curZ = candidate.chunkPosZ;
Block block = world.getBlock(curX, curY, curZ);
if (!block.isWood(world, curX, curY, curZ)) {
continue;
}
if (!visited.add(candidate)) {
continue;
}
// add the current layer and above
for (int offX = 0; offX < 3; offX++) {
for (int offY = 0; offY < 2; offY++) {
for (int offZ = 0; offZ < 3; offZ++) {
ChunkPosition newCandidate = new ChunkPosition(curX - 1 + offX, curY + offY, curZ - 1 + offZ);
if (!visited.contains(newCandidate)) {
candidates.add(newCandidate);
if (block.isWood(world, curX, curY, curZ)) {
for (int offX = 0; offX < 3; offX++) {
for (int offY = 0; offY < 2; offY++) {
for (int offZ = 0; offZ < 3; offZ++) {
ChunkPosition newCandidate = new ChunkPosition(
curX - 1 + offX,
curY + offY,
curZ - 1 + offZ);
if (!(wood.contains(newCandidate) || nonWood.contains(newCandidate))) {
candidates.add(newCandidate);
}
}
}
}
wood.add(candidate);
} else {
nonWood.add(candidate);
}
}
// not even one match, so there were no logs.
if (visited.isEmpty()) {
if (wood.isEmpty()) {
return false;
}
ChunkPosition topmost = visited.last();
ChunkPosition topmost = Collections.max(wood, Comparator.comparingInt((ChunkPosition a) -> a.chunkPosY));
// check if there were enough leaves around the last position
// pos now contains the block above the topmost log
@@ -234,6 +234,18 @@ public class PHConstruct {
true,
"Allow stacks of essence berries to be consumed at once when shifting (this does not spawn XP orbs in world).")
.getBoolean();
disgustingXPBerries = config.get(
"general",
"Allow effects for consumption",
false,
"Grants effects to players when consuming XP berries").getBoolean();
disgustingXPBerryEffects = config.get(
"general",
"Applied effects",
new String[] { "9, 200, 1, 1200, 2, false", "17, 160, 1, 1000, 3, false", "DAMAGE, 0.5, false ",
"9, 400, 2, 1200, 2, true", "17, 320, 1, 1000, 3, true", "DAMAGE, 0.3, true" },
" If an effect fails to apply, check the console for information \n FORMAT: \n potionID (Can also put \"DAMAGE\" to hurt the player instead, \n effectDuration (in ticks) (or DAMAGE effect strength) , \n initialAmplifier (Exclude if the first parameter is DAMAGE), \n maxDuration (this is the maximum duration the potions can stack in ticks (Exclude if the first parameter is DAMAGE)), \n maxAmplifier (the maximum allowed potionAmplifier with multiple effects uses (Exclude if the first parameter is DAMAGE)), \n stackExclusiveEffect (a true or false value which allows the effect to be only applied when the essence berries are eaten while shift is held (Only works if Allow stackwise consumption = true)")
.getStringList();
disableAllRecipes = config.get(
"general",
"Disable All Recipes",
@@ -443,6 +455,8 @@ public class PHConstruct {
public static boolean tconComesFirst;
public static boolean consumeXPBerryStacks;
public static boolean disgustingXPBerries;
public static String[] disgustingXPBerryEffects;
public static boolean disableAllRecipes;
public static double HarvestToolAOERelativeStrength;
@@ -6,12 +6,14 @@ import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityXPOrb;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import mantle.items.abstracts.CraftingItem;
import tconstruct.TConstruct;
import tconstruct.library.TConstructRegistry;
import tconstruct.util.config.PHConstruct;
@@ -53,7 +55,7 @@ public class OreBerries extends CraftingItem {
@Override
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) {
if (stack.getItemDamage() == 5) {
if (!PHConstruct.consumeXPBerryStacks || !player.isSneaking()) {
if (!PHConstruct.consumeXPBerryStacks || !player.isSneaking() || stack.stackSize == 1) {
EntityXPOrb entity = new EntityXPOrb(
world,
player.posX,
@@ -62,11 +64,28 @@ public class OreBerries extends CraftingItem {
itemRand.nextInt(14) + 6);
spawnEntity(player.posX, player.posY + 1, player.posZ, entity, world, player);
if (!player.capabilities.isCreativeMode) stack.stackSize--;
if (PHConstruct.disgustingXPBerries) {
if (applyBerryEffects(player, false) && !world.isRemote) player.worldObj.playSoundAtEntity(
player,
"game.player.hurt",
0.5F,
player.worldObj.rand.nextFloat() * 0.1F + 0.9F);
}
} else if (PHConstruct.consumeXPBerryStacks) {
int xpToAdd = 0;
boolean wasPlayerDamaged = false;
for (int i = stack.stackSize; i > 0; i--) {
xpToAdd += itemRand.nextInt(14) + 6;
if (PHConstruct.disgustingXPBerries) {
wasPlayerDamaged = applyBerryEffects(player, true);
}
}
if (PHConstruct.disgustingXPBerries && wasPlayerDamaged && !world.isRemote)
player.worldObj.playSoundAtEntity(
player,
"game.player.hurt",
0.5F,
player.worldObj.rand.nextFloat() * 0.1F + 0.9F);
player.addExperience(xpToAdd);
if (!player.capabilities.isCreativeMode) stack.stackSize = 0;
}
@@ -79,4 +98,63 @@ public class OreBerries extends CraftingItem {
world.spawnEntityInWorld(entity);
}
}
/**
* parameters ID | DURATION | initialAmplifier | maxDuration | maxAmplifier | stackExclusive
*
* @param player the player that's eating the berries
* @param isShifting is the player shifting?
* @return Was one of the effects DAMAGE (used properly play the damage sound in account to the player shifting)
*/
private static boolean applyBerryEffects(EntityPlayer player, boolean isShifting) {
boolean output = false;
if (player.capabilities.isCreativeMode || player.worldObj.isRemote) return false;
for (String effect : PHConstruct.disgustingXPBerryEffects) {
try {
String[] parameters = effect.replaceAll(" ", "").split(",");
boolean isDamageEffect = parameters[0].equals("DAMAGE");
if (!(isDamageEffect && parameters.length == 3) && parameters.length != 6) {
throw new RuntimeException("Too many or few parameters");
} else {
if (isShifting == Boolean.parseBoolean(parameters[isDamageEffect ? 2 : 5])) {
if (isDamageEffect) {
player.setHealth(player.getHealth() - Float.parseFloat(parameters[1]));
output = true;
} else {
player.addPotionEffect(getBerryEffect(player, parameters));
}
}
}
} catch (Exception e) {
TConstruct.logger.error(
"ERROR APPLYING ESSENCE BERRY EFFECT: {} ERROR: {} STACKTRACE: {}",
effect,
e.getMessage(),
e.getStackTrace());
}
}
return output;
}
/**
* Don't ask how the amplifier increase system works, I'm not fully sure myself @GamingB3ast
*
* @param player
* @param parameters ID | DURATION | initialAmplifier | maxDuration | maxAmplifier | stackExclusive
* @return The potion effect which is applied onto the player
*/
private static PotionEffect getBerryEffect(EntityPlayer player, String[] parameters) {
int duration = Integer.parseInt(parameters[1]);
int amplifier = Integer.parseInt(parameters[2]);
for (PotionEffect currentEffect : player.getActivePotionEffects()) {
if (currentEffect.getPotionID() == Integer.parseInt(parameters[0])) {
duration = Math.min(Integer.parseInt(parameters[3]), currentEffect.getDuration() + 40);
amplifier = currentEffect.getAmplifier() + 1;
int step = Integer.parseInt(parameters[3]) / (Integer.parseInt(parameters[4]) + 1 - amplifier) - 80;
amplifier += Math.min(Integer.parseInt(parameters[3]) - 1, (duration >= step * amplifier ? 1 : 0));
break;
}
}
return new PotionEffect(Integer.parseInt(parameters[0]), duration, amplifier - 1);
}
}