Search in sources :

Example 16 with BlockRailBase

use of net.minecraft.block.BlockRailBase in project NyaSamaRailway by NSDN.

the class NSPCT8W method updateRiderPosition.

@Override
public void updateRiderPosition() {
    if (this.riddenByEntity != null) {
        double x = this.posX, y = this.posY, z = this.posZ;
        int bx = MathHelper.floor_double(x);
        int by = MathHelper.floor_double(y);
        int bz = MathHelper.floor_double(z);
        Block block = worldObj.getBlock(bx, by, bz);
        int meta = worldObj.getBlockMetadata(bx, by, bz);
        double len = -1.0 + getShiftYCnt();
        Vec3 mod = Vec3.createVectorHelper(0, len, 0);
        mod.rotateAroundX(this.rotationPitch);
        mod.rotateAroundY(this.rotationYaw);
        x += mod.xCoord;
        y += mod.yCoord;
        z += mod.zCoord;
        this.riddenByEntity.setPositionAndRotation(x, y + this.getMountedYOffset(), z, this.rotationYaw, 0.0F);
        if (this.riddenByEntity instanceof Container && worldObj.isRemote) {
            Container container = (Container) this.riddenByEntity;
            container.setPositionAndRotation2(x, y + this.getMountedYOffset(), z, this.rotationYaw, 0.0F, -2);
            boolean fix = true;
            if (block instanceof BlockRailBase) {
                fix = ((BlockRailBase) block).isPowered() || meta < 6 || meta > 9;
            }
            if ((((int) container.rotationYaw) % 90) != 0 && fix) {
                container.prevRotationYaw = container.rotationYaw = (float) (MathHelper.floor_double((double) (this.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3) * 90.0F;
            }
        }
    }
}
Also used : Vec3(net.minecraft.util.Vec3) Block(net.minecraft.block.Block) BlockRailBase(net.minecraft.block.BlockRailBase)

Example 17 with BlockRailBase

use of net.minecraft.block.BlockRailBase in project NyaSamaRailway by NSDN.

the class NSPCT8C method updateRiderPosition.

@Override
public void updateRiderPosition() {
    if (this.riddenByEntity != null) {
        double x = this.posX, y = this.posY, z = this.posZ;
        int bx = MathHelper.floor_double(x);
        int by = MathHelper.floor_double(y);
        int bz = MathHelper.floor_double(z);
        Block block = worldObj.getBlock(bx, by, bz);
        int meta = worldObj.getBlockMetadata(bx, by, bz);
        double len = -1.0 + getShiftYCnt();
        Vec3 mod = Vec3.createVectorHelper(0, len, 0);
        mod.rotateAroundX(this.rotationPitch);
        mod.rotateAroundY(this.rotationYaw);
        x += mod.xCoord;
        y += mod.yCoord;
        z += mod.zCoord;
        this.riddenByEntity.setPositionAndRotation(x, y + this.getMountedYOffset(), z, this.rotationYaw, 0.0F);
        if (this.riddenByEntity instanceof Container && worldObj.isRemote) {
            Container container = (Container) this.riddenByEntity;
            container.setPositionAndRotation2(x, y + this.getMountedYOffset(), z, this.rotationYaw, 0.0F, -2);
            boolean fix = true;
            if (block instanceof BlockRailBase) {
                fix = ((BlockRailBase) block).isPowered() || meta < 6 || meta > 9;
            }
            if ((((int) container.rotationYaw) % 90) != 0 && fix) {
                container.prevRotationYaw = container.rotationYaw = (float) (MathHelper.floor_double((double) (this.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3) * 90.0F;
            }
        }
    }
}
Also used : Vec3(net.minecraft.util.Vec3) Block(net.minecraft.block.Block) BlockRailBase(net.minecraft.block.BlockRailBase)

Example 18 with BlockRailBase

use of net.minecraft.block.BlockRailBase in project malmo by Microsoft.

the class BlockDrawingHelper method setBlockState.

public void setBlockState(World w, BlockPos pos, XMLBlockState state) {
    if (!state.isValid())
        return;
    // Do some depressingly necessary specific stuff here for different block types:
    if (state.getBlock() instanceof BlockRailBase && state.variant != null) {
        // Caller has specified a variant - is it a shape variant?
        try {
            ShapeTypes shape = ShapeTypes.fromValue(state.variant.getValue());
            if (shape != null) {
                // Yes, user has requested a particular shape.
                // Minecraft won't honour this - and, worse, it may get altered by neighbouring pieces that are added later.
                // So we don't bother trying to get this right now - we add it as a state check, and set it correctly
                // after drawing has finished.
                StateCheck sc = new StateCheck();
                sc.pos = pos;
                sc.desiredState = state.state;
                sc.propertiesToCheck = new ArrayList<IProperty>();
                sc.propertiesToCheck.add(((BlockRailBase) state.getBlock()).getShapeProperty());
                this.checkList.add(sc);
            }
        } catch (IllegalArgumentException e) {
        // Wasn't a shape variation. Ignore.
        }
    }
    // Actually set the block state into the world:
    w.setBlockState(pos, state.state);
    // And now do the necessary post-placement processing:
    if (state.type == BlockType.MOB_SPAWNER) {
        TileEntity te = w.getTileEntity(pos);
        if (// Ought to be!
        te != null && te instanceof TileEntityMobSpawner) {
            // Attempt to use the variation to control what type of mob this spawns:
            try {
                EntityTypes entvar = EntityTypes.fromValue(state.variant.getValue());
                ((TileEntityMobSpawner) te).getSpawnerBaseLogic().setEntityId(new ResourceLocation(entvar.value()));
            } catch (Exception e) {
            // Do nothing - user has requested a non-entity variant.
            }
        }
    }
    if (state.type == BlockType.NOTEBLOCK) {
        TileEntity te = w.getTileEntity(pos);
        if (te != null && te instanceof TileEntityNote && state.variant != null) {
            try {
                NoteTypes note = NoteTypes.fromValue(state.variant.getValue());
                if (note != null) {
                    // User has requested a particular note.
                    ((TileEntityNote) te).note = (byte) note.ordinal();
                }
            } catch (IllegalArgumentException e) {
            // Wasn't a note variation. Ignore.
            }
        }
    }
}
Also used : EntityTypes(com.microsoft.Malmo.Schemas.EntityTypes) ShapeTypes(com.microsoft.Malmo.Schemas.ShapeTypes) NoteTypes(com.microsoft.Malmo.Schemas.NoteTypes) BlockRailBase(net.minecraft.block.BlockRailBase) TileEntity(net.minecraft.tileentity.TileEntity) IProperty(net.minecraft.block.properties.IProperty) ResourceLocation(net.minecraft.util.ResourceLocation) TileEntityNote(net.minecraft.tileentity.TileEntityNote) TileEntityMobSpawner(net.minecraft.tileentity.TileEntityMobSpawner)

Aggregations

BlockRailBase (net.minecraft.block.BlockRailBase)18 Block (net.minecraft.block.Block)11 Vec3 (net.minecraft.util.Vec3)5 SideOnly (cpw.mods.fml.relauncher.SideOnly)2 List (java.util.List)2 IBlockState (net.minecraft.block.state.IBlockState)2 Entity (net.minecraft.entity.Entity)2 EntityMinecart (net.minecraft.entity.item.EntityMinecart)2 MinecraftServer (net.minecraft.server.MinecraftServer)2 TileEntity (net.minecraft.tileentity.TileEntity)2 BlockPos (net.minecraft.util.math.BlockPos)2 WorldServer (net.minecraft.world.WorldServer)2 MinecartUpdateEvent (net.minecraftforge.event.entity.minecart.MinecartUpdateEvent)2 BlockRailReception (club.nsdn.nyasamarailway.block.rail.special.BlockRailReception)1 BlockRailReceptionAnti (club.nsdn.nyasamarailway.block.rail.special.BlockRailReceptionAnti)1 RailMonoMagnetReception (club.nsdn.nyasamarailway.tileblock.rail.mono.RailMonoMagnetReception)1 RailMonoMagnetReceptionAnti (club.nsdn.nyasamarailway.tileblock.rail.mono.RailMonoMagnetReceptionAnti)1 EntityTypes (com.microsoft.Malmo.Schemas.EntityTypes)1 NoteTypes (com.microsoft.Malmo.Schemas.NoteTypes)1 ShapeTypes (com.microsoft.Malmo.Schemas.ShapeTypes)1