Search in sources :

Example 1 with AbstractMinecartEntity

use of net.minecraft.entity.item.minecart.AbstractMinecartEntity in project MCMOD-Industria by M-Marvin.

the class MinecartHandler method save.

@Override
public CompoundNBT save(CompoundNBT compound) {
    CompoundNBT nbt = new CompoundNBT();
    ListNBT carts = new ListNBT();
    for (Entry<AbstractMinecartEntity, Long> entry : this.boostedMinecarts.entrySet()) {
        CompoundNBT cart = new CompoundNBT();
        cart.putUUID("UUID", entry.getKey().getUUID());
        cart.putLong("BoostTime", entry.getValue());
        carts.add(cart);
    }
    nbt.put("Minecarts", carts);
    return nbt;
}
Also used : ListNBT(net.minecraft.nbt.ListNBT) CompoundNBT(net.minecraft.nbt.CompoundNBT) AbstractMinecartEntity(net.minecraft.entity.item.minecart.AbstractMinecartEntity)

Example 2 with AbstractMinecartEntity

use of net.minecraft.entity.item.minecart.AbstractMinecartEntity in project Materialis by RCXcrafter.

the class CreateWrenchingModifier method afterEntityHit.

@Override
public int afterEntityHit(IModifierToolStack tool, int level, ToolAttackContext context, float damageDealt) {
    if (context.getTarget() instanceof AbstractMinecartEntity) {
        DamageSource source;
        PlayerEntity player = context.getPlayerAttacker();
        if (player != null) {
            source = DamageSource.playerAttack(player);
        } else {
            source = DamageSource.mobAttack(context.getAttacker());
        }
        context.getTarget().hurt(source, 100);
    }
    return 0;
}
Also used : DamageSource(net.minecraft.util.DamageSource) AbstractMinecartEntity(net.minecraft.entity.item.minecart.AbstractMinecartEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Example 3 with AbstractMinecartEntity

use of net.minecraft.entity.item.minecart.AbstractMinecartEntity in project Arclight by IzzelAliz.

the class MinecartItemMixin method onItemUse.

// @formatter:on
/**
 * @author IzzelAliz
 * @reason
 */
@Overwrite
public ActionResultType onItemUse(ItemUseContext context) {
    World world = context.getWorld();
    BlockPos blockpos = context.getPos();
    BlockState blockstate = world.getBlockState(blockpos);
    if (!blockstate.isIn(BlockTags.RAILS)) {
        return ActionResultType.FAIL;
    } else {
        ItemStack itemstack = context.getItem();
        if (!world.isRemote) {
            RailShape railshape = blockstate.getBlock() instanceof AbstractRailBlock ? ((AbstractRailBlock) blockstate.getBlock()).getRailDirection(blockstate, world, blockpos, null) : RailShape.NORTH_SOUTH;
            double d0 = 0.0D;
            if (railshape.isAscending()) {
                d0 = 0.5D;
            }
            AbstractMinecartEntity abstractminecartentity = AbstractMinecartEntity.create(world, (double) blockpos.getX() + 0.5D, (double) blockpos.getY() + 0.0625D + d0, (double) blockpos.getZ() + 0.5D, this.minecartType);
            if (itemstack.hasDisplayName()) {
                abstractminecartentity.setCustomName(itemstack.getDisplayName());
            }
            if (CraftEventFactory.callEntityPlaceEvent(context, abstractminecartentity).isCancelled()) {
                return ActionResultType.FAIL;
            }
            if (!world.addEntity(abstractminecartentity)) {
                return ActionResultType.PASS;
            }
        }
        itemstack.shrink(1);
        return ActionResultType.SUCCESS;
    }
}
Also used : BlockState(net.minecraft.block.BlockState) RailShape(net.minecraft.state.properties.RailShape) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) ItemStack(net.minecraft.item.ItemStack) AbstractRailBlock(net.minecraft.block.AbstractRailBlock) AbstractMinecartEntity(net.minecraft.entity.item.minecart.AbstractMinecartEntity) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 4 with AbstractMinecartEntity

use of net.minecraft.entity.item.minecart.AbstractMinecartEntity in project Arclight by IzzelAliz.

the class AbstractMinecartEntityMixin method tick.

/**
 * @author IzzelAliz
 * @reason
 */
