Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the fixes #40

Merged
merged 3 commits into from
Jan 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
modGroup=org.labellum.mc
modVersion=0.9.21
modVersion=0.9.16
modBaseName=dynamictreestfc
forgeVersion=1.12.2-14.23.5.2847
mcpVersion=stable_39
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.labellum.mc.dynamictreestfc;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

import com.ferreusveritas.dynamictrees.blocks.BlockBranch;
import net.dries007.tfc.ConfigTFC;
import net.dries007.tfc.util.OreDictionaryHelper;

import static org.labellum.mc.dynamictreestfc.DynamicTreesTFC.MOD_ID;

@Mod.EventBusSubscriber(modid = MOD_ID)
public class ForgeEventHandler
{
@SubscribeEvent
public static void onHarvestDrops(BlockEvent.HarvestDropsEvent event)
{
EntityPlayer player = event.getHarvester();
if (player != null && event.getState().getBlock() instanceof BlockBranch)
{
ItemStack held = player.getHeldItemMainhand();
if (OreDictionaryHelper.doesStackMatchOre(held, "axeStone"))
{
event.setDropChance(((float) ConfigTFC.General.TREE.stoneAxeReturnRate));
}
if (!player.isCreative())
held.damageItem(event.getDrops().size(), player);
}
}
}
6 changes: 3 additions & 3 deletions src/main/java/org/labellum/mc/dynamictreestfc/ModBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
import com.ferreusveritas.dynamictrees.ModConstants;
import com.ferreusveritas.dynamictrees.api.TreeRegistry;
import com.ferreusveritas.dynamictrees.api.cells.ICellKit;
import com.ferreusveritas.dynamictrees.blocks.BlockRootyDirt;
import com.ferreusveritas.dynamictrees.blocks.LeavesPaging;
import com.ferreusveritas.dynamictrees.blocks.LeavesProperties;
import net.dries007.tfc.objects.blocks.BlocksTFC;
import net.dries007.tfc.objects.blocks.stone.BlockRockVariant;
import net.dries007.tfc.objects.blocks.wood.BlockLeavesTFC;
import org.labellum.mc.dynamictreestfc.blocks.BlockRootyDirtTFC;

import static org.labellum.mc.dynamictreestfc.DynamicTreesTFC.MOD_ID;

Expand All @@ -26,11 +26,11 @@ public class ModBlocks
public static LeavesProperties[] tfcLeavesProperties;
public static Map<String, LeavesProperties> leafMap;
public static Map<String, ICellKit> kitMap;
public static BlockRootyDirt blockRootyDirt;
public static BlockRootyDirtTFC blockRootyDirt;

