use of net.minecraft.block.properties.IProperty in project malmo by Microsoft.
the class ObservationFromRayImplementation method buildMouseOverData.
/** Build the json object for the object under the cursor, whether it is a block or a creature.<br>
* If there is any data to be returned, the json will be added in a subnode called "LineOfSight".
* @param json a JSON object into which the info for the object under the mouse will be added.
*/
public static void buildMouseOverData(JsonObject json) {
// We could use Minecraft.getMinecraft().objectMouseOver but it's limited to the block reach distance, and
// doesn't register floating tile items.
// Ideally use Minecraft.timer.renderPartialTicks - but we don't need sub-tick resolution.
float partialTicks = 0;
Entity viewer = Minecraft.getMinecraft().thePlayer;
// Hard-coded for now - in future will be parameterised via the XML.
float depth = 50;
Vec3 eyePos = viewer.getPositionEyes(partialTicks);
Vec3 lookVec = viewer.getLook(partialTicks);
Vec3 searchVec = eyePos.addVector(lookVec.xCoord * depth, lookVec.yCoord * depth, lookVec.zCoord * depth);
MovingObjectPosition mop = Minecraft.getMinecraft().theWorld.rayTraceBlocks(eyePos, searchVec, false, false, false);
MovingObjectPosition mopEnt = findEntity(eyePos, lookVec, depth, mop, true);
if (mopEnt != null)
mop = mopEnt;
if (mop == null) {
// Nothing under the mouse.
return;
}
// Calculate ranges for player interaction:
double hitDist = mop.hitVec.distanceTo(eyePos);
double blockReach = Minecraft.getMinecraft().playerController.getBlockReachDistance();
double entityReach = Minecraft.getMinecraft().playerController.extendedReach() ? 6.0 : 3.0;
JsonObject jsonMop = new JsonObject();
if (mop.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) {
// We're looking at a block - send block data:
jsonMop.addProperty("hitType", "block");
jsonMop.addProperty("x", mop.hitVec.xCoord);
jsonMop.addProperty("y", mop.hitVec.yCoord);
jsonMop.addProperty("z", mop.hitVec.zCoord);
IBlockState state = Minecraft.getMinecraft().theWorld.getBlockState(mop.getBlockPos());
List<IProperty> extraProperties = new ArrayList<IProperty>();
DrawBlock db = MinecraftTypeHelper.getDrawBlockFromBlockState(state, extraProperties);
jsonMop.addProperty("type", db.getType().value());
if (db.getColour() != null)
jsonMop.addProperty("colour", db.getColour().value());
if (db.getVariant() != null)
jsonMop.addProperty("variant", db.getVariant().getValue());
if (db.getFace() != null)
jsonMop.addProperty("facing", db.getFace().value());
if (extraProperties.size() > 0) {
// Add the extra properties that aren't covered by colour/variant/facing.
for (IProperty prop : extraProperties) {
String key = "prop_" + prop.getName();
if (prop.getValueClass() == Boolean.class)
jsonMop.addProperty(key, Boolean.valueOf(state.getValue(prop).toString()));
else if (prop.getValueClass() == Integer.class)
jsonMop.addProperty(key, Integer.valueOf(state.getValue(prop).toString()));
else
jsonMop.addProperty(key, state.getValue(prop).toString());
}
}
jsonMop.addProperty("inRange", hitDist <= blockReach);
jsonMop.addProperty("distance", hitDist);
} else if (mop.typeOfHit == MovingObjectPosition.MovingObjectType.ENTITY) {
// Looking at an entity:
Entity entity = mop.entityHit;
if (entity != null) {
jsonMop.addProperty("x", entity.posX);
jsonMop.addProperty("y", entity.posY);
jsonMop.addProperty("z", entity.posZ);
String name = entity.getName();
String hitType = "entity";
if (entity instanceof EntityItem) {
ItemStack is = ((EntityItem) entity).getEntityItem();
DrawItem di = MinecraftTypeHelper.getDrawItemFromItemStack(is);
if (di.getColour() != null)
jsonMop.addProperty("colour", di.getColour().value());
if (di.getVariant() != null)
jsonMop.addProperty("variant", di.getVariant().getValue());
jsonMop.addProperty("stackSize", is.stackSize);
name = di.getType();
hitType = "item";
}
jsonMop.addProperty("type", name);
jsonMop.addProperty("hitType", hitType);
}
jsonMop.addProperty("inRange", hitDist <= entityReach);
jsonMop.addProperty("distance", hitDist);
}
json.add("LineOfSight", jsonMop);
}
use of net.minecraft.block.properties.IProperty in project SecurityCraft by Geforce132.
the class ItemBlockReinforcedSlabs2 method canPlaceBlockOnSide.
@Override
@SideOnly(Side.CLIENT)
public boolean canPlaceBlockOnSide(World worldIn, BlockPos pos, EnumFacing side, EntityPlayer player, ItemStack stack) {
BlockPos blockpos1 = pos;
IProperty iproperty = singleSlab.getVariantProperty();
Object object = singleSlab.getVariant(stack);
IBlockState iblockstate = worldIn.getBlockState(pos);
if (iblockstate.getBlock() == singleSlab) {
boolean flag = iblockstate.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.TOP;
if ((side == EnumFacing.UP && !flag || side == EnumFacing.DOWN && flag) && object == iblockstate.getValue(iproperty))
return true;
}
pos = pos.offset(side);
IBlockState iblockstate1 = worldIn.getBlockState(pos);
return iblockstate1.getBlock() == singleSlab && object == iblockstate1.getValue(iproperty) ? true : super.canPlaceBlockOnSide(worldIn, blockpos1, side, player, stack);
}
use of net.minecraft.block.properties.IProperty in project SecurityCraft by Geforce132.
the class ItemBlockReinforcedWoodSlabs method canPlaceBlockOnSide.
@Override
@SideOnly(Side.CLIENT)
public boolean canPlaceBlockOnSide(World worldIn, BlockPos pos, EnumFacing side, EntityPlayer player, ItemStack stack) {
BlockPos blockpos1 = pos;
IProperty iproperty = this.singleSlab.getVariantProperty();
Object object = this.singleSlab.getTypeForItem(stack);
IBlockState iblockstate = worldIn.getBlockState(pos);
if (iblockstate.getBlock() == this.singleSlab) {
boolean flag = iblockstate.getValue(BlockSlab.HALF) == BlockSlab.EnumBlockHalf.TOP;
if ((side == EnumFacing.UP && !flag || side == EnumFacing.DOWN && flag) && object == iblockstate.getValue(iproperty)) {
return true;
}
}
pos = pos.offset(side);
IBlockState iblockstate1 = worldIn.getBlockState(pos);
return iblockstate1.getBlock() == this.singleSlab && object == iblockstate1.getValue(iproperty) ? true : super.canPlaceBlockOnSide(worldIn, blockpos1, side, player, stack);
}
use of net.minecraft.block.properties.IProperty in project malmo by Microsoft.
the class ObservationFromRayImplementation method buildMouseOverData.
/**
* Build the json object for the object under the cursor, whether it is a block or a creature.<br>
* If there is any data to be returned, the json will be added in a subnode called "LineOfSight".
* @param json a JSON object into which the info for the object under the mouse will be added.
*/
public static void buildMouseOverData(JsonObject json, boolean includeNBTData) {
// We could use Minecraft.getMinecraft().objectMouseOver but it's limited to the block reach distance, and
// doesn't register floating tile items.
// Ideally use Minecraft.timer.renderPartialTicks - but we don't need sub-tick resolution.
float partialTicks = 0;
Entity viewer = Minecraft.getMinecraft().player;
// Hard-coded for now - in future will be parameterised via the XML.
float depth = 50;
Vec3d eyePos = viewer.getPositionEyes(partialTicks);
Vec3d lookVec = viewer.getLook(partialTicks);
Vec3d searchVec = eyePos.addVector(lookVec.xCoord * depth, lookVec.yCoord * depth, lookVec.zCoord * depth);
RayTraceResult mop = Minecraft.getMinecraft().world.rayTraceBlocks(eyePos, searchVec, false, false, false);
RayTraceResult mopEnt = findEntity(eyePos, lookVec, depth, mop, true);
if (mopEnt != null)
mop = mopEnt;
if (mop == null) {
// Nothing under the mouse.
return;
}
// Calculate ranges for player interaction:
double hitDist = mop.hitVec.distanceTo(eyePos);
double blockReach = Minecraft.getMinecraft().playerController.getBlockReachDistance();
double entityReach = Minecraft.getMinecraft().playerController.extendedReach() ? 6.0 : 3.0;
JsonObject jsonMop = new JsonObject();
if (mop.typeOfHit == RayTraceResult.Type.BLOCK) {
// We're looking at a block - send block data:
jsonMop.addProperty("hitType", "block");
jsonMop.addProperty("x", mop.hitVec.xCoord);
jsonMop.addProperty("y", mop.hitVec.yCoord);
jsonMop.addProperty("z", mop.hitVec.zCoord);
IBlockState state = Minecraft.getMinecraft().world.getBlockState(mop.getBlockPos());
List<IProperty> extraProperties = new ArrayList<IProperty>();
DrawBlock db = MinecraftTypeHelper.getDrawBlockFromBlockState(state, extraProperties);
jsonMop.addProperty("type", db.getType().value());
if (db.getColour() != null)
jsonMop.addProperty("colour", db.getColour().value());
if (db.getVariant() != null)
jsonMop.addProperty("variant", db.getVariant().getValue());
if (db.getFace() != null)
jsonMop.addProperty("facing", db.getFace().value());
if (extraProperties.size() > 0) {
// Add the extra properties that aren't covered by colour/variant/facing.
for (IProperty prop : extraProperties) {
String key = "prop_" + prop.getName();
if (prop.getValueClass() == Boolean.class)
jsonMop.addProperty(key, Boolean.valueOf(state.getValue(prop).toString()));
else if (prop.getValueClass() == Integer.class)
jsonMop.addProperty(key, Integer.valueOf(state.getValue(prop).toString()));
else
jsonMop.addProperty(key, state.getValue(prop).toString());
}
}
// Add the NBTTagCompound, if this is a tile entity.
if (includeNBTData) {
TileEntity tileentity = Minecraft.getMinecraft().world.getTileEntity(mop.getBlockPos());
if (tileentity != null) {
NBTTagCompound data = tileentity.getUpdateTag();
if (data != null) {
// Turn data directly into json and add it to what we're already returning.
String jsonString = data.toString();
try {
JsonElement jelement = new JsonParser().parse(jsonString);
if (jelement != null)
jsonMop.add("NBTTagCompound", jelement);
} catch (JsonSyntaxException e) {
// Duff NBTTagCompound - ignore it.
}
}
}
}
jsonMop.addProperty("inRange", hitDist <= blockReach);
jsonMop.addProperty("distance", hitDist);
} else if (mop.typeOfHit == RayTraceResult.Type.ENTITY) {
// Looking at an entity:
Entity entity = mop.entityHit;
if (entity != null) {
jsonMop.addProperty("x", entity.posX);
jsonMop.addProperty("y", entity.posY);
jsonMop.addProperty("z", entity.posZ);
jsonMop.addProperty("yaw", entity.rotationYaw);
jsonMop.addProperty("pitch", entity.rotationPitch);
String name = MinecraftTypeHelper.getUnlocalisedEntityName(entity);
String hitType = "entity";
if (entity instanceof EntityItem) {
ItemStack is = ((EntityItem) entity).getEntityItem();
DrawItem di = MinecraftTypeHelper.getDrawItemFromItemStack(is);
if (di.getColour() != null)
jsonMop.addProperty("colour", di.getColour().value());
if (di.getVariant() != null)
jsonMop.addProperty("variant", di.getVariant().getValue());
jsonMop.addProperty("stackSize", is.getCount());
name = di.getType();
hitType = "item";
}
jsonMop.addProperty("type", name);
jsonMop.addProperty("hitType", hitType);
}
jsonMop.addProperty("inRange", hitDist <= entityReach);
jsonMop.addProperty("distance", hitDist);
}
json.add("LineOfSight", jsonMop);
}
use of net.minecraft.block.properties.IProperty in project malmo by Microsoft.
the class AgentQuitFromTouchingBlockTypeImplementation method findMatch.
private boolean findMatch(BlockSpec blockspec, IBlockState blockstate) {
// Firstly, do the block types match at all?
String blockname = blockstate.getBlock().getUnlocalizedName().toLowerCase();
if (!findNameMatch(blockspec, blockname))
// Block name wasn't found in this block type.
return false;
// Next, check for a colour match:
net.minecraft.item.EnumDyeColor blockColour = null;
for (IProperty prop : blockstate.getProperties().keySet()) {
if (prop.getName().equals("color") && prop.getValueClass() == net.minecraft.item.EnumDyeColor.class) {
blockColour = (net.minecraft.item.EnumDyeColor) blockstate.getValue(prop);
}
}
if (blockColour != null && !findColourMatch(blockspec, blockColour.getName()))
// Colours didn't match.
return false;
// Now check for the variant match:
Object blockVariant = null;
for (IProperty prop : blockstate.getProperties().keySet()) {
if (prop.getName().equals("variant") && prop.getValueClass().isEnum()) {
blockVariant = blockstate.getValue(prop);
}
}
if (blockVariant != null && !findVariantMatch(blockspec, blockVariant.toString()))
return false;
// If we've got here, then we have a total match.
return true;
}
Aggregations