Block texture load only in the inventory - java

I am creating a mod but the texture of a block (the only one) loads only in the inventory and when it gets dropped, hope you can help me, I'm using the 1.8 MDK.
Blockstates:
{
"variants"": {
"normal": {"model": "horsenexus:horse_block"},
}
}
Models, block:
{
"parent": "block/cube_all",
"textures": {
"down": "horsenexus:blocks/horse_block_down",
"up": "horsenexus:blocks/horse_block_top",
"north": "horsenexus:blocks/horse_block_north",
"east": "horsenexus:blocks/horse_block_east",
"south": "horsenexus:blocks/horse_block_south",
"west": "horsenexus:blocks/horse_block_west"
}
}
Models, item:
{
"parent": "horsenexus:block/horse_block",
"display": {
"thirdperson": {
"rotation": [ 10, -45, 170 ],
"translation": [ 0, 1.5, -2.75 ],
"scale": [ 0.375, 0.375, 0.375 ]
}
}
}
And the codes:
package com.crazyhoorse961.core.blocks;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.MinecraftForge;
public class HorseBlock extends Block{
public HorseBlock(Material materialIn) {
super(materialIn);
this.setHardness(5.6F);
this.setResistance(56.34F);
this.setStepSound(this.soundTypeSnow);
}
}
And the last one:
package com.crazyhoorse961.core.init;
import com.crazyhoorse961.core.Reference;
import com.crazyhoorse961.core.blocks.HorseBlock;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.item.Item;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.registry.GameRegistry;
public class Horse_Block {
public static Block horse_block;
public static void init()
{
horse_block = new HorseBlock(Material.clay).setUnlocalizedName("horse_block");
}
public static void register()
{
GameRegistry.registerBlock(horse_block, horse_block.getUnlocalizedName().substring(5));
}
public static void registerRenders()
{
registerRender(horse_block);
}
public static void registerRender(Block block)
{
Item item = Item.getItemFromBlock(block);
Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, 0, new ModelResourceLocation(Reference.MOD_ID + ":" + item.getUnlocalizedName().substring(5), "inventory"));
}
}
Thank you for trying to help me, have a good day.

Try changing the following line in your "Models, block" code
"parent": "block/cube_all",
into:
"parent": "block/cube",
As far as I'm aware 'cube_all' is only used when you use the same texture for all sides of your block.

Related

Block texture load only when placed, but not in inventory

I've read some other 'similar' questions but their problems is exactly the opposite. I've also read the docs but they won't provide anything useful to this problem.
When I /give myself the block, it shows a missing texture in my inventory as a item. But when I place it, its texture is shown in the world as a block.
Screenshot:
Main mod class:
package com.byethost8.code2828.mcmods.chemc;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.Block;
import net.minecraft.block.OreBlock;
import net.minecraft.block.material.Material;
import net.minecraft.block.material.MaterialColor;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item.Properties;
import net.minecraft.item.ItemGroup;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
#Mod(CheMC_.modid)
public class CheMC_ {
public static final String modid = "chemc";
public static OreBlock ore_lithium = (OreBlock) new OreBlock(
AbstractBlock.Properties
.create(Material.ROCK, MaterialColor.PINK_TERRACOTTA)
.harvestLevel(1)
.hardnessAndResistance(1, 1)
.setLightLevel(
light -> {
return 1;
}
)
)
.setRegistryName("chemc", "lithium_ore");
public static BlockItem i_ore_lithium = (BlockItem) new BlockItem(
ore_lithium,
new Properties().group(ItemGroup.BUILDING_BLOCKS)
)
.setRegistryName(ore_lithium.getRegistryName());
public static Block block_lithium = new Block(
AbstractBlock.Properties
.create(Material.IRON, MaterialColor.PINK_TERRACOTTA)
.harvestLevel(1)
.hardnessAndResistance(1.2F, 1)
.setLightLevel(
light -> {
return 1;
}
)
)
.setRegistryName("chemc", "lithium_block");
public static BlockItem i_block_lithium = (BlockItem) new BlockItem(
block_lithium,
new Properties().group(ItemGroup.BUILDING_BLOCKS)
)
.setRegistryName(block_lithium.getRegistryName());
public CheMC_() {
FMLJavaModLoadingContext
.get()
.getModEventBus()
.addListener(this::setup);
MinecraftForge.EVENT_BUS.register(this);
}
private void setup(final FMLCommonSetupEvent event) {}
// You can use EventBusSubscriber to automatically subscribe events on the
// contained class (this is subscribing to the MOD
// Event bus for receiving Registry Events)
#Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)
public static class RegistryEvents {
#SubscribeEvent
public static void onBlocksRegistry(
final RegistryEvent.Register<Block> blockRegistryEvent
) {
// register a new block here
blockRegistryEvent
.getRegistry()
.registerAll(ore_lithium, block_lithium);
}
}
}
Some codes are removed to make the main problem clear.
Following texts only will say about Lithium Block, but same things apply for Lithium Ore.
Model File:
{
"parent": "block/cube_all",
"textures": {
"all": "chemc:block/lithium_block"
}
}
Folder structure of src/main/resources:
Blockstate:
{
"variants": {
"": [
{ "model": "chemc:block/lithium_block" }
]
}
}
I can't believe that I was stupid enough to register a Item and do nothing to assets/chemc/resources/models/item/ folder. See this for more. I have the exactly same problem as that OP.

