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;
}
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;
}
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;
}
}
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();
}
}
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());
}
}
}
Aggregations