@Overwrite
public void tick() {
    double prevX = this.posX;
    double prevY = this.posY;
    double prevZ = this.posZ;
    float prevYaw = this.rotationYaw;
    float prevPitch = this.rotationPitch;
    if (this.getRollingAmplitude() > 0) {
        this.setRollingAmplitude(this.getRollingAmplitude() - 1);
    }
    if (this.getDamage() > 0.0f) {
        this.setDamage(this.getDamage() - 1.0f);
    }
    if (this.posY < -64.0) {
        this.outOfWorld();
    }
    if (this.world.isRemote) {
        if (this.turnProgress > 0) {
            double d0 = this.posX + (this.minecartX - this.posX) / this.turnProgress;
            double d2 = this.posY + (this.minecartY - this.posY) / this.turnProgress;
            double d3 = this.posZ + (this.minecartZ - this.posZ) / this.turnProgress;
            double d4 = MathHelper.wrapDegrees(this.minecartYaw - this.rotationYaw);
            this.rotationYaw += (float) (d4 / this.turnProgress);
            this.rotationPitch += (float) ((this.minecartPitch - this.rotationPitch) / this.turnProgress);
            --this.turnProgress;
            this.setPosition(d0, d2, d3);
            this.setRotation(this.rotationYaw, this.rotationPitch);
        } else {
            this.setPosition(this.posX, this.posY, this.posZ);
            this.setRotation(this.rotationYaw, this.rotationPitch);
        }
    } else {
        /*
            this.prevPosX = this.posX;
            this.prevPosY = this.posY;
            this.prevPosZ = this.posZ;
             */
        if (!this.hasNoGravity()) {
            this.setMotion(this.getMotion().add(0.0, -0.04, 0.0));
        }
        int i = MathHelper.floor(this.posX);
        int j = MathHelper.floor(this.posY);
        int k = MathHelper.floor(this.posZ);
        if (this.world.getBlockState(new BlockPos(i, j - 1, k)).isIn(BlockTags.RAILS)) {
            --j;
        }
        BlockPos blockposition = new BlockPos(i, j, k);
        BlockState iblockdata = this.world.getBlockState(blockposition);
        if (iblockdata.isIn(BlockTags.RAILS)) {
            this.moveAlongTrack(blockposition, iblockdata);
            if (iblockdata.getBlock() == Blocks.ACTIVATOR_RAIL) {
                this.onActivatorRailPass(i, j, k, iblockdata.get(PoweredRailBlock.POWERED));
            }
        } else {
            this.moveDerailedMinecart();
        }
        this.doBlockCollisions();
        this.rotationPitch = 0.0f;
        double d5 = this.prevPosX - this.posX;
        double d6 = this.prevPosZ - this.posZ;
        if (d5 * d5 + d6 * d6 > 0.001) {
            this.rotationYaw = (float) (MathHelper.atan2(d6, d5) * 180.0 / 3.141592653589793);
            if (this.isInReverse) {
                this.rotationYaw += 180.0f;
            }
        }
        double d7 = MathHelper.wrapDegrees(this.rotationYaw - this.prevRotationYaw);
        if (d7 < -170.0 || d7 >= 170.0) {
            this.rotationYaw += 180.0f;
            this.isInReverse = !this.isInReverse;
        }
        this.setRotation(this.rotationYaw, this.rotationPitch);
        org.bukkit.World bworld = ((WorldBridge) this.world).bridge$getWorld();
        Location from = new Location(bworld, prevX, prevY, prevZ, prevYaw, prevPitch);
        Location to = new Location(bworld, this.posX, this.posY, this.posZ, this.rotationYaw, this.rotationPitch);
        Vehicle vehicle = (Vehicle) this.getBukkitEntity();
        Bukkit.getPluginManager().callEvent(new VehicleUpdateEvent(vehicle));
        if (!from.equals(to)) {
            Bukkit.getPluginManager().callEvent(new VehicleMoveEvent(vehicle, from, to));
        }
        if (this.getMinecartType() == AbstractMinecartEntity.Type.RIDEABLE && Entity.horizontalMag(this.getMotion()) > 0.01) {
            List<Entity> list = this.world.getEntitiesInAABBexcluding((AbstractMinecartEntity) (Object) this, this.getBoundingBox().grow(0.20000000298023224, 0.0, 0.20000000298023224), EntityPredicates.pushableBy((AbstractMinecartEntity) (Object) this));
            if (!list.isEmpty()) {
                for (Entity entity : list) {
                    if (!(entity instanceof PlayerEntity) && !(entity instanceof IronGolemEntity) && !(entity instanceof AbstractMinecartEntity) && !this.isBeingRidden() && !entity.isPassenger()) {
                        VehicleEntityCollisionEvent collisionEvent = new VehicleEntityCollisionEvent(vehicle, ((EntityBridge) entity).bridge$getBukkitEntity());
                        Bukkit.getPluginManager().callEvent(collisionEvent);
                        if (!collisionEvent.isCancelled()) {
                            entity.startRiding((AbstractMinecartEntity) (Object) this);
                        }
                    } else {
                        if (!isRidingSameEntity(entity)) {
                            VehicleEntityCollisionEvent collisionEvent = new VehicleEntityCollisionEvent(vehicle, ((EntityBridge) entity).bridge$getBukkitEntity());
                            Bukkit.getPluginManager().callEvent(collisionEvent);
                            if (collisionEvent.isCancelled()) {
                                continue;
                            }
                        }
                        entity.applyEntityCollision((AbstractMinecartEntity) (Object) this);
                    }
                }
            }
        } else {
            for (Entity entity2 : this.world.getEntitiesWithinAABBExcludingEntity((AbstractMinecartEntity) (Object) this, this.getBoundingBox().grow(0.20000000298023224, 0.0, 0.20000000298023224))) {
                if (!this.isPassenger(entity2) && entity2.canBePushed() && entity2 instanceof AbstractMinecartEntity) {
                    VehicleEntityCollisionEvent collisionEvent2 = new VehicleEntityCollisionEvent(vehicle, ((EntityBridge) entity2).bridge$getBukkitEntity());
                    Bukkit.getPluginManager().callEvent(collisionEvent2);
                    if (collisionEvent2.isCancelled()) {
                        continue;
                    }
                    entity2.applyEntityCollision((AbstractMinecartEntity) (Object) this);
                }
            }
        }
        this.handleWaterMovement();
    }
}
Also used : IronGolemEntity(net.minecraft.entity.passive.IronGolemEntity) Entity(net.minecraft.entity.Entity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) AbstractMinecartEntity(net.minecraft.entity.item.minecart.AbstractMinecartEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) Vehicle(org.bukkit.entity.Vehicle) VehicleUpdateEvent(org.bukkit.event.vehicle.VehicleUpdateEvent) BlockState(net.minecraft.block.BlockState) VehicleEntityCollisionEvent(org.bukkit.event.vehicle.VehicleEntityCollisionEvent) WorldBridge(io.izzel.arclight.common.bridge.world.WorldBridge) VehicleMoveEvent(org.bukkit.event.vehicle.VehicleMoveEvent) IronGolemEntity(net.minecraft.entity.passive.IronGolemEntity) BlockPos(net.minecraft.util.math.BlockPos) AbstractMinecartEntity(net.minecraft.entity.item.minecart.AbstractMinecartEntity) Location(org.bukkit.Location) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 5 with AbstractMinecartEntity

