3
0

增加对mod消息与物品左右键的方块放置监听

This commit is contained in:
聪聪 2017-07-04 14:30:21 +08:00
parent bfe43ae465
commit f1db52bb04
5 changed files with 151 additions and 46 deletions

View File

@ -0,0 +1,43 @@
--- ../src-base/minecraft/cpw/mods/fml/common/network/FMLEventChannel.java
+++ ../src-work/minecraft/cpw/mods/fml/common/network/FMLEventChannel.java
@@ -1,16 +1,20 @@
package cpw.mods.fml.common.network;
-import io.netty.channel.ChannelFutureListener;
-import io.netty.channel.ChannelHandlerContext;
import java.util.EnumMap;
-import net.minecraft.client.network.NetHandlerPlayClient;
-import net.minecraft.entity.player.EntityPlayerMP;
-import net.minecraft.network.NetHandlerPlayServer;
+
+import cc.capture.type.CaptureBlock;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.eventhandler.EventBus;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
+import cpw.mods.fml.common.network.FMLNetworkEvent.ServerCustomPacketEvent;
import cpw.mods.fml.common.network.internal.FMLProxyPacket;
import cpw.mods.fml.relauncher.Side;
+import io.netty.channel.ChannelFutureListener;
+import io.netty.channel.ChannelHandlerContext;
+import net.minecraft.client.network.NetHandlerPlayClient;
+import net.minecraft.entity.player.EntityPlayerMP;
+import net.minecraft.network.NetHandlerPlayServer;
+import net.minecraft.server.MinecraftServer;
/**
* An event driven network channel, using {@link FMLNetworkEvent.CustomPacketEvent} and {@link FMLNetworkEvent.CustomNetworkEvent}
@@ -100,7 +104,14 @@
FMLNetworkEvent.CustomPacketEvent<?> event = factory.make(msg);
if (event != null)
{
+ CaptureBlock tCapture=null;
+ if(MinecraftServer.cauldronConfig.modPacketPlace.getValue()&&event instanceof ServerCustomPacketEvent){
+ EntityPlayerMP tPlayer=((NetHandlerPlayServer)((ServerCustomPacketEvent)event).handler).playerEntity;
+ tCapture=tPlayer.worldObj.mCapture.startCapture(tPlayer);
+ }
this.eventBus.post(event);
+
+ if(tCapture!=null) tCapture.endCapture();
if (event.reply != null)
{
ctx.channel().attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.REPLY);

View File

@ -0,0 +1,46 @@
--- ../src-base/minecraft/cpw/mods/fml/common/network/simpleimpl/SimpleChannelHandlerWrapper.java
+++ ../src-work/minecraft/cpw/mods/fml/common/network/simpleimpl/SimpleChannelHandlerWrapper.java
@@ -2,10 +2,9 @@
import org.apache.logging.log4j.Level;
-import net.minecraft.network.INetHandler;
-
import com.google.common.base.Preconditions;
+import cc.capture.type.CaptureBlock;
import cpw.mods.fml.common.FMLLog;
import cpw.mods.fml.common.network.FMLOutboundHandler;
import cpw.mods.fml.common.network.NetworkRegistry;
@@ -13,6 +12,10 @@
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
+import net.minecraft.entity.player.EntityPlayerMP;
+import net.minecraft.network.INetHandler;
+import net.minecraft.network.NetHandlerPlayServer;
+import net.minecraft.server.MinecraftServer;
public class SimpleChannelHandlerWrapper<REQ extends IMessage, REPLY extends IMessage> extends SimpleChannelInboundHandler<REQ> {
private final IMessageHandler<? super REQ, ? extends REPLY> messageHandler;
@@ -34,9 +37,17 @@
{
INetHandler iNetHandler = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get();
MessageContext context = new MessageContext(iNetHandler, side);
- REPLY result = messageHandler.onMessage(msg, context);
- if (result != null)
- {
+
+ CaptureBlock tCapture=null;
+ if(MinecraftServer.cauldronConfig.modPacketPlace.getValue()&&iNetHandler instanceof NetHandlerPlayServer){
+ EntityPlayerMP tPlayer=((NetHandlerPlayServer)iNetHandler).playerEntity;
+ tCapture=tPlayer.worldObj.mCapture.startCapture(tPlayer);
+ }
+
+ REPLY result=messageHandler.onMessage(msg,context);
+
+ if(tCapture!=null) tCapture.endCapture();
+ if(result!=null){
ctx.channel().attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.REPLY);
ctx.writeAndFlush(result).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE);
}

View File

@ -1,47 +1,38 @@
--- ../src-base/minecraft/net/minecraft/item/ItemStack.java --- ../src-base/minecraft/net/minecraft/item/ItemStack.java
+++ ../src-work/minecraft/net/minecraft/item/ItemStack.java +++ ../src-work/minecraft/net/minecraft/item/ItemStack.java
@@ -2,14 +2,18 @@ @@ -1,15 +1,18 @@
package net.minecraft.item;
import com.google.common.collect.HashMultimap; -import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap; -import com.google.common.collect.Multimap;
+ -import cpw.mods.fml.relauncher.Side;
+import cpw.mods.fml.common.FMLLog; -import cpw.mods.fml.relauncher.SideOnly;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
+
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Random; -import java.util.Random;
import java.util.Map.Entry; import java.util.Map.Entry;
+import java.util.Random;
+ +
+import com.google.common.collect.HashMultimap;
+import com.google.common.collect.Multimap;
+
+import cc.capture.type.CaptureBlock;
+import cpw.mods.fml.relauncher.Side;
+import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.enchantment.Enchantment; import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentDurability; import net.minecraft.enchantment.EnchantmentDurability;
@@ -35,6 +39,21 @@ @@ -21,6 +24,7 @@
import net.minecraft.world.World; import net.minecraft.entity.ai.attributes.AttributeModifier;
import net.minecraftforge.event.ForgeEventFactory; import net.minecraft.entity.item.EntityItemFrame;
import net.minecraft.entity.player.EntityPlayer;
+import org.bukkit.craftbukkit.util.CraftMagicNumbers; // CraftBukkit
+
+import net.minecraft.entity.player.EntityPlayerMP; // Spigot +import net.minecraft.entity.player.EntityPlayerMP; // Spigot
+// Cauldron start import net.minecraft.event.HoverEvent;
+import net.minecraft.block.BlockSapling; import net.minecraft.init.Items;
+import net.minecraft.block.BlockMushroom; import net.minecraft.nbt.NBTBase;
+ @@ -43,7 +47,12 @@
+import org.bukkit.Location;
+import org.bukkit.TreeType;
+import org.bukkit.block.BlockState;
+import org.bukkit.craftbukkit.block.CraftBlockState;
+import org.bukkit.entity.Player;
+import org.bukkit.event.world.StructureGrowEvent;
+// Cauldron end
+
public final class ItemStack
{
public static final DecimalFormat field_111284_a = new DecimalFormat("#.###");
@@ -43,7 +62,12 @@
private Item field_151002_e; private Item field_151002_e;
public NBTTagCompound stackTagCompound; public NBTTagCompound stackTagCompound;
int itemDamage; int itemDamage;
@ -55,7 +46,7 @@
private static final String __OBFID = "CL_00000043"; private static final String __OBFID = "CL_00000043";
private cpw.mods.fml.common.registry.RegistryDelegate<Item> delegate; private cpw.mods.fml.common.registry.RegistryDelegate<Item> delegate;
@@ -126,12 +150,14 @@ @@ -126,12 +135,14 @@
public boolean tryPlaceItemIntoWorld(EntityPlayer p_77943_1_, World p_77943_2_, int p_77943_3_, int p_77943_4_, int p_77943_5_, int p_77943_6_, float p_77943_7_, float p_77943_8_, float p_77943_9_) public boolean tryPlaceItemIntoWorld(EntityPlayer p_77943_1_, World p_77943_2_, int p_77943_3_, int p_77943_4_, int p_77943_5_, int p_77943_6_, float p_77943_7_, float p_77943_8_, float p_77943_9_)
{ {
if (!p_77943_2_.isRemote) return net.minecraftforge.common.ForgeHooks.onPlaceItemIntoWorld(this, p_77943_1_, p_77943_2_, p_77943_3_, p_77943_4_, p_77943_5_, p_77943_6_, p_77943_7_, p_77943_8_, p_77943_9_); if (!p_77943_2_.isRemote) return net.minecraftforge.common.ForgeHooks.onPlaceItemIntoWorld(this, p_77943_1_, p_77943_2_, p_77943_3_, p_77943_4_, p_77943_5_, p_77943_6_, p_77943_7_, p_77943_8_, p_77943_9_);
@ -71,7 +62,18 @@
return flag; return flag;
} }
@@ -227,8 +253,22 @@ @@ -143,7 +154,9 @@
public ItemStack useItemRightClick(World p_77957_1_, EntityPlayer p_77957_2_)
{
- return this.getItem().onItemRightClick(this, p_77957_1_, p_77957_2_);
+ CaptureBlock tCapture=p_77957_1_.mCapture.startCapture(p_77957_2_,this);
+ ItemStack tResult=this.getItem().onItemRightClick(this, p_77957_1_, p_77957_2_);
+ return !tCapture.endCapture()?this:tResult;
}
public ItemStack onFoodEaten(World p_77950_1_, EntityPlayer p_77950_2_)
@@ -227,8 +240,22 @@
return getItem().getMaxDamage(this); return getItem().getMaxDamage(this);
} }
@ -94,7 +96,7 @@
if (!this.isItemStackDamageable()) if (!this.isItemStackDamageable())
{ {
return false; return false;
@@ -250,6 +290,23 @@ @@ -250,6 +277,23 @@
p_96631_1_ -= k; p_96631_1_ -= k;
@ -118,7 +120,7 @@
if (p_96631_1_ <= 0) if (p_96631_1_ <= 0)
{ {
return false; return false;
@@ -267,7 +324,7 @@ @@ -267,7 +311,7 @@
{ {
if (this.isItemStackDamageable()) if (this.isItemStackDamageable())
{ {
@ -127,7 +129,7 @@
{ {
p_77972_2_.renderBrokenItemStack(this); p_77972_2_.renderBrokenItemStack(this);
--this.stackSize; --this.stackSize;
@@ -288,6 +345,12 @@ @@ -288,6 +332,12 @@
this.stackSize = 0; this.stackSize = 0;
} }
@ -140,7 +142,7 @@
this.itemDamage = 0; this.itemDamage = 0;
} }
} }
@@ -419,6 +482,7 @@ @@ -419,6 +469,7 @@
public void setTagCompound(NBTTagCompound p_77982_1_) public void setTagCompound(NBTTagCompound p_77982_1_)
{ {
@ -148,7 +150,7 @@
this.stackTagCompound = p_77982_1_; this.stackTagCompound = p_77982_1_;
} }
@@ -768,4 +832,12 @@ @@ -768,4 +819,12 @@
return ichatcomponent; return ichatcomponent;
} }

View File

@ -8,7 +8,7 @@
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemSword; import net.minecraft.item.ItemSword;
import net.minecraft.network.play.server.S23PacketBlockChange; import net.minecraft.network.play.server.S23PacketBlockChange;
@@ -13,13 +14,32 @@ @@ -13,13 +14,33 @@
import net.minecraft.world.WorldSettings; import net.minecraft.world.WorldSettings;
import net.minecraftforge.common.ForgeHooks; import net.minecraftforge.common.ForgeHooks;
import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.MinecraftForge;
@ -29,6 +29,7 @@
+import org.bukkit.event.block.Action; +import org.bukkit.event.block.Action;
+import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerInteractEvent;
+ +
+import cc.capture.type.CaptureBlock;
+// CraftBukkit end +// CraftBukkit end
+// Cauldron start +// Cauldron start
+import net.minecraft.inventory.ContainerPlayer; +import net.minecraft.inventory.ContainerPlayer;
@ -44,7 +45,7 @@
public class ItemInWorldManager public class ItemInWorldManager
{ {
/** Forge reach distance */ /** Forge reach distance */
@@ -135,15 +155,29 @@ @@ -135,15 +156,29 @@
public void onBlockClicked(int p_73074_1_, int p_73074_2_, int p_73074_3_, int p_73074_4_) public void onBlockClicked(int p_73074_1_, int p_73074_2_, int p_73074_3_, int p_73074_4_)
{ {
@ -77,7 +78,7 @@
if (this.isCreative()) if (this.isCreative())
{ {
if (!this.theWorld.extinguishFire((EntityPlayer)null, p_73074_1_, p_73074_2_, p_73074_3_, p_73074_4_)) if (!this.theWorld.extinguishFire((EntityPlayer)null, p_73074_1_, p_73074_2_, p_73074_3_, p_73074_4_))
@@ -157,30 +191,56 @@ @@ -157,30 +192,56 @@
float f = 1.0F; float f = 1.0F;
Block block = this.theWorld.getBlock(p_73074_1_, p_73074_2_, p_73074_3_); Block block = this.theWorld.getBlock(p_73074_1_, p_73074_2_, p_73074_3_);
@ -146,7 +147,7 @@
if (!block.isAir(theWorld, p_73074_1_, p_73074_2_, p_73074_3_) && f >= 1.0F) if (!block.isAir(theWorld, p_73074_1_, p_73074_2_, p_73074_3_) && f >= 1.0F)
{ {
this.tryHarvestBlock(p_73074_1_, p_73074_2_, p_73074_3_); this.tryHarvestBlock(p_73074_1_, p_73074_2_, p_73074_3_);
@@ -269,6 +329,12 @@ @@ -269,6 +330,12 @@
return false; return false;
} }
Block block = this.theWorld.getBlock(p_73084_1_, p_73084_2_, p_73084_3_); Block block = this.theWorld.getBlock(p_73084_1_, p_73084_2_, p_73084_3_);
@ -159,7 +160,7 @@
int l = this.theWorld.getBlockMetadata(p_73084_1_, p_73084_2_, p_73084_3_); int l = this.theWorld.getBlockMetadata(p_73084_1_, p_73084_2_, p_73084_3_);
this.theWorld.playAuxSFXAtEntity(this.thisPlayerMP, 2001, p_73084_1_, p_73084_2_, p_73084_3_, Block.getIdFromBlock(block) + (this.theWorld.getBlockMetadata(p_73084_1_, p_73084_2_, p_73084_3_) << 12)); this.theWorld.playAuxSFXAtEntity(this.thisPlayerMP, 2001, p_73084_1_, p_73084_2_, p_73084_3_, Block.getIdFromBlock(block) + (this.theWorld.getBlockMetadata(p_73084_1_, p_73084_2_, p_73084_3_) << 12));
boolean flag = false; boolean flag = false;
@@ -312,6 +378,7 @@ @@ -312,6 +379,7 @@
public boolean tryUseItem(EntityPlayer p_73085_1_, World p_73085_2_, ItemStack p_73085_3_) public boolean tryUseItem(EntityPlayer p_73085_1_, World p_73085_2_, ItemStack p_73085_3_)
{ {
int i = p_73085_3_.stackSize; int i = p_73085_3_.stackSize;
@ -167,7 +168,7 @@
int j = p_73085_3_.getItemDamage(); int j = p_73085_3_.getItemDamage();
ItemStack itemstack1 = p_73085_3_.useItemRightClick(p_73085_2_, p_73085_1_); ItemStack itemstack1 = p_73085_3_.useItemRightClick(p_73085_2_, p_73085_1_);
@@ -350,57 +417,105 @@ @@ -350,57 +418,111 @@
public boolean activateBlockOrUseItem(EntityPlayer p_73078_1_, World p_73078_2_, ItemStack p_73078_3_, int p_73078_4_, int p_73078_5_, int p_73078_6_, int p_73078_7_, float p_73078_8_, float p_73078_9_, float p_73078_10_) public boolean activateBlockOrUseItem(EntityPlayer p_73078_1_, World p_73078_2_, ItemStack p_73078_3_, int p_73078_4_, int p_73078_5_, int p_73078_6_, int p_73078_7_, float p_73078_8_, float p_73078_9_, float p_73078_10_)
{ {
@ -218,10 +219,16 @@
- result = event.useItem != Event.Result.ALLOW; - result = event.useItem != Event.Result.ALLOW;
+ Item item = (p_73078_3_ != null ? p_73078_3_.getItem() : null); + Item item = (p_73078_3_ != null ? p_73078_3_.getItem() : null);
+ // try to use an item in hand before activating a block. Used for items such as IC2's wrench. + // try to use an item in hand before activating a block. Used for items such as IC2's wrench.
+ if (item != null && item.onItemUseFirst(p_73078_3_, p_73078_1_, p_73078_2_, p_73078_4_, p_73078_5_, p_73078_6_, p_73078_7_, p_73078_8_, p_73078_9_, p_73078_10_)) + if (item != null)
+ { + {
+ CaptureBlock tCapture=p_73078_2_.mCapture.startCapture(thisPlayerMP,p_73078_3_);
+ boolean tResult=item.onItemUseFirst(p_73078_3_,p_73078_1_,p_73078_2_,p_73078_4_,p_73078_5_,p_73078_6_,p_73078_7_,p_73078_8_,p_73078_9_,p_73078_10_);
+ if(!tCapture.endCapture()) return false;
+
+ if(tResult){
+ if(p_73078_3_.stackSize<=0) ForgeEventFactory.onPlayerDestroyItem(thisPlayerMP,p_73078_3_); + if(p_73078_3_.stackSize<=0) ForgeEventFactory.onPlayerDestroyItem(thisPlayerMP,p_73078_3_);
+ return true; + return true;
+ }
+ } + }
} }
- } - }

View File

@ -59,6 +59,10 @@ public class CauldronConfig extends ConfigBase
// Plug-in options // Plug-in options
public final BoolSetting remapPluginFile = new BoolSetting(this, "plugin-settings.default.remap-plugin-file", false, "Remap the plugin file (dev)"); public final BoolSetting remapPluginFile = new BoolSetting(this, "plugin-settings.default.remap-plugin-file", false, "Remap the plugin file (dev)");
// Block Monitor
public final BoolSetting modPacketPlace = new BoolSetting(this, "block-monitor.mod-packet-place", true, "monitor block place on mod packet");
public final BoolSetting modPacketInteract = new BoolSetting(this, "block-monitor.mod-packet-interact", false, "monitor block interact on mod packet");
/* ======================================================================== */ /* ======================================================================== */
public CauldronConfig(String fileName, String commandName) public CauldronConfig(String fileName, String commandName)
@ -100,6 +104,9 @@ public class CauldronConfig extends ConfigBase
settings.put(userLogin.path, userLogin); settings.put(userLogin.path, userLogin);
settings.put(allowTntPunishment.path, allowTntPunishment); settings.put(allowTntPunishment.path, allowTntPunishment);
settings.put(maxPlayersVisible.path, maxPlayersVisible); settings.put(maxPlayersVisible.path, maxPlayersVisible);
settings.put(modPacketPlace.path,modPacketPlace);
settings.put(modPacketInteract.path,modPacketInteract);
load(); load();
} }