Search in sources :

Example 1 with ProxyBlockSource

use of net.minecraft.dispenser.ProxyBlockSource in project Arclight by IzzelAliz.

the class DropperBlockMixin method dispense.

/**
 * @author IzzelAliz
 * @reason
 */
@Overwrite
public void dispense(World worldIn, BlockPos pos) {
    ProxyBlockSource proxyblocksource = new ProxyBlockSource(worldIn, pos);
    DispenserTileEntity dispensertileentity = proxyblocksource.getBlockTileEntity();
    int i = dispensertileentity.getDispenseSlot();
    if (i < 0) {
        worldIn.playEvent(1001, pos, 0);
    } else {
        ItemStack itemstack = dispensertileentity.getStackInSlot(i);
        if (!itemstack.isEmpty() && net.minecraftforge.items.VanillaInventoryCodeHooks.dropperInsertHook(worldIn, pos, dispensertileentity, i, itemstack)) {
            Direction direction = worldIn.getBlockState(pos).get(DispenserBlock.FACING);
            IInventory iinventory = HopperTileEntity.getInventoryAtPosition(worldIn, pos.offset(direction));
            ItemStack itemstack1;
            if (iinventory == null) {
                itemstack1 = DISPENSE_BEHAVIOR.dispense(proxyblocksource, itemstack);
            } else {
                ItemStack split = itemstack.copy().split(1);
                CraftItemStack craftItemStack = CraftItemStack.asCraftMirror(split);
                Inventory destinationInventory;
                // Have to special case large chests as they work oddly
                if (iinventory instanceof DoubleSidedInventory) {
                    destinationInventory = new CraftInventoryDoubleChest((DoubleSidedInventory) iinventory);
                } else {
                    destinationInventory = ((IInventoryBridge) iinventory).getOwner().getInventory();
                }
                InventoryMoveItemEvent event = new InventoryMoveItemEvent(((IInventoryBridge) dispensertileentity).getOwner().getInventory(), craftItemStack, destinationInventory, true);
                Bukkit.getPluginManager().callEvent(event);
                if (event.isCancelled()) {
                    return;
                }
                itemstack1 = HopperTileEntity.putStackInInventoryAllSlots(dispensertileentity, iinventory, CraftItemStack.asNMSCopy(event.getItem()), direction.getOpposite());
                if (event.getItem().equals(craftItemStack) && itemstack1.isEmpty()) {
                    itemstack1 = itemstack.copy();
                    itemstack1.shrink(1);
                } else {
                    itemstack1 = itemstack.copy();
                }
            }
            dispensertileentity.setInventorySlotContents(i, itemstack1);
        }
    }
}
Also used : IInventory(net.minecraft.inventory.IInventory) CraftItemStack(org.bukkit.craftbukkit.v.inventory.CraftItemStack) DoubleSidedInventory(net.minecraft.inventory.DoubleSidedInventory) ProxyBlockSource(net.minecraft.dispenser.ProxyBlockSource) IInventoryBridge(io.izzel.arclight.common.bridge.inventory.IInventoryBridge) DispenserTileEntity(net.minecraft.tileentity.DispenserTileEntity) CraftItemStack(org.bukkit.craftbukkit.v.inventory.CraftItemStack) ItemStack(net.minecraft.item.ItemStack) CraftInventoryDoubleChest(org.bukkit.craftbukkit.v.inventory.CraftInventoryDoubleChest) InventoryMoveItemEvent(org.bukkit.event.inventory.InventoryMoveItemEvent) Direction(net.minecraft.util.Direction) DoubleSidedInventory(net.minecraft.inventory.DoubleSidedInventory) Inventory(org.bukkit.inventory.Inventory) IInventory(net.minecraft.inventory.IInventory) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 2 with ProxyBlockSource

use of net.minecraft.dispenser.ProxyBlockSource in project Magma-1.16.x by magmafoundation.

the class CraftBlockProjectileSource method launchProjectile.

