Skip to content

Commit

Permalink
DynamicTrees
Browse files Browse the repository at this point in the history
  • Loading branch information
strubium committed Feb 19, 2024
1 parent 64e2e1a commit 523956f
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 7 deletions.
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ minecraft {
dependencies {
deobfCompile "mezz.jei:jei_${jei_version}"
deobfCompile "cofh:RedstoneFlux:${redstoneflux_version}"

compileOnly "dynamictrees:DynamicTrees:1.12.2:0.9.2+"
}

jar {
Expand Down
7 changes: 1 addition & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,4 @@ mcp_mappings=snapshot_20180504
forge_version=14.23.3.2678

jei_version=1.12.2:4.8.5.159
waila_version=1.8.23-B38_1.12
top_version=1.12:1.12-1.4.20-12
mcjtylib_version=1.12-3.0.0
redstoneflux_version=1.12-2.0.0.1:universal
intwheel_version=1.12-1.2.7
oc_version=MC1.12.1-1.7.+:api
redstoneflux_version=1.12-2.0.0.1:universal
1 change: 0 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#Mon Sep 14 12:28:28 PDT 2015
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package mcjty.theoneprobe.apiimpl.providers.modcompat;

import com.ferreusveritas.dynamictrees.ModConfigs;
import com.ferreusveritas.dynamictrees.api.TreeHelper;
import com.ferreusveritas.dynamictrees.api.network.MapSignal;
import com.ferreusveritas.dynamictrees.blocks.BlockBranch;
import com.ferreusveritas.dynamictrees.blocks.BlockRooty;
import com.ferreusveritas.dynamictrees.blocks.BlockTrunkShell;
import com.ferreusveritas.dynamictrees.systems.nodemappers.NodeNetVolume;
import com.ferreusveritas.dynamictrees.trees.Species;
import mcjty.theoneprobe.Utilities;
import mcjty.theoneprobe.api.*;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

import javax.annotation.Nonnull;

public class DynamicTreesInfoProvider implements IProbeInfoProvider {

@Override
public String getID() {
return Utilities.getProviderId("dynamic_trees");
}

@Override
public void addProbeInfo(ProbeMode mode, IProbeInfo probeInfo, EntityPlayer player, World world, @Nonnull IBlockState blockState, IProbeHitData data) {
Block block = blockState.getBlock();
if (block instanceof BlockRooty) {
int life = ((BlockRooty) block).getSoilLife(blockState, world, data.getPos());
probeInfo.text(TextStyleClass.LABEL + "{*topextras.dynamic_trees.soil_life*} " + TextStyleClass.INFO + Math.floor(life * 100.0F / 15.0F) + "%");
} else if (block instanceof BlockBranch || block instanceof BlockTrunkShell) {
Species species = TreeHelper.getBestGuessSpecies(world, data.getPos());
if (species != Species.NULLSPECIES) {
probeInfo.text(TextStyleClass.LABEL + "{*topextras.dynamic_trees.species*} " + TextStyleClass.INFO + species.getLocalizedName());

IProbeInfo horizontalPane = probeInfo.horizontal(probeInfo.defaultLayoutStyle().alignment(ElementAlignment.ALIGN_CENTER));
horizontalPane.item(species.getSeedStack(1));

float volume = getTreeVolume(world, blockState, block, data.getPos());
if (volume > 0.0F) {
Species.LogsAndSticks logsAndSticks = species.getLogsAndSticks(volume);
if (logsAndSticks.logs > 0) horizontalPane.item(species.getFamily().getPrimitiveLogItemStack(logsAndSticks.logs));
if (logsAndSticks.sticks > 0) horizontalPane.item(species.getFamily().getStick(logsAndSticks.sticks));
}
}
}
}

private static float getTreeVolume(@Nonnull World world, @Nonnull IBlockState state, @Nonnull Block block, @Nonnull BlockPos pos) {
// Dereference proxy trunk shell block
if (block instanceof BlockTrunkShell) {
BlockTrunkShell.ShellMuse muse = ((BlockTrunkShell) block).getMuse(world, pos);
if (muse != null) {
state = muse.state;
block = state.getBlock();
pos = muse.pos;
}
}

if (block instanceof BlockBranch) {
BlockBranch branch = (BlockBranch) block;

// Analyze only part of the tree beyond the break point and calculate its volume, then destroy the branches
NodeNetVolume volumeSum = new NodeNetVolume();
branch.analyse(state, world, pos, null, new MapSignal(volumeSum));

return volumeSum.getVolume() * ModConfigs.treeHarvestMultiplier;
}

return 0.0F;
}
}

0 comments on commit 523956f

Please sign in to comment.