NativeScriptAngular http request error Android 4.2

I am making an app in angular nativescript, I am using web services, but when I try to do a http request in Android 4, it throws this error. But when I do it on Android 9, there are no errors and it makes the insert.
app.module.ts
import { NgModule, NO_ERRORS_SCHEMA } from "#angular/core";
import { NativeScriptModule, NativeScriptHttpClientModule, NativeScriptFormsModule } from "#nativescript/angular";
import { NgShadowModule } from 'nativescript-ng-shadow';
import { AppRoutingModule } from "./app-routing.module";
import { AppComponent } from "./app.component";
import { LoginComponent } from './components/login/login.component';
import { HeaderComponent } from './components/partials/header/header.component';
import { FooterComponent } from './components/partials/footer/footer.component';
import { IndexComponent } from './components/index/index.component';
import { RegistrarComponent } from './components/registrar/registrar.component';
#NgModule({
bootstrap: [
AppComponent
],
imports: [
NativeScriptModule,
AppRoutingModule,
NativeScriptHttpClientModule,
NgShadowModule,
NativeScriptFormsModule
],
declarations: [
AppComponent,
LoginComponent,
HeaderComponent,
FooterComponent,
IndexComponent,
RegistrarComponent,
],
providers: [],
schemas: [
NO_ERRORS_SCHEMA
]
})
/*
Pass your application module to the bootstrapModule function located in main.ts to start your app
*/
export class AppModule { }
service
post(url: string, body: Object): Observable<any> {
return this.http.post(this.apiUrl() + url, JSON.stringify(body), { headers: this.getHeaders() })
.pipe(catchError(function (error: any) {
return throwError(error || 'Server error');
}));
}
app.gradle
android {
defaultConfig {
minSdkVersion 17
generatedDensities = []
flavorDimensions "versionCode"
}
aaptOptions {
additionalParameters "--no-version-vectors"
}
}
Thanks for your time
Try to this:- Add HttpClientModule In App Module.
import { NgModule, NO_ERRORS_SCHEMA } from "#angular/core";
import { NativeScriptModule, NativeScriptHttpClientModule,
NativeScriptFormsModule } from "#nativescript/angular";
import { NgShadowModule } from "nativescript-ng-shadow";
import { AppRoutingModule } from "./app-routing.module";
import { AppComponent } from "./app.component";
import { LoginComponent } from './components/login/login.component';
import { HeaderComponent } from
'./components/partials/header/header.component';
import { FooterComponent } from
'./components/partials/footer/footer.component';
import { IndexComponent } from './components/index/index.component';
import { RegistrarComponent } from
'./components/registrar/registrar.component';
import { HttpClientModule } from "#angular/common/http";
#NgModule({
bootstrap: [
AppComponent
],
imports: [
NativeScriptModule,
AppRoutingModule,
NativeScriptHttpClientModule,
NgShadowModule,
HttpClientModule,
NativeScriptFormsModule
],
declarations: [
AppComponent,
LoginComponent,
HeaderComponent,
FooterComponent,
IndexComponent,
RegistrarComponent,
],
providers: [],
schemas: [
NO_ERRORS_SCHEMA
]
})
/*
Pass your application module to the bootstrapModule function located in
main.ts to start your app
*/
export class AppModule { }
And Add One Line In AndroidManifest.xml File:-
<application
android:usesCleartextTraffic="true">
File Location:- App_Resource->Android->src->main