@Override
public <T extends Projectile> T launchProjectile(Class<? extends T> projectile, Vector velocity) {
    Validate.isTrue(getBlock().getType() == Material.DISPENSER, "Block is no longer dispenser");
    // Copied from DispenserBlock.dispense()
    ProxyBlockSource isourceblock = new ProxyBlockSource(dispenserBlock.getLevel().getMinecraftWorld(), dispenserBlock.getBlockPos());
    // Copied from DispenseTaskProjectile
    IPosition iposition = DispenserBlock.getDispensePosition(isourceblock);
    Direction enumdirection = (Direction) isourceblock.getBlockState().getValue(DispenserBlock.FACING);
    net.minecraft.world.World world = dispenserBlock.getLevel();
    net.minecraft.entity.Entity launch = null;
    if (Snowball.class.isAssignableFrom(projectile)) {
        launch = new SnowballEntity(world, iposition.x(), iposition.y(), iposition.z());
    } else if (Egg.class.isAssignableFrom(projectile)) {
        launch = new EggEntity(world, iposition.x(), iposition.y(), iposition.z());
    } else if (EnderPearl.class.isAssignableFrom(projectile)) {
        launch = new EnderPearlEntity(world, null);
        launch.setPos(iposition.x(), iposition.y(), iposition.z());
    } else if (ThrownExpBottle.class.isAssignableFrom(projectile)) {
        launch = new ExperienceBottleEntity(world, iposition.x(), iposition.y(), iposition.z());
    } else if (ThrownPotion.class.isAssignableFrom(projectile)) {
        if (LingeringPotion.class.isAssignableFrom(projectile)) {
            launch = new PotionEntity(world, iposition.x(), iposition.y(), iposition.z());
            ((PotionEntity) launch).setItem(CraftItemStack.asNMSCopy(new ItemStack(org.bukkit.Material.LINGERING_POTION, 1)));
        } else {
            launch = new PotionEntity(world, iposition.x(), iposition.y(), iposition.z());
            ((PotionEntity) launch).setItem(CraftItemStack.asNMSCopy(new ItemStack(org.bukkit.Material.SPLASH_POTION, 1)));
        }
    } else if (AbstractArrow.class.isAssignableFrom(projectile)) {
        if (TippedArrow.class.isAssignableFrom(projectile)) {
            launch = new ArrowEntity(world, iposition.x(), iposition.y(), iposition.z());
            ((ArrowEntity) launch).setType(CraftPotionUtil.fromBukkit(new PotionData(PotionType.WATER, false, false)));
        } else if (SpectralArrow.class.isAssignableFrom(projectile)) {
            launch = new SpectralArrowEntity(world, iposition.x(), iposition.y(), iposition.z());
        } else {
            launch = new ArrowEntity(world, iposition.x(), iposition.y(), iposition.z());
        }
        ((AbstractArrowEntity) launch).pickup = AbstractArrowEntity.PickupStatus.ALLOWED;
        ((AbstractArrowEntity) launch).projectileSource = this;
    } else if (Fireball.class.isAssignableFrom(projectile)) {
        double d0 = iposition.x() + (double) ((float) enumdirection.getStepX() * 0.3F);
        double d1 = iposition.y() + (double) ((float) enumdirection.getStepY() * 0.3F);
        double d2 = iposition.z() + (double) ((float) enumdirection.getStepZ() * 0.3F);
        Random random = world.random;
        double d3 = random.nextGaussian() * 0.05D + (double) enumdirection.getStepX();
        double d4 = random.nextGaussian() * 0.05D + (double) enumdirection.getStepY();
        double d5 = random.nextGaussian() * 0.05D + (double) enumdirection.getStepZ();
        if (SmallFireball.class.isAssignableFrom(projectile)) {
            launch = new SmallFireballEntity(world, null, d0, d1, d2);
        } else if (WitherSkull.class.isAssignableFrom(projectile)) {
            launch = EntityType.WITHER_SKULL.create(world);
            launch.setPos(d0, d1, d2);
            double d6 = (double) MathHelper.sqrt(d3 * d3 + d4 * d4 + d5 * d5);
            ((DamagingProjectileEntity) launch).xPower = d3 / d6 * 0.1D;
            ((DamagingProjectileEntity) launch).yPower = d4 / d6 * 0.1D;
            ((DamagingProjectileEntity) launch).zPower = d5 / d6 * 0.1D;
        } else {
            launch = EntityType.FIREBALL.create(world);
            launch.setPos(d0, d1, d2);
            double d6 = (double) MathHelper.sqrt(d3 * d3 + d4 * d4 + d5 * d5);
            ((DamagingProjectileEntity) launch).xPower = d3 / d6 * 0.1D;
            ((DamagingProjectileEntity) launch).yPower = d4 / d6 * 0.1D;
            ((DamagingProjectileEntity) launch).zPower = d5 / d6 * 0.1D;
        }
        ((DamagingProjectileEntity) launch).projectileSource = this;
    }
    Validate.notNull(launch, "Projectile not supported");
    if (launch instanceof ProjectileEntity) {
        if (launch instanceof ThrowableEntity) {
            ((ThrowableEntity) launch).projectileSource = this;
        }
        // Values from DispenseTaskProjectile
        float a = 6.0F;
        float b = 1.1F;
        if (launch instanceof PotionEntity || launch instanceof ThrownExpBottle) {
            // Values from respective DispenseTask classes
            a *= 0.5F;
            b *= 1.25F;
        }
        // Copied from DispenseTaskProjectile
        ((ProjectileEntity) launch).shoot((double) enumdirection.getStepX(), (double) ((float) enumdirection.getStepY() + 0.1F), (double) enumdirection.getStepZ(), b, a);
    }
    if (velocity != null) {
        ((T) launch.getBukkitEntity()).setVelocity(velocity);
    }
    world.addFreshEntity(launch);
    return (T) launch.getBukkitEntity();
}
Also used : SpectralArrowEntity(net.minecraft.entity.projectile.SpectralArrowEntity) ArrowEntity(net.minecraft.entity.projectile.ArrowEntity) AbstractArrowEntity(net.minecraft.entity.projectile.AbstractArrowEntity) SmallFireballEntity(net.minecraft.entity.projectile.SmallFireballEntity) EggEntity(net.minecraft.entity.projectile.EggEntity) SpectralArrowEntity(net.minecraft.entity.projectile.SpectralArrowEntity) ThrowableEntity(net.minecraft.entity.projectile.ThrowableEntity) Direction(net.minecraft.util.Direction) EnderPearlEntity(net.minecraft.entity.item.EnderPearlEntity) PotionData(org.bukkit.potion.PotionData) TippedArrow(org.bukkit.entity.TippedArrow) Random(java.util.Random) DamagingProjectileEntity(net.minecraft.entity.projectile.DamagingProjectileEntity) SnowballEntity(net.minecraft.entity.projectile.SnowballEntity) DamagingProjectileEntity(net.minecraft.entity.projectile.DamagingProjectileEntity) ProjectileEntity(net.minecraft.entity.projectile.ProjectileEntity) IPosition(net.minecraft.dispenser.IPosition) ProxyBlockSource(net.minecraft.dispenser.ProxyBlockSource) Egg(org.bukkit.entity.Egg) PotionEntity(net.minecraft.entity.projectile.PotionEntity) ThrownExpBottle(org.bukkit.entity.ThrownExpBottle) ExperienceBottleEntity(net.minecraft.entity.item.ExperienceBottleEntity) CraftItemStack(org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack) WitherSkull(org.bukkit.entity.WitherSkull) AbstractArrow(org.bukkit.entity.AbstractArrow) AbstractArrowEntity(net.minecraft.entity.projectile.AbstractArrowEntity)