public static void preInit()
{
blockRootyDirt = new BlockRootyDirt(false);
blockRootyDirt = new BlockRootyDirtTFC();

kitMap = new HashMap<>();
fillMaps(kitMap);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,9 @@ public boolean removedByPlayer(IBlockState state, World world, BlockPos cutPos,
ItemStack tool = player.getHeldItemMainhand();
// after BlockLogTFC#harvestBlock
final Set<String> toolClasses = tool.getItem().getToolClasses(tool);
if (toolClasses.contains("axe") || toolClasses.contains("saw"))
if (toolClasses.contains("axe") || toolClasses.contains("saw") || player.isCreative())
{
if (OreDictionaryHelper.doesStackMatchOre(tool, "axeStone") && Constants.RNG.nextDouble() > ConfigTFC.General.TREE.stoneAxeReturnRate)
{
return false; // stone axe failure rate (default 40% of logs don't drop)
}
// success!
}
else if (toolClasses.contains("hammer") && ConfigTFC.General.TREE.enableHammerSticks)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public boolean removedByPlayer(IBlockState state, World world, BlockPos cutPos,
ItemStack tool = player.getHeldItemMainhand();
// after BlockLogTFC#harvestBlock
final Set<String> toolClasses = tool.getItem().getToolClasses(tool);
if (toolClasses.contains("axe") || toolClasses.contains("saw"))
if (toolClasses.contains("axe") || toolClasses.contains("saw") || player.isCreative())
{
// success!
}
Expand All @@ -39,11 +39,6 @@ else if (ConfigTFC.General.TREE.requiresAxe)
// Here, there was no valid tool used. Deny spawning any drops since logs require axes
return false; //Also no wood for you!
}
else
{
// or no tool, but handle normally
}

return super.removedByPlayer(state, world, cutPos, player, canHarvest);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package org.labellum.mc.dynamictreestfc.blocks;

import java.util.Random;

import javax.annotation.Nonnull;
import javax.annotation.ParametersAreNonnullByDefault;

import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

import net.minecraftforge.common.property.IExtendedBlockState;

import com.ferreusveritas.dynamictrees.api.ICustomRootDecay;
import com.ferreusveritas.dynamictrees.blocks.BlockRootyDirt;
import com.ferreusveritas.dynamictrees.blocks.MimicProperty;
import net.dries007.tfc.api.types.Rock;
import net.dries007.tfc.objects.blocks.stone.BlockRockVariant;
import net.dries007.tfc.world.classic.chunkdata.ChunkDataTFC;
import org.labellum.mc.dynamictreestfc.TFCRootDecay;

@ParametersAreNonnullByDefault
public class BlockRootyDirtTFC extends BlockRootyDirt
{
private static final EnumFacing[] NOT_UP = new EnumFacing[] {EnumFacing.DOWN, EnumFacing.EAST, EnumFacing.NORTH, EnumFacing.WEST, EnumFacing.SOUTH};

public BlockRootyDirtTFC()
{
super(false);
}

@Override
public IBlockState getMimic(IBlockAccess access, BlockPos pos) // this IBlockAccess is actually a ChunkCache which has no World access (therefore no chunk data)
{
IBlockState mimicState = super.getMimic(access, pos);
if (mimicState.getBlock() == Blocks.DIRT)
{
for (int i = 1; i < 4; i++) // so we will search manually
{
for (EnumFacing d : NOT_UP)
{
IBlockState state = access.getBlockState(pos.offset(d, i));
if (state.getBlock() instanceof BlockRockVariant)
{
Rock rock = ((BlockRockVariant) state.getBlock()).getRock();
return BlockRockVariant.get(rock, Rock.Type.DIRT).getDefaultState();
}
}
}
// this doesn't *really* matter because the decay BlockState has World access and will always be correct
// so in the 0.00001% of cases where the rooty block is somehow floating with nothing around, this will do.
return BlockRockVariant.get(Rock.LIMESTONE, Rock.Type.DIRT).getDefaultState();
}
return mimicState;
}

@Override
public void getDrops(NonNullList<ItemStack> drops, IBlockAccess world, BlockPos pos, IBlockState state, int fortune)
{
if (world instanceof World) //lol
{
Rock rock = ChunkDataTFC.get((World) world, pos).getRockHeight(pos);
drops.clear();
drops.add(new ItemStack(BlockRockVariant.get(rock, Rock.Type.DIRT)));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,26 @@
import net.minecraft.client.renderer.BlockModelShapes;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.block.model.IBakedModel;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.model.IModel;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.client.model.ModelLoaderRegistry;
import net.minecraftforge.common.property.IExtendedBlockState;

import com.ferreusveritas.dynamictrees.blocks.MimicProperty;
import com.ferreusveritas.dynamictrees.models.bakedmodels.BakedModelBlockRooty;

import static org.labellum.mc.dynamictreestfc.DynamicTreesTFC.MOD_ID;

public class BakedModelBlockRootyTFC extends BakedModelBlockRooty
{
private TextureAtlasSprite particleSprite = Minecraft.getMinecraft().getTextureMapBlocks().getTextureExtry("minecraft:dirt");
private static final IModel rootyIModel = ModelLoaderRegistry.getModelOrMissing(new ResourceLocation(MOD_ID, "block/roots"));
private static final IBakedModel rootyIBakedModel = rootyIModel.bake(rootyIModel.getDefaultState(), DefaultVertexFormats.BLOCK, ModelLoader.defaultTextureGetter());

public BakedModelBlockRootyTFC()
{
super(null);
Expand All @@ -35,7 +47,17 @@ public List<BakedQuad> getQuads(IBlockState state, EnumFacing side, long rand)
BlockModelShapes blockModelShapes = Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes();
IBakedModel mimicModel = blockModelShapes.getModelForState(mimicState);
quads.addAll(mimicModel.getQuads(mimicState, side, rand));
quads.addAll(rootyIBakedModel.getQuads(state, side, rand));
if (!quads.isEmpty())
particleSprite = quads.get(0).getSprite();
}
return quads;
}

@Override
@Nonnull
public TextureAtlasSprite getParticleTexture()
{
return particleSprite;
}
}
19 changes: 19 additions & 0 deletions src/main/resources/assets/dynamictreestfc/models/block/roots.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"credit": "Made with Blockbench",
"textures": {
"particle": "dynamictrees:blocks/roots",
"side": "dynamictrees:blocks/roots"
},
"elements": [
{
"from": [-0.1, -0.1, -0.1],
"to": [16.1, 16.1, 16.1],
"faces": {
"north": {"uv": [0, 0, 16, 16], "texture": "#side"},
"east": {"uv": [0, 0, 16, 16], "texture": "#side"},
"south": {"uv": [0, 0, 16, 16], "texture": "#side"},
"west": {"uv": [0, 0, 16, 16], "texture": "#side"}
}
}
]
}