Support effective materials of vanilla AxeItem (#7351)

This commit is contained in:
cech12 2020-09-28 20:01:59 +02:00 committed by GitHub
parent 03082c361a
commit 248d207dbc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 54 additions and 1 deletions

View file

@ -45,6 +45,7 @@ import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import net.minecraft.advancements.Advancement; import net.minecraft.advancements.Advancement;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.fluid.*; import net.minecraft.fluid.*;
import net.minecraft.loot.LootContext; import net.minecraft.loot.LootContext;
import net.minecraft.loot.LootTable; import net.minecraft.loot.LootTable;
@ -213,7 +214,11 @@ public class ForgeHooks
blocks.forEach(block -> blockToolSetter.accept(block, ToolType.PICKAXE, 0)); blocks.forEach(block -> blockToolSetter.accept(block, ToolType.PICKAXE, 0));
blocks = getPrivateValue(ShovelItem.class, null, 0); blocks = getPrivateValue(ShovelItem.class, null, 0);
blocks.forEach(block -> blockToolSetter.accept(block, ToolType.SHOVEL, 0)); blocks.forEach(block -> blockToolSetter.accept(block, ToolType.SHOVEL, 0));
//TODO Axes check Material and Blocks now. //Axes check Materials and Blocks now.
Set<Material> materials = getPrivateValue(AxeItem.class, null, 0);
for (Block block : ForgeRegistries.BLOCKS)
if (materials.contains(block.getDefaultState().getMaterial()))
blockToolSetter.accept(block, ToolType.AXE, 0);
blocks = getPrivateValue(AxeItem.class, null, 1); blocks = getPrivateValue(AxeItem.class, null, 1);
blocks.forEach(block -> blockToolSetter.accept(block, ToolType.AXE, 0)); blocks.forEach(block -> blockToolSetter.accept(block, ToolType.AXE, 0));
blocks = getPrivateValue(HoeItem.class, null, 0); blocks = getPrivateValue(HoeItem.class, null, 0);

View file

@ -0,0 +1,46 @@
/*
* Minecraft Forge
* Copyright (c) 2016-2020.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package net.minecraftforge.debug.block;
import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.text.StringTextComponent;
import net.minecraftforge.common.ToolType;
import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
@Mod("block_harvest_tool_test")
@Mod.EventBusSubscriber
public class HarvestToolTest
{
@SubscribeEvent
public static void onBlockBreak(BlockEvent.BreakEvent event)
{
PlayerEntity player = event.getPlayer();
BlockState state = event.getState();
for (ToolType toolType : player.getHeldItemMainhand().getToolTypes()) {
if (state.isToolEffective(toolType)) {
player.sendMessage(new StringTextComponent(String.format("Tool was effective. tool type: %s | harvest level: %d", toolType.getName(), state.getHarvestLevel())), player.getUniqueID());
break;
}
}
}
}

View file

@ -18,6 +18,8 @@ license="LGPL v2.1"
modId="slipperiness_test" modId="slipperiness_test"
[[mods]] [[mods]]
modId="custom_slime_block_test" modId="custom_slime_block_test"
[[mods]]
modId="block_harvest_tool_test"
[[mods]] [[mods]]
modId="client_chat_event_test" modId="client_chat_event_test"
[[mods]] [[mods]]