Search in sources :

Example 6 with AbstractRailBlock

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;
    }
}
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 7 with AbstractRailBlock

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

AbstractRailBlock (net.minecraft.block.AbstractRailBlock)7 RailShape (net.minecraft.state.properties.RailShape)5 BlockState (net.minecraft.block.BlockState)4 BlockPos (net.minecraft.util.math.BlockPos)4 Vector3d (net.minecraft.util.math.vector.Vector3d)4 MinecoloniesMinecart (com.minecolonies.api.entity.MinecoloniesMinecart)2 PoweredRailBlock (net.minecraft.block.PoweredRailBlock)2 AbstractMinecartEntity (net.minecraft.entity.item.minecart.AbstractMinecartEntity)2 Vector3i (net.minecraft.util.math.vector.Vector3i)2 HashMap (java.util.HashMap)1 Block (net.minecraft.block.Block)1 DoorBlock (net.minecraft.block.DoorBlock)1 FenceBlock (net.minecraft.block.FenceBlock)1 WallBlock (net.minecraft.block.WallBlock)1 Material (net.minecraft.block.material.Material)1 ItemStack (net.minecraft.item.ItemStack)1 PathFinder (net.minecraft.pathfinding.PathFinder)1 PathNodeType (net.minecraft.pathfinding.PathNodeType)1 PathPoint (net.minecraft.pathfinding.PathPoint)1 WalkNodeProcessor (net.minecraft.pathfinding.WalkNodeProcessor)1