当前位置: 首页>>代码示例>>Java>>正文


Java MinecartUpdateEvent类代码示例

本文整理汇总了Java中net.minecraftforge.event.entity.minecart.MinecartUpdateEvent的典型用法代码示例。如果您正苦于以下问题:Java MinecartUpdateEvent类的具体用法?Java MinecartUpdateEvent怎么用?Java MinecartUpdateEvent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


MinecartUpdateEvent类属于net.minecraftforge.event.entity.minecart包,在下文中一共展示了MinecartUpdateEvent类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onCartUpdate

import net.minecraftforge.event.entity.minecart.MinecartUpdateEvent; //导入依赖的package包/类
public void onCartUpdate(MinecartUpdateEvent event){
    EntityMinecart cart = event.getMinecart();
    if(!cart.world.isRemote) {
        if(isMotorized()) {
            boolean shouldRun = true;
            EnumFacing cartDir = cart.getAdjustedHorizontalFacing();
            if(new Vec3d(cart.motionX, cart.motionY, cart.motionZ).lengthVector() < 0.05) {
                shouldRun = false;
                if(hopperTimer > 0) {
                    hopperTimer--;
                }
                if(hopperTimer == 0) {
                    hopperTimer = extractFuelFromHopper(cart, event.getPos()) ? 8 : 40;
                }
            } else {
                hopperTimer = 0;
                RailWrapper rail = RailCacheManager.getInstance(cart.world).getRail(cart.world, event.getPos());

                if(rail == null) {
                    shouldRun = false;
                } else {
                    TileEntitySignalBase signal = TileEntitySignalBase.getNeighborSignal(rail, cartDir.getOpposite());
                    shouldRun = signal == null || signal.getLampStatus() != EnumLampStatus.RED;
                    if(!shouldRun) {
                        cart.motionX = 0;
                        cart.motionZ = 0;
                    }
                }
            }

            if(shouldRun && useFuel(cart)) {
                if(!motorActive) NetworkHandler.sendToAllAround(new PacketUpdateMinecartEngineState(cart, true), new NetworkRegistry.TargetPoint(cart.world.provider.getDimension(), cart.getPositionVector().x, cart.getPositionVector().y, cart.getPositionVector().z, 64));
                motorActive = true;

                double acceleration = 0.03D;
                cart.motionX += cartDir.getFrontOffsetX() * acceleration;
                cart.motionZ += cartDir.getFrontOffsetZ() * acceleration;
                cart.motionX = MathHelper.clamp(cart.motionX, -cart.getMaxCartSpeedOnRail(), cart.getMaxCartSpeedOnRail());
                cart.motionZ = MathHelper.clamp(cart.motionZ, -cart.getMaxCartSpeedOnRail(), cart.getMaxCartSpeedOnRail());
            } else {
                if(motorActive) NetworkHandler.sendToAllAround(new PacketUpdateMinecartEngineState(cart, true), new NetworkRegistry.TargetPoint(cart.world.provider.getDimension(), cart.getPositionVector().x, cart.getPositionVector().y, cart.getPositionVector().z, 64));
                motorActive = false;
            }
        }
    } else {
        if(motorActive) {
            cart.world.spawnParticle(EnumParticleTypes.SMOKE_LARGE, cart.getPositionVector().x, cart.getPositionVector().y, cart.getPositionVector().z, 0, 0, 0);
        }
    }
}
 
开发者ID:MineMaarten,项目名称:Signals,代码行数:51,代码来源:CapabilityMinecartDestination.java

示例2: onMinecartUpdate

import net.minecraftforge.event.entity.minecart.MinecartUpdateEvent; //导入依赖的package包/类
@SubscribeEvent
public void onMinecartUpdate(MinecartUpdateEvent event){
    EntityMinecart cart = event.getMinecart();
    CapabilityMinecartDestination cap = cart.getCapability(CapabilityMinecartDestination.INSTANCE, null);
    if(cap != null) cap.onCartUpdate(event);
}
 
开发者ID:MineMaarten,项目名称:Signals,代码行数:7,代码来源:EventHandler.java


注:本文中的net.minecraftforge.event.entity.minecart.MinecartUpdateEvent类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。