use of net.minecraft.block.AbstractRailBlock 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.block.AbstractRailBlock 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