Jump to content

Tschipp

Forge Modder
  • Posts

    307
  • Joined

  • Last visited

Posts posted by Tschipp

  1. I'm trying to check if an ItemStack has the FluidHandler capability.

    For that I tried using this:

    		boolean hasCap = stack.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null);

    The ItemStack passed was a ItemWaterBucket. I've also tried it using forge filled buckets, but both alway return false. Am I checking for the wrong capability?

  2. I have an item that changes its appearance based on nbt. For that I made a custom IBakedModel with a custom ItemOverrideList

    What i now do in the ItemOverrideList#handleItemState method is create a new SimpleBakedModel, that I create from the parent model of an itemstack. I know sounds confusing, let's just show the code:

    ItemOverrideList:

    public static class OverrideList extends ItemOverrideList
    	{
    
    		public OverrideList(List<ItemOverride> overridesIn) {
    			super(overridesIn);
    		}
    
    
    		@Override
    		public IBakedModel handleItemState(IBakedModel originalModel, ItemStack stack, World world, EntityLivingBase entity)
    		{
    			if(stack.hasTagCompound() && stack.getTagCompound().hasKey("block") && stack.getTagCompound().hasKey("meta"))
    			{
    				Block block = Block.getBlockFromName(stack.getTagCompound().getString("block"));
    				int meta = stack.getTagCompound().getInteger("meta");
    
    				IBlockState state = block.getDefaultState();
    
    				meta = meta - 12;
    
    				ItemStack blockstack = new ItemStack(block, 1, meta);
    
    				IBakedModel parentmodel = Minecraft.getMinecraft().getRenderItem().getItemModelMesher().getItemModel(blockstack);
    
    				TextureAtlasSprite side = parentmodel.getParticleTexture();
    
    				Map<EnumFacing, List<BakedQuad>> map = new HashMap<EnumFacing, List<BakedQuad>>();
    				
    				List<BakedQuad> quadsup = parentmodel.getQuads(state, EnumFacing.UP, 0);
    				BakedQuadRetextured up = new BakedQuadRetextured(quadsup.get(0), side);				
    				quadsup.set(0,up);
    				
    				List<BakedQuad> quadsdown = parentmodel.getQuads(state, EnumFacing.DOWN, 0);
    				BakedQuadRetextured down = new BakedQuadRetextured(quadsdown.get(0), side);				
    				quadsdown.set(0,down); 
    				
    				map.put(EnumFacing.DOWN, quadsdown);
    				map.put(EnumFacing.UP, quadsup);
    				map.put(EnumFacing.NORTH, parentmodel.getQuads(state, EnumFacing.NORTH, 1));
    				map.put(EnumFacing.SOUTH, parentmodel.getQuads(state, EnumFacing.SOUTH, 1));
    				map.put(EnumFacing.WEST, parentmodel.getQuads(state, EnumFacing.WEST, 1));
    				map.put(EnumFacing.EAST, parentmodel.getQuads(state, EnumFacing.EAST, 1));
    				
    
    				SimpleBakedModel model = new SimpleBakedModel(new ArrayList(), map, parentmodel.isAmbientOcclusion(), parentmodel.isGui3d(), side, parentmodel.getItemCameraTransforms(), ItemOverrideList.NONE);
    				return model;
    			}
    			return Minecraft.getMinecraft().getRenderItem().getItemModelMesher().getItemModel(new ItemStack(Blocks.LOG));
    		}
    
    
    	}

    So what's happening is I'm getting a block with metadata stored in nbt of the itemstack. Then I create an ItemStack from that block and metatdata. Then I get the BakedModel for that ItemStack, and also extract the particle texture. Then I create a new map which contains all the BakedQuads. The BakedQuads I get from the parentModel. I also edit the top and bottom quad, to change the texture, so I replace them in the list with a BakedQuadRetextured. Finally, I create the SimpleBakedModel and return it.

     

    The problem now is this:

    https://gyazo.com/29de5fec9915a801d0f4dae029bc37c4

     

    First of all, it cycles through every texture for the top quad. The bottom quad remains unchanged. 

    It also changes the top quad for vanilla log blocks, idk how that's happening.

     

    I'm applying the BakedModel in the ModelBakeEvent:

    @SubscribeEvent
    	public void onModelBake(ModelBakeEvent event)
    	{
    		Object object =  event.getModelRegistry().getObject(new ModelResourceLocation("barkifier:barkified_log", "inventory"));
    	    if (object instanceof IBakedModel) {
    	      IBakedModel existingModel = (IBakedModel)object;
    	      BarkifiedLogsRendering.Model customModel = new  BarkifiedLogsRendering.Model(existingModel);
    	      event.getModelRegistry().putObject(new ModelResourceLocation("barkifier:barkified_log", "inventory"), customModel);
    	    } 
    	}

     

    Also, my IBakedModel:

    public static class Model implements IPerspectiveAwareModel
    	{
    
    		private IBakedModel base;
    		private OverrideList overrides;
    
    		public Model(IBakedModel base) {
    
    			this.base = base;
    			this.overrides = new OverrideList(Collections.EMPTY_LIST);
    
    		}
    
    		@Override
    		public List<BakedQuad> getQuads(IBlockState state, EnumFacing side, long rand) {
    			return base.getQuads(state, side, rand);
    		}
    
    		@Override
    		public boolean isAmbientOcclusion() {
    			return base.isAmbientOcclusion();
    		}
    
    		@Override
    		public boolean isGui3d() {
    			return base.isGui3d();
    		}
    
    		@Override
    		public boolean isBuiltInRenderer() {
    			return base.isBuiltInRenderer();
    		}
    
    		@Override
    		public TextureAtlasSprite getParticleTexture() {
    			return base.getParticleTexture();
    		}
    
    		@Override
    		public ItemCameraTransforms getItemCameraTransforms() {
    			return base.getItemCameraTransforms();
    		}
    
    		@Override
    		public ItemOverrideList getOverrides() {
    			return overrides;
    		}
    
    		@Override
    		public Pair<? extends IBakedModel, Matrix4f> handlePerspective(ItemCameraTransforms.TransformType cameraTransformType) {
    			if (base instanceof IPerspectiveAwareModel) {
    				Matrix4f matrix4f = ((IPerspectiveAwareModel)base).handlePerspective(cameraTransformType).getRight();
    				return Pair.of(this, matrix4f);
    			} else {
    				// If the base model isn't an IPerspectiveAware, we'll need to generate the correct matrix ourselves using the
    				//  ItemCameraTransforms.
    
    				ItemCameraTransforms itemCameraTransforms = base.getItemCameraTransforms();
    				ItemTransformVec3f itemTransformVec3f = itemCameraTransforms.getTransform(cameraTransformType);
    				TRSRTransformation tr = new TRSRTransformation(itemTransformVec3f);
    				Matrix4f mat = null;
    				if (tr != null) { // && tr != TRSRTransformation.identity()) {
    					mat = tr.getMatrix();
    				}
    				// The TRSRTransformation for vanilla items have blockCenterToCorner() applied, however handlePerspective
    				//  reverses it back again with blockCornerToCenter().  So we don't need to apply it here.
    
    				return Pair.of(this, mat);
    			}
    		}
    
    
    
    	}

    I really hope someone can help me with this, I cannot explain how this is happening.

  3. 18 minutes ago, larsgerrits said:

    It's an old, bad API which is still used by Minecraft itself, while capabilities are added by Forge to offer much better compatibility between mods. If you still use IInventory/ISidedInventory, most mods wouldn't know how to interact with your inventories, and can't be used in automation.

    Ok, I see. But in this case, automation really doesn't matter. The block just gives you some text information about the item that you put in, so it's only useable by players. I'll still take a look at the capability thing, in the long run it seems less complicated.

  4. 9 hours ago, Kokkie said:

    Why all this? You can also just check once if it isn't EnumFacing.DOWN...

    Whoops xD

     

    But still, I removed all this and just return true all the time, I also added a print statement... nothing. The method is supposed to be executed when a hopper tries to insert an item into the machine, right? Becasue the ISidedInventory#canExtractItem method gets executed when a hopper tries to pull items out of it...

  5. 7 hours ago, Choonster said:

     

    They can, using AnimationModelBase. This also allows the model to be animated with Forge's baked model animation system.

    Oh. I guess so, learned something new

  6. I want to make it so that a slot from my machine is accessable from up and all the sides, but the  ISidedInventory#canInsertItem method doesn't seem to get called... ever. I've checked with the debug tool.

    This is my method, but as I said it isn't even being called.. Am I understanding something wrong?

     

    @Override
    	public boolean canInsertItem(int index, ItemStack stack, EnumFacing direction) {
    		return  (direction == EnumFacing.EAST || direction == EnumFacing.NORTH || direction == EnumFacing.SOUTH || direction == EnumFacing.WEST || direction == EnumFacing.UP) && index == 9;
    	}

     

  7. 49 minutes ago, recneps said:

    I'd just put it in the code right before it checks if you're wearing the armour.. That way it sets it to 0 each time and then increases it afterwards.

    Hm. It doesn't seem to be possible to set the attributes for a player, it's only possible to get them. Did you have anything other in mind?

     

    EDIT: I figured it out, the attribute had no valid UUID

  8. 23 minutes ago, recneps said:

    It seems to me like the error is it not resetting the knockback resistance of the player. It increases it by .25 if the player is wearing the armour, but does it ever set it to 0? Or does it just increase it each time the code runs?

    No, I don't set it to 0 ever. I thought somethink like that was done automatically, when the armor gets unequipped. Like when you're holding a sword that boosts your speed, switching off that sword also removes your speed. But I can try and see if that's the reason.

×
×
  • Create New...

Important Information

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