Example 3 with ProxyBlockSource

use of net.minecraft.dispenser.ProxyBlockSource in project LoliServer by Loli-Server.

the class CraftBlockProjectileSource method launchProjectile.

@Override
public <T extends Projectile> T launchProjectile(Class<? extends T> projectile, Vector velocity) {
    Validate.isTrue(getBlock().getType() == Material.DISPENSER, "Block is no longer dispenser");
    // Copied from DispenserBlock.dispense()
    ProxyBlockSource isourceblock = new ProxyBlockSource((ServerWorld) dispenserBlock.getLevel(), dispenserBlock.getBlockPos());
    // Copied from DispenseTaskProjectile
    IPosition iposition = DispenserBlock.getDispensePosition(isourceblock);
    Direction enumdirection = (Direction) isourceblock.getBlockState().getValue(DispenserBlock.FACING);
    net.minecraft.world.World world = dispenserBlock.getLevel();
    net.minecraft.entity.Entity launch = null;
    if (Snowball.class.isAssignableFrom(projectile)) {
        launch = new SnowballEntity(world, iposition.x(), iposition.y(), iposition.z());
    } else if (Egg.class.isAssignableFrom(projectile)) {
        launch = new EggEntity(world, iposition.x(), iposition.y(), iposition.z());
    } else if (EnderPearl.class.isAssignableFrom(projectile)) {
        launch = new EnderPearlEntity(world, null);
        launch.setPos(iposition.x(), iposition.y(), iposition.z());
    } else if (ThrownExpBottle.class.isAssignableFrom(projectile)) {
        launch = new ExperienceBottleEntity(world, iposition.x(), iposition.y(), iposition.z());
    } else if (ThrownPotion.class.isAssignableFrom(projectile)) {
        if (LingeringPotion.class.isAssignableFrom(projectile)) {
            launch = new PotionEntity(world, iposition.x(), iposition.y(), iposition.z());
            ((PotionEntity) launch).setItem(CraftItemStack.asNMSCopy(new ItemStack(org.bukkit.Material.LINGERING_POTION, 1)));
        } else {
            launch = new PotionEntity(world, iposition.x(), iposition.y(), iposition.z());
            ((PotionEntity) launch).setItem(CraftItemStack.asNMSCopy(new ItemStack(org.bukkit.Material.SPLASH_POTION, 1)));
        }
    } else if (AbstractArrow.class.isAssignableFrom(projectile)) {
        if (TippedArrow.class.isAssignableFrom(projectile)) {
            launch = new ArrowEntity(world, iposition.x(), iposition.y(), iposition.z());
            ((ArrowEntity) launch).setType(CraftPotionUtil.fromBukkit(new PotionData(PotionType.WATER, false, false)));
        } else if (SpectralArrow.class.isAssignableFrom(projectile)) {
            launch = new SpectralArrowEntity(world, iposition.x(), iposition.y(), iposition.z());
        } else {
            launch = new ArrowEntity(world, iposition.x(), iposition.y(), iposition.z());
        }
        ((AbstractArrowEntity) launch).pickup = AbstractArrowEntity.PickupStatus.ALLOWED;
        ((AbstractArrowEntity) launch).projectileSource = this;
    } else if (Fireball.class.isAssignableFrom(projectile)) {
        double d0 = iposition.x() + (double) ((float) enumdirection.getStepX() * 0.3F);
        double d1 = iposition.y() + (double) ((float) enumdirection.getStepY() * 0.3F);
        double d2 = iposition.z() + (double) ((float) enumdirection.getStepZ() * 0.3F);
        Random random = world.random;
        double d3 = random.nextGaussian() * 0.05D + (double) enumdirection.getStepX();
        double d4 = random.nextGaussian() * 0.05D + (double) enumdirection.getStepY();
        double d5 = random.nextGaussian() * 0.05D + (double) enumdirection.getStepZ();
        if (SmallFireball.class.isAssignableFrom(projectile)) {
            launch = new SmallFireballEntity(world, null, d0, d1, d2);
        } else if (WitherSkull.class.isAssignableFrom(projectile)) {
            launch = EntityType.WITHER_SKULL.create(world);
            launch.setPos(d0, d1, d2);
            double d6 = (double) MathHelper.sqrt(d3 * d3 + d4 * d4 + d5 * d5);
            ((DamagingProjectileEntity) launch).xPower = d3 / d6 * 0.1D;
            ((DamagingProjectileEntity) launch).yPower = d4 / d6 * 0.1D;
            ((DamagingProjectileEntity) launch).zPower = d5 / d6 * 0.1D;
        } else {
            launch = EntityType.FIREBALL.create(world);
            launch.setPos(d0, d1, d2);
            double d6 = (double) MathHelper.sqrt(d3 * d3 + d4 * d4 + d5 * d5);
            ((DamagingProjectileEntity) launch).xPower = d3 / d6 * 0.1D;
            ((DamagingProjectileEntity) launch).yPower = d4 / d6 * 0.1D;
            ((DamagingProjectileEntity) launch).zPower = d5 / d6 * 0.1D;
        }
        ((DamagingProjectileEntity) launch).projectileSource = this;
    }
    Validate.notNull(launch, "Projectile not supported");
    if (launch instanceof ProjectileEntity) {
        if (launch instanceof ThrowableEntity) {
            ((ThrowableEntity) launch).projectileSource = this;
        }
        // Values from DispenseTaskProjectile
        float a = 6.0F;
        float b = 1.1F;
        if (launch instanceof PotionEntity || launch instanceof ThrownExpBottle) {
            // Values from respective DispenseTask classes
            a *= 0.5F;
            b *= 1.25F;
        }
        // Copied from DispenseTaskProjectile
        ((ProjectileEntity) launch).shoot((double) enumdirection.getStepX(), (double) ((float) enumdirection.getStepY() + 0.1F), (double) enumdirection.getStepZ(), b, a);
    }
    if (velocity != null) {
        ((T) launch.getBukkitEntity()).setVelocity(velocity);
    }
    world.addFreshEntity(launch);
    return (T) launch.getBukkitEntity();
}
Also used : SpectralArrowEntity(net.minecraft.entity.projectile.SpectralArrowEntity) ArrowEntity(net.minecraft.entity.projectile.ArrowEntity) AbstractArrowEntity(net.minecraft.entity.projectile.AbstractArrowEntity) SmallFireballEntity(net.minecraft.entity.projectile.SmallFireballEntity) EggEntity(net.minecraft.entity.projectile.EggEntity) SpectralArrowEntity(net.minecraft.entity.projectile.SpectralArrowEntity) ThrowableEntity(net.minecraft.entity.projectile.ThrowableEntity) Direction(net.minecraft.util.Direction) EnderPearlEntity(net.minecraft.entity.item.EnderPearlEntity) PotionData(org.bukkit.potion.PotionData) TippedArrow(org.bukkit.entity.TippedArrow) Random(java.util.Random) DamagingProjectileEntity(net.minecraft.entity.projectile.DamagingProjectileEntity) SnowballEntity(net.minecraft.entity.projectile.SnowballEntity) DamagingProjectileEntity(net.minecraft.entity.projectile.DamagingProjectileEntity) ProjectileEntity(net.minecraft.entity.projectile.ProjectileEntity) IPosition(net.minecraft.dispenser.IPosition) ProxyBlockSource(net.minecraft.dispenser.ProxyBlockSource) Egg(org.bukkit.entity.Egg) PotionEntity(net.minecraft.entity.projectile.PotionEntity) ThrownExpBottle(org.bukkit.entity.ThrownExpBottle) ExperienceBottleEntity(net.minecraft.entity.item.ExperienceBottleEntity) CraftItemStack(org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack) WitherSkull(org.bukkit.entity.WitherSkull) AbstractArrow(org.bukkit.entity.AbstractArrow) AbstractArrowEntity(net.minecraft.entity.projectile.AbstractArrowEntity)

