Java Code Examples for net.minecraft.block.state.IBlockState#equals()

The following examples show how to use net.minecraft.block.state.IBlockState#equals() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BucketHandler.java    From AdvancedRocketry with MIT License 6 votes vote down vote up
@SubscribeEvent
public void onBucketFill(FillBucketEvent event) {
	if(event.getTarget() == null || Type.BLOCK != event.getTarget().typeOfHit)
		return;
	IBlockState state =  event.getWorld().getBlockState(new BlockPos(event.getTarget().getBlockPos()));
	Block block = state.getBlock();
	Item bucket = bucketMap.get(block);
	
	if(bucket != null && state.equals(block.getDefaultState())) {
		event.getWorld().setBlockToAir(new BlockPos(event.getTarget().getBlockPos()));
		
		event.setFilledBucket(new ItemStack(bucket));
		
		bucket.hasContainerItem(event.getFilledBucket());
		
		event.setResult(Result.ALLOW);
	}
}
 
Example 2
Source File: BlockRoutiduct.java    From CommunityMod with GNU Lesser General Public License v2.1 5 votes vote down vote up
public boolean isSideCompatible(IBlockState state, IBlockState directionState) {
	IBlockState neutralState = getDefaultState().withProperty(AXIS, EnumAxis.NEUTRAL);
	System.out.println(directionState);
	if ((state.equals(directionState) || state.equals(neutralState) || state.getBlock() instanceof BlockRelay && ((BlockRelay) state.getBlock()).getProtocol() == protocol || state.getBlock() instanceof BlockPackager && ((BlockPackager) state.getBlock()).getProtocol() == protocol)) {
		return true;
	}
	return false;
}
 
Example 3
Source File: PhysicsCalculations.java    From Valkyrien-Skies with Apache License 2.0 5 votes vote down vote up
public void onSetBlockState(IBlockState oldState, IBlockState newState, BlockPos pos) {
    World worldObj = getParent().world();
    if (!newState.equals(oldState)) {
        if (BlockPhysicsDetails.isBlockProvidingForce(newState, pos, worldObj)) {
            activeForcePositions.add(pos);
        } else {
            activeForcePositions.remove(pos);
        }

        double oldMass = BlockPhysicsDetails.getMassFromState(oldState, pos, worldObj);
        double newMass = BlockPhysicsDetails.getMassFromState(newState, pos, worldObj);
        double deltaMass = newMass - oldMass;
        // Don't change anything if the mass is the same
        if (Math.abs(deltaMass) > EPSILON) {
            double x = pos.getX() + .5D;
            double y = pos.getY() + .5D;
            double z = pos.getZ() + .5D;

            deltaMass /= 9D;
            addMassAt(x, y, z, deltaMass);
            addMassAt(x + INERTIA_OFFSET, y + INERTIA_OFFSET, z + INERTIA_OFFSET, deltaMass);
            addMassAt(x + INERTIA_OFFSET, y + INERTIA_OFFSET, z - INERTIA_OFFSET, deltaMass);
            addMassAt(x + INERTIA_OFFSET, y - INERTIA_OFFSET, z + INERTIA_OFFSET, deltaMass);
            addMassAt(x + INERTIA_OFFSET, y - INERTIA_OFFSET, z - INERTIA_OFFSET, deltaMass);
            addMassAt(x - INERTIA_OFFSET, y + INERTIA_OFFSET, z + INERTIA_OFFSET, deltaMass);
            addMassAt(x - INERTIA_OFFSET, y + INERTIA_OFFSET, z - INERTIA_OFFSET, deltaMass);
            addMassAt(x - INERTIA_OFFSET, y - INERTIA_OFFSET, z + INERTIA_OFFSET, deltaMass);
            addMassAt(x - INERTIA_OFFSET, y - INERTIA_OFFSET, z - INERTIA_OFFSET, deltaMass);
        }
    }
}
 
Example 4
Source File: BlockCrystal.java    From AdvancedRocketry with MIT License 5 votes vote down vote up
@Override
@SideOnly(Side.CLIENT)
public boolean shouldSideBeRendered(IBlockState blockState,
		IBlockAccess world, BlockPos pos, EnumFacing side) {
      
       EnumFacing dir = side;//side.getOpposite();
       IBlockState blockState2 = world.getBlockState(pos.offset(dir));
      
       return  blockState.equals(blockState2) ? false : super.shouldSideBeRendered(blockState, world, pos, side);
  
}
 
Example 5
Source File: BlockUnpackager.java    From CommunityMod with GNU Lesser General Public License v2.1 4 votes vote down vote up
public boolean isEqual(IBlockState state, EnumFacing facingValue, boolean connectionValue) {
	if (state.equals(getDefaultState().withProperty(FACING, facingValue).withProperty(CONNECTION, connectionValue))) {
		return true;
	}
	return false;
}
 