use of net.minecraft.entity.item.minecart.AbstractMinecartEntity in project MCMOD-Industria by M-Marvin.

the class MinecartHandler method updateMinecarts.

@SuppressWarnings("unchecked")
public void updateMinecarts() {
    for (Entry<AbstractMinecartEntity, Long> entry : ((HashMap<AbstractMinecartEntity, Long>) this.boostedMinecarts.clone()).entrySet()) {
        long tagAge = world.getGameTime() - entry.getValue();
        if (tagAge > 350) {
            this.stopBoosted(entry.getKey());
        }
        Block railBlock1 = world.getBlockState(entry.getKey().blockPosition()).getBlock();
        Block railBlock2 = world.getBlockState(entry.getKey().blockPosition().below()).getBlock();
        if (railBlock1 != ModItems.steel_rail && railBlock1 != ModItems.inductive_rail && railBlock2 != ModItems.steel_rail && railBlock2 != ModItems.inductive_rail && (railBlock1 instanceof AbstractRailBlock || railBlock2 instanceof AbstractRailBlock)) {
            this.stopBoosted(entry.getKey());
        }
    }
}
Also used : HashMap(java.util.HashMap) AbstractRailBlock(net.minecraft.block.AbstractRailBlock) Block(net.minecraft.block.Block) AbstractRailBlock(net.minecraft.block.AbstractRailBlock) AbstractMinecartEntity(net.minecraft.entity.item.minecart.AbstractMinecartEntity)

Aggregations

AbstractMinecartEntity (net.minecraft.entity.item.minecart.AbstractMinecartEntity)5 AbstractRailBlock (net.minecraft.block.AbstractRailBlock)2 BlockState (net.minecraft.block.BlockState)2 PlayerEntity (net.minecraft.entity.player.PlayerEntity)2 BlockPos (net.minecraft.util.math.BlockPos)2 Overwrite (org.spongepowered.asm.mixin.Overwrite)2 WorldBridge (io.izzel.arclight.common.bridge.world.WorldBridge)1 HashMap (java.util.HashMap)1 Block (net.minecraft.block.Block)1 Entity (net.minecraft.entity.Entity)1 IronGolemEntity (net.minecraft.entity.passive.IronGolemEntity)1 ItemStack (net.minecraft.item.ItemStack)1 CompoundNBT (net.minecraft.nbt.CompoundNBT)1 ListNBT (net.minecraft.nbt.ListNBT)1 RailShape (net.minecraft.state.properties.RailShape)1 DamageSource (net.minecraft.util.DamageSource)1 World (net.minecraft.world.World)1 Location (org.bukkit.Location)1 Vehicle (org.bukkit.entity.Vehicle)1 VehicleEntityCollisionEvent (org.bukkit.event.vehicle.VehicleEntityCollisionEvent)1