How can I parse nested JSON with multiple wrapper classes? (spring boot project)

Make a sample Java service which takes the following json from an endpoint as input, parses it
and puts it into the database.
Input: ​ The input will have a fixed format which will be posted as a content body to the endpoint.
Output: ​ The output should be a number of rows that are filled in the database or error in case of failures.
Sample input :
{
"quiz": {
"sport": {
"q1": {
"question": "Which one is correct team name in NBA?",
"options": [
"New York Bulls",
"Los Angeles Kings",
"Golden State Warriros",
"Huston Rocket"
],
"answer": "Huston Rocket"
}
},
"maths": {
"q1": {
"question": "5 + 7 = ?",
"options": [
"10",
"11",
"12",
"13"
],
"answer": "12"
},
"q2": {
"question": "12 - 8 = ?",
"options": [
"1",
"2",
"3",
"4"
],
"answer": "4"
}
}
}
}
I've created a basic Rest service with springboot that takes in question, options and answer as input, and also displays it in the same way.
Ex. input :
{
"question": "khis is the question part",
"options": [
"option 1",
"option 2",
"option 3",
"option 4"
],
"answer": "option 1"
}
I have created a springboot project and created the following java classes:
1. QuestionSet.java
package com.example.demo.questionset;
import java.io.Serializable;
import com.fasterxml.jackson.annotation.JsonRootName;
public class QuestionSet {
private String question;
private String options[];
private String answer;
public QuestionSet() {
}
public QuestionSet(String question, String[] options, String answer) {
super();
this.question = question;
this.options = options;
this.answer = answer;
}
public String getQuestion() {
return question;
}
public String[] getOptions() {
return options;
}
public String getAnswer() {
return answer;
}
public void setQuestion(String question) {
this.question = question;
}
public void setOptions(String[] options) {
this.options = options;
}
public void setAnswer(String answer) {
this.answer = answer;
}
}
`
QuestionSetService.java
package com.example.demo.questionset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.ObjectWriter;
#Service
public class QuestionSetService {
String nameString[] = {"kabir", "ram", "shyam", "varun"};
QuestionSetController.java
package com.example.demo.questionset;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.fasterxml.jackson.annotation.JsonGetter;
#RestController
public class QuestionSetController {
#Autowired
QuestionSetService questionSetService;
#RequestMapping("/questionsets")
public List<QuestionSet> getAllQuestionSets(){
return questionSetService.getAllQuestionSets();
}
#RequestMapping("/questionsets/{question}")
public QuestionSet getQuestionSetByQuestion(#PathVariable String question)
{
return questionSetService.getQuestionSetByQuestion(question);
}
#PostMapping("/questionsets")
public void postController(
#RequestBody QuestionSet questionSet) {
questionSetService.addQuestionSet(questionSet);
}
}
private List<QuestionSet> questionSets = null;
public List<QuestionSet> getAllQuestionSets() {
return questionSets;
}
public QuestionSet getQuestionSetByQuestion(String question) {
return questionSets.stream().filter(t ->
t.getQuestion().equals(question)).findFirst().get();
}
public ResponseEntity addQuestionSet( QuestionSet questionSet) {
questionSets.add(questionSet);
return ResponseEntity.ok(HttpStatus.OK);
}
}
I can take in simple json input in the form of questionset but the required json input is much more complex. I understand that I need to make wrapper classes and use objectmapper, but I don't know how.
JSONObject obj = (JSONObject) parser.parse(reader);
JSONObject response =(JSONObject) parser.parse(obj.get("quiz").toString());
JSONObject sub =(JSONObject) parser.parse(response.get("sport").toString());
JSONObject q1 = (JSONObject) parser.parse(sub.get("q1").toString());
String question =(q1.get("question").toString());
System.out.println(question);
JSONArray options = (JSONArray)parser.parse(q1.get("options").toString());
for(int i=0 ;i<options.size();i++) {
System.out.println(options.get(i));
}
Output :-
Which one is correct team name in NBA?
New York Bulls
Los Angeles Kings
Golden State Warriros
Huston Rocket
This is a sample on how you can parse the input json using simple-json. Although there is a lot of manual work here, you can avoid it by using nested JSONArray and iterate over it.

Minecraft Forge Item Block Render Issue

I am having an item block rendering issue, as when I place the block, it renders correctly, but when I hold it in my hand, it has a missing texture/model.
An image of what I see is in the link: http://i.stack.imgur.com/atq1L.png
I have checked many times for the reason, and there is no error message in the console, there does not appear to be any problems with the JSON formatting, and there seems to be no problem in the code.
*By the way, the code for the block class is not too important because it is just a class that extends *Block.class, then gives the super with Material.stone
Here is my code for my blocks class:
package com.kraftymods.luckyblocks.init;
import com.kraftymods.luckyblocks.blocks.LuckyBlock;
import com.kraftymods.luckyblocks.blocks.itemblocks.LuckyBlockItem;
import com.kraftymods.luckyblocks.main.Reference;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraftforge.fml.common.registry.GameRegistry;
public class Blocks {
public static Block luckyblock;
public static void init(){
luckyblock = new LuckyBlock().setUnlocalizedName("luckyblock")[enter image description here][1].setCreativeTab(CreativeTabs.tabMisc);
}
public static void register(){
GameRegistry.registerBlock(luckyblock, LuckyBlockItem.class, luckyblock.getUnlocalizedName().substring(5));
}
public static void registerRenders(){
registerRender(luckyblock);
}
private static void registerRender(Block block){
Item item = Item.getItemFromBlock(block);
Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, 0, new ModelResourceLocation(Reference.MODID + ":" + item.getUnlocalizedName().substring(5), "inventory"));
}
}
Here is the code for my JSON files:
Blockdata:
{
"variants": {
"normal": { "model": "luckyblocks:luckyblock" }
}
}
Block Model:
{
"parent": "block/cube_all",
"textures": {
"all": "luckyblocks:blocks/luckyblock"
}
}
Item Model:
{
"parent": "luckyblocks:block/luckyblock",
"display": {
"thirdperson": {
"rotation": [ 10, -45, 170 ],
"translation": [ 0, 1.5, -2.75 ],
"scale": [ 0.375, 0.375, 0.375 ]
}
}
}
I appreciate the time you took to read this
Please make a class for clientside purposes in which you register your renderers
I have this for example:
public final class BlockRenderRegister {
public static void registerBlockRenderer() {
register(BlocksLibrary.blockDarkStone);
}
public static void register(Block block) {
Minecraft.getMinecraft().getRenderItem().getItemModelMesher()
.register(Item.getItemFromBlock(block),
0,
new ModelResourceLocation(
ModHooks.MODID.toLowerCase() + ":" + BlocksLibrary.DARKSTONE,
"inventory"
)
);
}
}
And for loading your blocks I also suggest a seperate class(just for maintenance purposes
public class BlockLoader {
/**
* Loads all blocks into memory
* and populates the BlocksLibary
* with decent values.
*/
public static void loadBlocks() {
GameRegistry.registerBlock(
BlocksLibrary.blockDarkStone = new BlockDarkStone(Material.rock),
BlocksLibrary.DARKSTONE
);
}
}
I register the blocks in the PreInit event so the game knows my blocks.
#EventHandler
public void preInit(FMLPreInitializationEvent e) {
BlockLoader.loadBlocks();
}
And I call this from the FMLInitializationEvent in my main mod class to register the renderers.
#EventHandler
public void init(FMLInitializationEvent event) {
BlockRenderRegister.registerBlockRenderer();
}

Elasticsearch FunctionScore query using Java API

I need to implement the below function_score query using Java APIs. I couldn't find any official documentation for function_score query in the Java API section of elasticsearch
"function_score": {
"functions": [
{
"boost_factor": "3",
"filter": {
"terms" : {"course_cd" : ["writ100", "writ112", "writ113"] }
}
}
],
"query": {
"match" : {
"party_id" : "12"
}
}
}
Please help!
Thanks to Jörg
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder;
import java.util.Arrays;
import static org.elasticsearch.client.Requests.searchRequest;
import static org.elasticsearch.index.query.FilterBuilders.termsFilter;
import static org.elasticsearch.index.query.QueryBuilders.matchQuery;
import static org.elasticsearch.index.query.functionscore.ScoreFunctionBuilders.factorFunction;
import static org.elasticsearch.search.builder.SearchSourceBuilder.searchSource;
public class FunctionScoreTest {
public void testFunctionScore() {
SearchRequest searchRequest = searchRequest()
.source(searchSource().query(new FunctionScoreQueryBuilder(matchQuery("party_id", "12"))
.add(termsFilter("course_cd", Arrays.asList("writ100", "writ112", "writ113")), factorFunction(3.0f))));
}
}

Categories

Resources