Example 6
Source File: BlockPackager.java    From CommunityMod with GNU Lesser General Public License v2.1 4 votes vote down vote up
public boolean isEqual(IBlockState state, EnumFacing facingValue) {
	if (state.equals(getDefaultState().withProperty(FACING, facingValue))) {
		return true;
	}
	return false;
}
 
Example 7
Source File: GTIBlockFilters.java    From GT-Classic with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public boolean isValidBlock(IBlockState state) {
	return state.equals(this.block.getDefaultState());
}
 
Example 8
Source File: GTIBlockFilters.java    From GT-Classic with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public boolean isValidBlock(IBlockState state) {
	return state.equals(GTBlocks.casingLapotron.getDefaultState());
}
 
Example 9
Source File: BuildBattleDecoratorImplementation.java    From malmo with MIT License 4 votes vote down vote up
private void updateAndScorePlayerVolume(World w, boolean updateReward)
{
    int wrongBlocks = 0;
    int rightBlocks = 0;
    int totalMatchingBlocks = 0;
    BlockDrawingHelper drawContext = new BlockDrawingHelper();
    drawContext.beginDrawing(w);

    for (int x = this.sourceBounds.getMin().getX(); x <= this.sourceBounds.getMax().getX(); x++)
    {
        for (int y = this.sourceBounds.getMin().getY(); y <= this.sourceBounds.getMax().getY(); y++)
        {
            for (int z = this.sourceBounds.getMin().getZ(); z <= this.sourceBounds.getMax().getZ(); z++)
            {
                BlockPos goalStructurePos = new BlockPos(x, y, z);
                BlockPos playerStructurePos = goalStructurePos.add(this.delta);
                // We don't compare the world's block states, since we re-colour them to give
                // feedback on right / wrong blocks.
                // Instead, query our internal representations:
                IBlockState srcState = getSourceBlockState(w, goalStructurePos);
                IBlockState dstState = getDestBlockState(w, playerStructurePos);
                if (srcState == null || dstState == null)
                    continue;   // Shouldn't happen unless we've had an out-of-bounds error somehow.
                boolean destAir = w.isAirBlock(playerStructurePos);
                if (srcState.equals(dstState))
                {
                    // They match. We count this if the dest block is not air.
                    if (!destAir)
                        rightBlocks++;
                    if (blockTypeOnCorrectPlacement != null && !w.isAirBlock(goalStructurePos))
                    {
                        // Mark both source and destination blocks for correct placement:
                        drawContext.setBlockState(w, playerStructurePos, blockTypeOnCorrectPlacement);
                        drawContext.setBlockState(w, goalStructurePos, blockTypeOnCorrectPlacement);
                    }
                    totalMatchingBlocks++;
                }
                else
                {
                    // Non-match. We call this wrong if the dest block is not air.
                    if (!destAir)
                    {
                        wrongBlocks++;
                        if (blockTypeOnIncorrectPlacement != null)
                        {
                            // Recolour the destination block only:
                            drawContext.setBlockState(w, playerStructurePos, blockTypeOnIncorrectPlacement);
                        }
                    }
                    // Check the source block - if it was previously correct, and has become incorrect,
                    // then we will need to reset the world's blockstate:
                    IBlockState actualState = w.getBlockState(goalStructurePos);
                    if (!actualState.equals(srcState))
                        drawContext.setBlockState(w, goalStructurePos, new XMLBlockState(srcState));
                }
            }
        }
    }
    drawContext.endDrawing(w);
    int score = rightBlocks - wrongBlocks;
    boolean sendData = false;
    boolean sendCompletionBonus = false;
    int reward = 0;

    if (updateReward && score != this.currentScore)
    {
        reward = score - this.currentScore;
        sendData = true;
    }
    this.currentScore = score;

    if (totalMatchingBlocks == this.structureVolume)
    {
        if (!this.structureHasBeenCompleted)
        {
            // The structure has been completed - send the reward bonus.
            // We check structureHasBeenCompleted here because we only want to do this once.
            // (Otherwise the agent can game the rewards by repeatedly breaking and re-adding the
            // final block.)
            if (updateReward)
                sendCompletionBonus = true;
        }
        this.structureHasBeenCompleted = true;
    }
    this.valid = true;

    if (sendData)
    {
        HashMap<String,String> data = new HashMap<String, String>();
        data.put("reward", Integer.toString(reward));
        data.put("completed", Boolean.toString(sendCompletionBonus));
        MalmoMod.safeSendToAll(MalmoMessageType.SERVER_BUILDBATTLEREWARD, data);
    }
}