use of net.minecraft.block.state.IBlockState in project malmo by Microsoft.
the class MinecraftTypeHelper method ParseItemType.
/**
* Attempts to parse the item type string.
* @param s The string to parse.
* @param checkBlocks if string can't be parsed as an item, attempt to parse as a block, if checkBlocks is true
* @return The item type, or null if the string is not recognised.
*/
public static Item ParseItemType(String s, boolean checkBlocks) {
if (s == null)
return null;
// Minecraft returns null when it doesn't recognise the string
Item item = (Item) Item.itemRegistry.getObject(new ResourceLocation(s));
if (item == null && checkBlocks) {
// Maybe this is a request for a block item?
IBlockState block = MinecraftTypeHelper.ParseBlockType(s);
item = (block != null && block.getBlock() != null) ? Item.getItemFromBlock(block.getBlock()) : null;
}
return item;
}
use of net.minecraft.block.state.IBlockState in project malmo by Microsoft.
the class JSONWorldDataHelper method buildGridData.
/**
* Build a signal for the cubic block grid centred on the player.<br>
* Default is 3x3x4. (One cube all around the player.)<br>
* Blocks are returned as a 1D array, in order
* along the x, then z, then y axes.<br>
* Data will be returned in an array called "Cells"
* @param json a JSON object into which the info for the object under the mouse will be added.
* @param environmentDimensions object which specifies the required dimensions of the grid to be returned.
* @param jsonName name to use for identifying the returned JSON array.
*/
public static void buildGridData(JsonObject json, GridDimensions environmentDimensions, EntityPlayerMP player, String jsonName) {
if (player == null || json == null)
return;
JsonArray arr = new JsonArray();
BlockPos pos = new BlockPos(player.posX, player.posY, player.posZ);
for (int y = environmentDimensions.yMin; y <= environmentDimensions.yMax; y++) {
for (int z = environmentDimensions.zMin; z <= environmentDimensions.zMax; z++) {
for (int x = environmentDimensions.xMin; x <= environmentDimensions.xMax; x++) {
BlockPos p;
if (environmentDimensions.absoluteCoords)
p = new BlockPos(x, y, z);
else
p = pos.add(x, y, z);
String name = "";
IBlockState state = player.worldObj.getBlockState(p);
Object blockName = Block.blockRegistry.getNameForObject(state.getBlock());
if (blockName instanceof ResourceLocation) {
name = ((ResourceLocation) blockName).getResourcePath();
}
JsonElement element = new JsonPrimitive(name);
arr.add(element);
}
}
}
json.add(jsonName, arr);
}
use of net.minecraft.block.state.IBlockState in project MinecraftForge by MinecraftForge.
the class ModelLoader method onPostBakeEvent.
/**
* Internal, do not use.
*/
public void onPostBakeEvent(IRegistry<ModelResourceLocation, IBakedModel> modelRegistry) {
IBakedModel missingModel = modelRegistry.getObject(MODEL_MISSING);
Map<String, Integer> modelErrors = Maps.newHashMap();
Set<ResourceLocation> printedBlockStateErrors = Sets.newHashSet();
Multimap<ModelResourceLocation, IBlockState> reverseBlockMap = null;
Multimap<ModelResourceLocation, String> reverseItemMap = null;
if (enableVerboseMissingInfo) {
reverseBlockMap = HashMultimap.create();
for (Map.Entry<IBlockState, ModelResourceLocation> entry : blockModelShapes.getBlockStateMapper().putAllStateModelLocations().entrySet()) {
reverseBlockMap.put(entry.getValue(), entry.getKey());
}
reverseItemMap = HashMultimap.create();
for (Item item : GameData.getItemRegistry().typeSafeIterable()) {
for (String s : getVariantNames(item)) {
ModelResourceLocation memory = getInventoryVariant(s);
reverseItemMap.put(memory, item.getRegistryName().toString());
}
}
}
for (Map.Entry<ResourceLocation, Exception> entry : loadingExceptions.entrySet()) {
// ignoring pure ResourceLocation arguments, all things we care about pass ModelResourceLocation
if (entry.getKey() instanceof ModelResourceLocation) {
ModelResourceLocation location = (ModelResourceLocation) entry.getKey();
IBakedModel model = modelRegistry.getObject(location);
if (model == null || model == missingModel) {
String domain = entry.getKey().getResourceDomain();
Integer errorCountBox = modelErrors.get(domain);
int errorCount = errorCountBox == null ? 0 : errorCountBox;
errorCount++;
if (errorCount < verboseMissingInfoCount) {
String errorMsg = "Exception loading model for variant " + entry.getKey();
if (enableVerboseMissingInfo) {
Collection<IBlockState> blocks = reverseBlockMap.get(location);
if (!blocks.isEmpty()) {
if (blocks.size() == 1) {
errorMsg += " for blockstate \"" + blocks.iterator().next() + "\"";
} else {
errorMsg += " for blockstates [\"" + Joiner.on("\", \"").join(blocks) + "\"]";
}
}
Collection<String> items = reverseItemMap.get(location);
if (!items.isEmpty()) {
if (!blocks.isEmpty())
errorMsg += " and";
if (items.size() == 1) {
errorMsg += " for item \"" + items.iterator().next() + "\"";
} else {
errorMsg += " for items [\"" + Joiner.on("\", \"").join(items) + "\"]";
}
}
}
if (entry.getValue() instanceof ItemLoadingException) {
ItemLoadingException ex = (ItemLoadingException) entry.getValue();
FMLLog.getLogger().error(errorMsg + ", normal location exception: ", ex.normalException);
FMLLog.getLogger().error(errorMsg + ", blockstate location exception: ", ex.blockstateException);
} else {
FMLLog.getLogger().error(errorMsg, entry.getValue());
}
ResourceLocation blockstateLocation = new ResourceLocation(location.getResourceDomain(), location.getResourcePath());
if (loadingExceptions.containsKey(blockstateLocation) && !printedBlockStateErrors.contains(blockstateLocation)) {
FMLLog.getLogger().error("Exception loading blockstate for the variant " + location + ": ", loadingExceptions.get(blockstateLocation));
printedBlockStateErrors.add(blockstateLocation);
}
}
modelErrors.put(domain, errorCount);
}
if (model == null) {
modelRegistry.putObject(location, missingModel);
}
}
}
for (ModelResourceLocation missing : missingVariants) {
IBakedModel model = modelRegistry.getObject(missing);
if (model == null || model == missingModel) {
String domain = missing.getResourceDomain();
Integer errorCountBox = modelErrors.get(domain);
int errorCount = errorCountBox == null ? 0 : errorCountBox;
errorCount++;
if (errorCount < verboseMissingInfoCount) {
FMLLog.severe("Model definition for location %s not found", missing);
}
modelErrors.put(domain, errorCount);
}
if (model == null) {
modelRegistry.putObject(missing, missingModel);
}
}
for (Map.Entry<String, Integer> e : modelErrors.entrySet()) {
if (e.getValue() >= verboseMissingInfoCount) {
FMLLog.severe("Suppressed additional %s model loading errors for domain %s", e.getValue() - verboseMissingInfoCount, e.getKey());
}
}
isLoading = false;
}
use of net.minecraft.block.state.IBlockState in project MinecraftForge by MinecraftForge.
the class AnimationTESR method renderTileEntityFast.
public void renderTileEntityFast(@Nonnull T te, double x, double y, double z, float partialTick, int breakStage, @Nonnull VertexBuffer renderer) {
if (!te.hasCapability(CapabilityAnimation.ANIMATION_CAPABILITY, null)) {
return;
}
if (blockRenderer == null)
blockRenderer = Minecraft.getMinecraft().getBlockRendererDispatcher();
BlockPos pos = te.getPos();
IBlockAccess world = MinecraftForgeClient.getRegionRenderCache(te.getWorld(), pos);
IBlockState state = world.getBlockState(pos);
if (state.getPropertyKeys().contains(Properties.StaticProperty)) {
state = state.withProperty(Properties.StaticProperty, false);
}
if (state instanceof IExtendedBlockState) {
IExtendedBlockState exState = (IExtendedBlockState) state;
if (exState.getUnlistedNames().contains(Properties.AnimationProperty)) {
float time = Animation.getWorldTime(getWorld(), partialTick);
IAnimationStateMachine capability = te.getCapability(CapabilityAnimation.ANIMATION_CAPABILITY, null);
if (capability != null) {
Pair<IModelState, Iterable<Event>> pair = capability.apply(time);
handleEvents(te, time, pair.getRight());
// TODO: caching?
IBakedModel model = blockRenderer.getBlockModelShapes().getModelForState(exState.getClean());
exState = exState.withProperty(Properties.AnimationProperty, pair.getLeft());
renderer.setTranslation(x - pos.getX(), y - pos.getY(), z - pos.getZ());
blockRenderer.getBlockModelRenderer().renderModel(world, model, exState, pos, renderer, false);
}
}
}
}
use of net.minecraft.block.state.IBlockState in project MinecraftForge by MinecraftForge.
the class BlockInfo method updateLightMatrix.
public void updateLightMatrix() {
boolean full = false;
for (int x = 0; x <= 2; x++) {
for (int y = 0; y <= 2; y++) {
for (int z = 0; z <= 2; z++) {
BlockPos pos = blockPos.add(x - 1, y - 1, z - 1);
IBlockState state = world.getBlockState(pos);
translucent[x][y][z] = state.isTranslucent();
//translucent[x][y][z] = world.getBlockState(pos).getBlock().getLightOpacity(world, pos) == 0;
int brightness = state.getPackedLightmapCoords(world, pos);
s[x][y][z] = (brightness >> 0x14) & 0xF;
b[x][y][z] = (brightness >> 0x04) & 0xF;
ao[x][y][z] = state.getAmbientOcclusionLightValue();
if (x == 1 && y == 1 && z == 1) {
full = state.isFullCube();
}
}
}
}
if (!full) {
for (EnumFacing side : EnumFacing.values()) {
int x = side.getFrontOffsetX() + 1;
int y = side.getFrontOffsetY() + 1;
int z = side.getFrontOffsetZ() + 1;
s[x][y][z] = Math.max(s[1][1][1] - 1, s[x][y][z]);
b[x][y][z] = Math.max(b[1][1][1] - 1, b[x][y][z]);
}
}
for (int x = 0; x < 2; x++) {
for (int y = 0; y < 2; y++) {
for (int z = 0; z < 2; z++) {
int x1 = x * 2;
int y1 = y * 2;
int z1 = z * 2;
boolean tx = translucent[x1][1][z1] || translucent[x1][y1][1];
skyLight[0][x][y][z] = combine(s[x1][1][1], s[x1][1][z1], s[x1][y1][1], tx ? s[x1][y1][z1] : s[x1][1][1]);
blockLight[0][x][y][z] = combine(b[x1][1][1], b[x1][1][z1], b[x1][y1][1], tx ? b[x1][y1][z1] : b[x1][1][1]);
boolean ty = translucent[x1][y1][1] || translucent[1][y1][z1];
skyLight[1][x][y][z] = combine(s[1][y1][1], s[x1][y1][1], s[1][y1][z1], ty ? s[x1][y1][z1] : s[1][y1][1]);
blockLight[1][x][y][z] = combine(b[1][y1][1], b[x1][y1][1], b[1][y1][z1], ty ? b[x1][y1][z1] : b[1][y1][1]);
boolean tz = translucent[1][y1][z1] || translucent[x1][1][z1];
skyLight[2][x][y][z] = combine(s[1][1][z1], s[1][y1][z1], s[x1][1][z1], tz ? s[x1][y1][z1] : s[1][1][z1]);
blockLight[2][x][y][z] = combine(b[1][1][z1], b[1][y1][z1], b[x1][1][z1], tz ? b[x1][y1][z1] : b[1][1][z1]);
}
}
}
}
Aggregations