Aggregations

ProxyBlockSource (net.minecraft.dispenser.ProxyBlockSource)3 Direction (net.minecraft.util.Direction)3 Random (java.util.Random)2 IPosition (net.minecraft.dispenser.IPosition)2 EnderPearlEntity (net.minecraft.entity.item.EnderPearlEntity)2 ExperienceBottleEntity (net.minecraft.entity.item.ExperienceBottleEntity)2 AbstractArrowEntity (net.minecraft.entity.projectile.AbstractArrowEntity)2 ArrowEntity (net.minecraft.entity.projectile.ArrowEntity)2 DamagingProjectileEntity (net.minecraft.entity.projectile.DamagingProjectileEntity)2 EggEntity (net.minecraft.entity.projectile.EggEntity)2 PotionEntity (net.minecraft.entity.projectile.PotionEntity)2 ProjectileEntity (net.minecraft.entity.projectile.ProjectileEntity)2 SmallFireballEntity (net.minecraft.entity.projectile.SmallFireballEntity)2 SnowballEntity (net.minecraft.entity.projectile.SnowballEntity)2 SpectralArrowEntity (net.minecraft.entity.projectile.SpectralArrowEntity)2 ThrowableEntity (net.minecraft.entity.projectile.ThrowableEntity)2 CraftItemStack (org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack)2 AbstractArrow (org.bukkit.entity.AbstractArrow)2 Egg (org.bukkit.entity.Egg)2 ThrownExpBottle (org.bukkit.entity.ThrownExpBottle)2