Exemplo n.º 1
0
 @Inject(
     method = "newExplosion",
     at = @At(value = "INVOKE", target = "Lnet/minecraft/world/Explosion;doExplosionA()V"),
     locals = LocalCapture.CAPTURE_FAILHARD,
     cancellable = true)
 public void callWorldOnExplosionEvent(
     Entity entityIn,
     double x,
     double y,
     double z,
     float strength,
     boolean isFlaming,
     boolean isSmoking,
     CallbackInfoReturnable<Explosion> cir,
     Explosion explosion) {
   final ExplosionEvent.Pre event =
       SpongeEventFactory.createExplosionEventPre(
           Sponge.getGame(),
           Cause.of(this),
           (org.spongepowered.api.world.explosion.Explosion) explosion,
           (org.spongepowered.api.world.World) this);
   if (Sponge.getGame().getEventManager().post(event)) {
     cir.setReturnValue(explosion);
   }
 }
 @Inject(
     method = "dropItem",
     at =
         @At(
             value = "FIELD",
             opcode = Opcodes.GETFIELD,
             target = "Lnet/minecraft/entity/player/EntityPlayer;posY:D"),
     cancellable = true)
 private void onDropTop(
     ItemStack itemStack,
     boolean a,
     boolean b,
     CallbackInfoReturnable<EntityItem> callbackInfoReturnable) {
   final double height = this.posY - 0.3D + (double) this.getEyeHeight();
   Transform<org.spongepowered.api.world.World> transform =
       new Transform<>(this.getWorld(), new Vector3d(this.posX, height, this.posZ));
   SpawnCause cause =
       EntitySpawnCause.builder().entity(this).type(SpawnTypes.DROPPED_ITEM).build();
   ConstructEntityEvent.Pre event =
       SpongeEventFactory.createConstructEntityEventPre(
           Cause.of(NamedCause.source(cause)), EntityTypes.ITEM, transform);
   SpongeImpl.postEvent(event);
   if (event.isCancelled()) {
     callbackInfoReturnable.setReturnValue(null);
   }
 }
 @Inject(
     method = "getDisplayName",
     at = @At("RETURN"),
     cancellable = true,
     locals = LocalCapture.CAPTURE_FAILHARD)
 public void onGetDisplayName(
     CallbackInfoReturnable<IChatComponent> ci, ChatComponentText component) {
   ci.setReturnValue(LegacyTexts.parseComponent(component, SpongeTexts.COLOR_CHAR));
 }
Exemplo n.º 4
0
 @SuppressWarnings("rawtypes")
 @Inject(
     method =
         "getCollidingBoundingBoxes(Lnet/minecraft/entity/Entity;Lnet/minecraft/util/AxisAlignedBB;)Ljava/util/List;",
     at = @At("HEAD"),
     cancellable = true)
 public void onGetCollidingBoundingBoxes(
     net.minecraft.entity.Entity entity, AxisAlignedBB axis, CallbackInfoReturnable<List> cir) {
   if (!entity.worldObj.isRemote && SpongeHooks.checkBoundingBoxSize(entity, axis)) {
     // Removing misbehaved living entities
     cir.setReturnValue(new ArrayList());
   }
 }
 @Inject(method = "onItemUse", at = @At("HEAD"), cancellable = true)
 public void onOnItemUseHead(
     EntityPlayer playerIn,
     World worldIn,
     BlockPos pos,
     EnumFacing side,
     float hitX,
     float hitY,
     float hitZ,
     CallbackInfoReturnable<Boolean> ci) {
   ci.setReturnValue(
       VanillaHooks.callPlaceBlockEventAsPlayer(
           (ItemStack) (Object) this, playerIn, worldIn, pos, side, hitX, hitY, hitZ));
 }