Jump to content

grossik

Members
  • Posts

    88
  • Joined

  • Last visited

Posts posted by grossik

  1. Hi.
    I'm having trouble rendering my own head. If I place a head that has my skin texture and another one next to it (without texture - completely black) my skin is visible on the second one until the first head disappears from view. 
    How to make the second head always be all black?

    https://imgur.com/Bd2fNgP

    https://imgur.com/m04kAWV

    Code:

    public class CustomSkullRenderer implements BlockEntityRenderer<CustomSkullBlockEntity> {
    	
    	SkullModelBase headModel;
    	RenderType rendertype;
    	DynamicTexture texture;
    		
    	private int[][] oldTextureMap;
    	
    	public CustomSkullRenderer(BlockEntityRendererProvider.Context context) {
    		headModel = new SkullModel(context.bakeLayer(ClientSetup.HEAD));
    		rendertype = null;		
    		oldTextureMap = new int[16][32];
    		
    		texture = new DynamicTexture(64, 64, true);
    	}
    	
    	@Override
    	public void render(CustomSkullBlockEntity be, float p_112308_, PoseStack pose, MultiBufferSource buffer, int light, int p_112312_) {  
    		try {
    			updateImage(be);
    			if(rendertype == null) {
    				Minecraft.getInstance().getTextureManager().register(be.getLocation(), texture);
    				rendertype = CustomRenderType.createSkullRenderType(be.getLocation());
    			}
    		} catch(Exception e) {
    			e.printStackTrace();
    		}
    				
          BlockState blockstate = be.getBlockState();
          boolean flag = blockstate.getBlock() instanceof CustomSkullWall;
          Direction direction = flag ? blockstate.getValue(CustomSkullWall.FACING) : null;
          float f1 = 22.5F * (float)(flag ? (2 + direction.get2DDataValue()) * 4 : blockstate.getValue(CustomSkull.ROTATION));
          
          pose.pushPose();
          if(direction == null) {
          	pose.translate(0.5D, 0.0D, 0.5D);
          } else {
          	pose.translate((double)(0.5F - (float)direction.getStepX() * 0.25F), 0.25D, (double)(0.5F - (float)direction.getStepZ() * 0.25F));
          }
    
          pose.scale(-1.0F, -1.0F, 1.0F);
          VertexConsumer vertexconsumer = buffer.getBuffer(rendertype);
          headModel.setupAnim(0, f1, 0);
          headModel.renderToBuffer(pose, vertexconsumer, light, OverlayTexture.NO_OVERLAY, 1.0F, 1.0F, 1.0F, 1.0F);
          pose.popPose();
    	}
    
    	public void updateImage(CustomSkullBlockEntity be) {		
    		boolean update = false;
    		for(int y = 0; y < be.getTextureMap().length; y++) {
          	for(int x = 0; x < be.getTextureMap()[y].length; x++) {
          		if(oldTextureMap[y][x] != be.getTextureMap()[y][x]) {
          			setColorToImage(x, y, be.getTextureMap()[y][x]);
          			update = true;
          		}
          	}
          }
    
    		if(update) {
    			texture.upload();
    		}
    	}
    	
    	public void setColorToImage(int x, int y, int color) {						
    		texture.getPixels().setPixelRGBA(x, y, color);
    		oldTextureMap[y][x] = color;
    	}
    }
    public static RenderType createSkullRenderType(ResourceLocation location) {
          RenderType.CompositeState rendertype$compositestate = RenderType.CompositeState.builder()
          		.setShaderState(RENDERTYPE_ENTITY_TRANSLUCENT_SHADER)
          		.setTextureState(new RenderStateShard.TextureStateShard(location, false, false))
          		.setTransparencyState(TRANSLUCENT_TRANSPARENCY)
          		.setCullState(NO_CULL)
          		.setLightmapState(LIGHTMAP)
          		.setOverlayState(OVERLAY)
          		.createCompositeState(true);
          return RenderType.create(Main.MODID + "_head", DefaultVertexFormat.NEW_ENTITY, VertexFormat.Mode.QUADS, 256, true, true, rendertype$compositestate);
    }

     

  2. Hi

    I try to get custom entity to a specific position which is located above the diamond block, but the entity stops next to the block and doesn't continue. Where is the problem? How can I get my entity to position above the diamond block?

    https://imgur.com/6dzbt6J

     

    Custom goal:

    public class TestMoveToPositionGoal extends Goal {
    
    	protected MiniGolemEntity mob;
    	protected BlockPos blockPos;
    	protected int index;
    	protected int tryTicks;
    
    	public TestMoveToPositionGoal(MiniGolemEntity entity, int index) {
    		this.mob = entity;
    		this.index = index;
    		
    		this.setFlags(EnumSet.of(Goal.Flag.MOVE, Goal.Flag.JUMP));
    		
    		blockPos = new BlockPos(8, -60, -19);
    	}
    	
    	@Override
    	public void tick() {
    		super.tick();
    		
    		if(!blockPos.closerThan(this.mob.position(), 1D)) {
    			this.tryTicks++;
    			if(this.shouldRecalculatePath()) {
    				System.out.println("recalculate");
    				mob.getNavigation().moveTo(blockPos.getX() + 0.5D, blockPos.getY(), blockPos.getZ() + 0.5D, 1F);
    			}
    		} else {
    			this.tryTicks--;
    			mob.getNavigation().stop();
    			mob.chanceStatus(index);
    			System.out.println("finish");
    		}
    	}
    	
    	@Override
    	public void start() {
    		super.start();
    		tryTicks = 0;
    	}
    	
    	public boolean shouldRecalculatePath() {
    		return this.tryTicks % 40 == 0;
    	}	
       
    	@Override
    	public boolean canUse() {
    		return mob.canUseGoal(index);
    	}
    }

    Entity only recalculate path, but doesn't move. I know. I can solve it by increasing the radius, but I don't want to.

  3. Hi. I update my mod from 1.15.2 to 1.16.1 and in 1.16.1 version I see "button" behind my text.

    image.png.f98678b1daaf36db3cfe67c6fd5962ec.png

     

    I dont know how this solved

    Screen init:

    	@Override
    	public void func_231160_c_() {
    		super.func_231160_c_();
    		   
    		this.func_230480_a_(new Slider(this.guiLeft + 84, this.guiTop + 26, 85, 10, new StringTextComponent("Red: "), new StringTextComponent(""), 0, 255, this.container.tile.red, false, true, slider -> { }));   
    		this.func_230480_a_(new Slider(this.guiLeft + 84, this.guiTop + 38, 85, 10, new StringTextComponent("Green: "), new StringTextComponent(""), 0, 255, this.container.tile.green, false, true, slider -> { }));
    		this.func_230480_a_(new Slider(this.guiLeft + 84, this.guiTop + 50, 85, 10, new StringTextComponent("Blue: "), new StringTextComponent(""), 0, 255, this.container.tile.blue, false, true, slider -> { }));
    	}

     

  4. 9 hours ago, TheGreyGhost said:

    Hi

    Probably - some of your face normals are pointing the wrong way.  Use blender to automatically recalculate them so that your faces are pointing outwards, not inwards.

     

    Cheers

    TGG

    I try recalculate outside (Mesh -> Normals -> Recalculate outside) but not work. I also tried to recalculate inside and set from faces but nothing worked.

  5. Hi. I create Blender model, But I don't understand why it's hollow?

    dsa.thumb.png.aa9401c2d0c6e1fc97eccbcf1e64f1ad.png

    And JSON is:

    {
    	"parent": "forge:block/default",
      	"loader": "forge:obj",
      	"model": "farmcraft:models/block/boiling.obj",
      	"flip-v": true,
      	"transform": { "scale": [0.375, 0.375, 0.375], "translation": [0.4, -0.5, 0.4] } 
    }

    This problem occurs when they start to change model in modeling tab in blender. And if I add a normal cube without changes so it works.

  6. Hi. I need to use more texture layers for my item, but only 5 layers will load.

        	Minecraft minecraft = Minecraft.getInstance();
        	ItemColors colors = minecraft.getItemColors();
        	colors.register((p_210242_0_, p_210242_1_) -> {
        		if(p_210242_0_.getItem() == ItemInit.LABEL.get()) {
                    return ((LabelItem) p_210242_0_.getItem()).getColor(p_210242_0_, p_210242_1_);
        		}
        		return -1;
             }, ItemInit.LABEL.get());

    Item json:

    {
        "parent": "item/generated",
        "textures": {
            "layer0": "realistic_beer_brewing:items/label/layer0",
            "layer1": "realistic_beer_brewing:items/label/layer1",
            "layer2": "realistic_beer_brewing:items/label/layer2",
            "layer3": "realistic_beer_brewing:items/label/layer3",
            "layer4": "realistic_beer_brewing:items/label/layer4",
            "layer5": "realistic_beer_brewing:items/label/layer5",
            "layer6": "realistic_beer_brewing:items/label/layer6",
            "layer7": "realistic_beer_brewing:items/label/layer7",
            "layer8": "realistic_beer_brewing:items/label/layer8"
        }
    }
    

    Is the number of layers limited or why doesn't it work for me?

  7. Hello. 

    I have transferStackInSlot method and use hasRecipe for find if itemstack is present in recipe.

    @Override
    public ItemStack transferStackInSlot(PlayerEntity playerIn, int index) {
    	ItemStack itemstack = ItemStack.EMPTY;
    	Slot slot = this.inventorySlots.get(index);
    	if(slot != null && slot.getHasStack()) {
    		ItemStack itemstack1 = slot.getStack();
    		itemstack = itemstack1.copy();
    		if(index == 2) {
    			if(!this.mergeItemStack(itemstack1, 3, 39, true)) {
    				return ItemStack.EMPTY;
    			}
    
    			slot.onSlotChange(itemstack1, itemstack);
    		} else if(index != 1 && index != 0) {
    			if(this.hasRecipe(itemstack1)) {
    				if(!this.mergeItemStack(itemstack1, 1, 2, false)) {
    					return ItemStack.EMPTY;
    				}
    			} else if(this.isBucket(itemstack1)) {
    				if(!this.mergeItemStack(itemstack1, 0, 1, false)) {
    					return ItemStack.EMPTY;
    				}
    			} else if(index >= 3 && index < 30) {
    				if(!this.mergeItemStack(itemstack1, 30, 39, false)) {
    					return ItemStack.EMPTY;
    				}
    			} else if(index >= 30 && index < 39 && !this.mergeItemStack(itemstack1, 3, 30, false)) {
    				return ItemStack.EMPTY;
    			}
    		} else if(!this.mergeItemStack(itemstack1, 3, 39, false)) {
    			return ItemStack.EMPTY;
    		}
    
    		if(itemstack1.isEmpty()) {
    			slot.putStack(ItemStack.EMPTY);
    		} else {
    			slot.onSlotChanged();
    		}
    
    		if(itemstack1.getCount() == itemstack.getCount()) {
    			return ItemStack.EMPTY;
    		}
    
    		slot.onTake(playerIn, itemstack1);
    	}
    
    	return itemstack;
    }	
    
    protected boolean hasRecipe(ItemStack stack) {
    	return this.world.getRecipeManager().getRecipe(MaltingRecipe.RECIPE_TYPE, new Inventory(stack), world).isPresent();
    }

    But hasRecipe return false for all itemstack, but i have recipe who works.

    Recipe:

    {
    	"type": "realistic_beer_brewing:malting",
      	"ingredient": {
        	"item": "realistic_beer_brewing:barley"
      	},
      	"result": {
            "item": "realistic_beer_brewing:barley_seed"
        },
      	"process_time": 200
    }

    Recipe in this tile entity works.

  8. 3 minutes ago, TheGreyGhost said:

    Hi

    I think it's better to split your obj file into 8 separate files.

     

    If you really want to load just a small part of one obj file, have a look at OBJLoader and OBJmodel to see how it parses the file (g and o in particular); you can copy it to your own loader class and tweak it if you want to.

     

    TGG

    I wanted it over json, but ok...

    Any good way to split a model? Or will I have to do it for each file separately?

  9. 16 hours ago, TheGreyGhost said:

    Howdy

    A couple of things

    - it looks like you have multiple faces one on top of the other which is leading to 'z-fighting', https://en.wikipedia.org/wiki/Z-fighting

    - the 'recommended' version of forge has a bug where the vertex order of faces in obj files doesn't match what vanilla expects for ambient occlusion and leads to strange lighting.  Try latest instead of recommended.

     

    -TGG

     

    I use 1.15.2-31.1.63 forge version

    And the problem was that this obj files is too large and render for all 8 blocks... 

    Can I change the start position from which it will be loading obj model?

  10. 2 hours ago, diesieben07 said:

    First you are copying the position wrong (do not use getPosition, it returns a BlockPos). Use getPosX, getPosY and getPosZ.

    Then you also need to copy the other properties of the entity. Most importantly motion (Entity#getMotion) and for ItemEntity properties like pickupDelay, age, etc.

    float f8 = MathHelper.sin(location.rotationPitch * ((float)Math.PI / 180F));
    float f2 = MathHelper.cos(location.rotationPitch * ((float)Math.PI / 180F));
    float f3 = MathHelper.sin(location.rotationYaw * ((float)Math.PI / 180F));
    float f4 = MathHelper.cos(location.rotationYaw * ((float)Math.PI / 180F));
    float f5 = ((float)Math.PI * 2F);
    float f6 = 0.02F;
    itementity.setMotion((double)(-f3 * f2 * 0.3F) + Math.cos((double)f5) * (double)f6, (double)(-f8 * 0.3F + 0.1F * 0.1F), (double)(f4 * f2 * 0.3F) + Math.sin((double)f5) * (double)f6);

    This code drop item around player no in front of the player. Its from PlayerEntity drop

  11. 12 minutes ago, diesieben07 said:

    At this point I can't see the issue from just staring at the code.

    Please post a Git repository showing the issue so I can test this locally.

    https://github.com/grossik/FarmCraft/blob/master/src/main/java/cz/grossik/farmcraft/entity/FarmCraftItemEntity.java

    Item for this entity

    https://github.com/grossik/FarmCraft/blob/master/src/main/java/cz/grossik/farmcraft/item/ItemBarley.java

  12. 1 minute ago, diesieben07 said:

    This is your issue. You need to use your own registry name.

    Yes I know. I forgot send new registration. Sorry

    	public static RegistryObject<EntityType<FarmCraftItemEntity>> ITEM_ENTITY = ENTITIES
    			.register("item_farmcraft", () -> EntityType.Builder.<FarmCraftItemEntity>create(FarmCraftItemEntity::new, EntityClassification.MISC)
    					.size(0.25F, 0.25F)
    					.build(new ResourceLocation(Main.MOD_ID, "item_farmcraft").toString()));

     

  13. 1 minute ago, diesieben07 said:

    Post where you spawn the entity.

    This item:

    package cz.grossik.farmcraft.item;
    
    import cz.grossik.farmcraft.entity.FarmCraftItemEntity;
    import cz.grossik.farmcraft.init.EntityInit;
    import net.minecraft.entity.Entity;
    import net.minecraft.entity.item.ItemEntity;
    import net.minecraft.item.Item;
    import net.minecraft.item.ItemStack;
    import net.minecraft.world.World;
    
    public class ItemBarley extends Item {
    
    	public ItemBarley(Properties properties) {
    		super(properties);
    	}
    
    	@Override
    	public boolean hasCustomEntity(ItemStack itemstack) {
    		return true;
    	}
    	
    	@Override
    	public Entity createEntity(World world, Entity location, ItemStack itemstack) {
    		return new FarmCraftItemEntity(EntityInit.ITEM_ENTITY.get(), world);
    	}
    }

     

  14. package cz.grossik.farmcraft.entity;
    
    import cz.grossik.farmcraft.init.ItemInit;
    import net.minecraft.entity.EntityType;
    import net.minecraft.entity.item.ItemEntity;
    import net.minecraft.item.ItemStack;
    import net.minecraft.network.IPacket;
    import net.minecraft.world.World;
    import net.minecraftforge.fml.network.NetworkHooks;
    
    public class FarmCraftItemEntity extends ItemEntity {
    		
    	public FarmCraftItemEntity(EntityType<? extends ItemEntity> p_i50217_1_, World p_i50217_2_) {
    		super(p_i50217_1_, p_i50217_2_);
    	}
    	   
    	@Override
    	public IPacket<?> createSpawnPacket() {
    		return NetworkHooks.getEntitySpawningPacket(this);
    	}
    	   
    	@Override
    	public void tick() {
    		System.err.println("tick");
    		if(this.isInWater()) {
    			System.err.println("water");
    			ItemStack newItemStack = new ItemStack(ItemInit.soaked_barley.get());
    			ItemEntity newItem = new ItemEntity(this.world, this.getPosition().getX(), this.getPosition().getY(), this.getPosition().getZ(), newItemStack);
    			this.world.addEntity(newItem);
    			this.remove();
    		}
    		super.tick();
    	}
    }

     

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.