Add Item.canDestroyBlocksInCreative() allowing more items to not break blocks in creative (#3805)
This commit is contained in:
parent
646a8977d6
commit
dbc6baf2f7
4 changed files with 63 additions and 10 deletions
|
@ -1,18 +1,23 @@
|
|||
--- ../src-base/minecraft/net/minecraft/client/multiplayer/PlayerControllerMP.java
|
||||
+++ ../src-work/minecraft/net/minecraft/client/multiplayer/PlayerControllerMP.java
|
||||
@@ -122,6 +122,12 @@
|
||||
@@ -122,10 +122,16 @@
|
||||
}
|
||||
}
|
||||
|
||||
- if (this.field_78779_k.func_77145_d() && !this.field_78776_a.field_71439_g.func_184614_ca().func_190926_b() && this.field_78776_a.field_71439_g.func_184614_ca().func_77973_b() instanceof ItemSword)
|
||||
+ ItemStack stack = field_78776_a.field_71439_g.func_184614_ca();
|
||||
+ if (!stack.func_190926_b() && stack.func_77973_b().onBlockStartBreak(stack, p_187103_1_, field_78776_a.field_71439_g))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
+
|
||||
+ if (this.field_78779_k.func_77145_d() && !stack.func_190926_b() && !stack.func_77973_b().canDestroyBlockInCreative(field_78776_a.field_71441_e, p_187103_1_, stack, field_78776_a.field_71439_g))
|
||||
+ {
|
||||
+ return false;
|
||||
+ }
|
||||
+
|
||||
if (this.field_78779_k.func_77145_d() && !this.field_78776_a.field_71439_g.func_184614_ca().func_190926_b() && this.field_78776_a.field_71439_g.func_184614_ca().func_77973_b() instanceof ItemSword)
|
||||
else
|
||||
{
|
||||
return false;
|
||||
World world = this.field_78776_a.field_71441_e;
|
||||
@@ -143,19 +149,13 @@
|
||||
else
|
||||
{
|
||||
|
|
|
@ -60,7 +60,7 @@
|
|||
return p_77621_1_.func_147447_a(vec3d, vec3d1, p_77621_3_, !p_77621_3_, false);
|
||||
}
|
||||
|
||||
@@ -433,11 +440,613 @@
|
||||
@@ -433,11 +440,625 @@
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -510,6 +510,18 @@
|
|||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * Checked from {@link net.minecraft.client.multiplayer.PlayerControllerMP#onPlayerDestroyBlock(BlockPos pos) PlayerControllerMP.onPlayerDestroyBlock()}
|
||||
+ * when a creative player left-clicks a block with this item.
|
||||
+ * Also checked from {@link net.minecraftforge.common.ForgeHooks#onBlockBreakEvent(World, GameType, EntityPlayerMP, BlockPos) ForgeHooks.onBlockBreakEvent()}
|
||||
+ * to prevent sending an event.
|
||||
+ * @return true if the given player can destroy specified block in creative mode with this item
|
||||
+ */
|
||||
+ public boolean canDestroyBlockInCreative(World world, BlockPos pos, ItemStack stack, EntityPlayer player)
|
||||
+ {
|
||||
+ return !(this instanceof ItemSword);
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * ItemStack sensitive version of {@link #canHarvestBlock(IBlockState)}
|
||||
+ * @param state The block trying to harvest
|
||||
+ * @param stack The itemstack used to harvest the block
|
||||
|
@ -674,7 +686,7 @@
|
|||
public static void func_150900_l()
|
||||
{
|
||||
func_179214_a(Blocks.field_150350_a, new ItemAir(Blocks.field_150350_a));
|
||||
@@ -972,6 +1581,8 @@
|
||||
@@ -972,6 +1593,8 @@
|
||||
private final float field_78010_h;
|
||||
private final float field_78011_i;
|
||||
private final int field_78008_j;
|
||||
|
@ -683,7 +695,7 @@
|
|||
|
||||
private ToolMaterial(int p_i1874_3_, int p_i1874_4_, float p_i1874_5_, float p_i1874_6_, int p_i1874_7_)
|
||||
{
|
||||
@@ -1007,9 +1618,26 @@
|
||||
@@ -1007,9 +1630,26 @@
|
||||
return this.field_78008_j;
|
||||
}
|
||||
|
||||
|
|
|
@ -63,7 +63,6 @@ import net.minecraft.item.ItemBucket;
|
|||
import net.minecraft.item.ItemPickaxe;
|
||||
import net.minecraft.item.ItemSpade;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ItemSword;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.NetHandlerPlayServer;
|
||||
import net.minecraft.network.Packet;
|
||||
|
@ -754,7 +753,9 @@ public class ForgeHooks
|
|||
{
|
||||
// Logic from tryHarvestBlock for pre-canceling the event
|
||||
boolean preCancelEvent = false;
|
||||
if (gameType.isCreative() && !entityPlayer.getHeldItemMainhand().isEmpty() && entityPlayer.getHeldItemMainhand().getItem() instanceof ItemSword)
|
||||
ItemStack itemstack = entityPlayer.getHeldItemMainhand();
|
||||
if (gameType.isCreative() && !itemstack.isEmpty()
|
||||
&& !itemstack.getItem().canDestroyBlockInCreative(world, pos, itemstack, entityPlayer))
|
||||
preCancelEvent = true;
|
||||
|
||||
if (gameType.isAdventure())
|
||||
|
@ -764,7 +765,6 @@ public class ForgeHooks
|
|||
|
||||
if (!entityPlayer.isAllowEdit())
|
||||
{
|
||||
ItemStack itemstack = entityPlayer.getHeldItemMainhand();
|
||||
if (itemstack.isEmpty() || !itemstack.canDestroy(world.getBlockState(pos).getBlock()))
|
||||
preCancelEvent = true;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
package net.minecraftforge.test;
|
||||
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
|
||||
@Mod(modid = ItemCanDestroyBlocksInCreativeTest.MODID, name = "Item.canDestroyBlockInCreative() Test", version = "1.0", acceptableRemoteVersions = "*")
|
||||
public class ItemCanDestroyBlocksInCreativeTest
|
||||
{
|
||||
public static final boolean ENABLE = true;
|
||||
public static final String MODID = "item_can_destroy_blocks_in_creative_test";
|
||||
|
||||
public static Item testItem = new Item()
|
||||
{
|
||||
@Override
|
||||
public boolean canDestroyBlockInCreative(World world, BlockPos pos, ItemStack stack, EntityPlayer player)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}.setRegistryName(MODID, "item_test")
|
||||
.setUnlocalizedName(MODID + ".item_test")
|
||||
.setCreativeTab(CreativeTabs.TOOLS);
|
||||
|
||||
@Mod.EventHandler
|
||||
public static void init(FMLInitializationEvent event)
|
||||
{
|
||||
if (ENABLE)
|
||||
GameRegistry.register(testItem);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue