Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

How do I have use mulitple textures for one item such as a compass.


Melonize
 Share

Recommended Posts

How do I have use mulitple textures for one item such as a compass or clock. I tried searching through the tutorials in the wiki but I couldn't find anything (I might be wrong, I don't spot things easily.). I've took a look in the TextureCompass.java but I had some issue trying to find what I wanted.

 

Scenario:

I'm currently making a sword which I want to switch textures when the player right clicks.

 

Any ideas?

Link to comment
Share on other sites

For that you just need to check when the player right clicks, store that state in a boolean, so when he right clicks one time, the boolean is true, and the second time it is false, then just put check for the variable if it is true in the registerIcons() function, and set a new texture based on the state of the variable.

Link to comment
Share on other sites

I seem to be getting a null somewhere, as the game crashes. I clearly don't know where the problem is or if I'm even doing it right.

        public boolean isSwitched = false;
public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer){
	if(isSwitched){
		isSwitched = false;
	}
	else{
		isSwitched = true;
	}
	par3EntityPlayer.setItemInUse(par1ItemStack, this.getMaxItemUseDuration(par1ItemStack));
                return par1ItemStack;
}
public void registerIcon(IconRegister par1IconRegister){
	if(isSwitched){
	        this.itemIcon = par1IconRegister.registerIcon("shadowRapier2");
	} else {
		this.itemIcon = par1IconRegister.registerIcon("shadowRapier1");
	}
}

Link to comment
Share on other sites

public void registerIcon(IconRegister par1IconRegister){
	if(isSwitched){
	        this.itemIcon = par1IconRegister.registerIcon("shadowRapier2");
	} else {
		this.itemIcon = par1IconRegister.registerIcon("shadowRapier1");
	}
}

 

You're doing this wrong.

 

You need to register BOTH icons at the same time as the registerIcon function is called ONCE.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Override public Icon getIconFromDamage(int par1)

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hello, I am trying to launch a mod pack i made for forge 1.12.2 but every time I launch the pack it fails with exit code 1.   crash log: https://pastebin.com/06SkS9CF debug log: https://pastebin.com/2k7jxBqb
    • I'm trying to sync player capabilities from server to client using packets. I've researched about this topic a lot, but man is it confusing. I'm trying to update the players data on the client side when the player logs in, respawns, and when they change dimension. I also do so with the event StartTracking. Here are those events: @SubscribeEvent public void onPlayerTracking(PlayerEvent.StartTracking event) { if(event.getTarget() instanceof PlayerEntity) { PlayerEntity player = (PlayerEntity)event.getTarget(); ServerPlayerEntity target = (ServerPlayerEntity)event.getPlayer(); if(!player.getCommandSenderWorld().isClientSide()) { player.getCapability(TitanShiftersProvider.TITAN_SHIFTERS_CAPABILITY).ifPresent(capability -> { CompoundNBT nbt = new CompoundNBT(); Capability<ITitanShifters> cap = TitanShiftersProvider.TITAN_SHIFTERS_CAPABILITY; Capability.IStorage<ITitanShifters> storage = cap.getStorage(); nbt.put(cap.getName(), storage.writeNBT(cap, capability, TitanShiftersMod.direction)); ClientMessage message = new ClientMessage(nbt); TitanShiftersNetwork.CLIENTCHANNEL.send(PacketDistributor.PLAYER.with(() -> target), message); }); } } } @SubscribeEvent public void onPlayerLogin(PlayerLoggedInEvent event) { ServerPlayerEntity player = (ServerPlayerEntity)event.getPlayer(); if(!player.getCommandSenderWorld().isClientSide()) { player.getCapability(TitanShiftersProvider.TITAN_SHIFTERS_CAPABILITY).ifPresent(capability -> { CompoundNBT nbt = new CompoundNBT(); Capability<ITitanShifters> cap = TitanShiftersProvider.TITAN_SHIFTERS_CAPABILITY; Capability.IStorage<ITitanShifters> storage = cap.getStorage(); nbt.put(cap.getName(), storage.writeNBT(cap, capability, TitanShiftersMod.direction)); ClientMessage message = new ClientMessage(nbt); TitanShiftersNetwork.CLIENTCHANNEL.send(PacketDistributor.PLAYER.with(() -> player), message); }); } } @SubscribeEvent public void onPlayerRespawn(PlayerRespawnEvent event) { ServerPlayerEntity player = (ServerPlayerEntity)event.getPlayer(); if(!player.getCommandSenderWorld().isClientSide()) { player.getCapability(TitanShiftersProvider.TITAN_SHIFTERS_CAPABILITY).ifPresent(capability -> { CompoundNBT nbt = new CompoundNBT(); Capability<ITitanShifters> cap = TitanShiftersProvider.TITAN_SHIFTERS_CAPABILITY; Capability.IStorage<ITitanShifters> storage = cap.getStorage(); nbt.put(cap.getName(), storage.writeNBT(cap, capability, TitanShiftersMod.direction)); ClientMessage message = new ClientMessage(nbt); TitanShiftersNetwork.CLIENTCHANNEL.send(PacketDistributor.PLAYER.with(() -> player), message); }); } } @SubscribeEvent public void onPlayerChangeDimension(PlayerChangedDimensionEvent event) { ServerPlayerEntity player = (ServerPlayerEntity)event.getPlayer(); if(!player.getCommandSenderWorld().isClientSide()) { player.getCapability(TitanShiftersProvider.TITAN_SHIFTERS_CAPABILITY).ifPresent(capability -> { CompoundNBT nbt = new CompoundNBT(); Capability<ITitanShifters> cap = TitanShiftersProvider.TITAN_SHIFTERS_CAPABILITY; Capability.IStorage<ITitanShifters> storage = cap.getStorage(); nbt.put(cap.getName(), storage.writeNBT(cap, capability, TitanShiftersMod.direction)); ClientMessage message = new ClientMessage(nbt); TitanShiftersNetwork.CLIENTCHANNEL.send(PacketDistributor.PLAYER.with(() -> player), message); }); } } Here is the packet I am sending: public class ClientMessage { private CompoundNBT data; public ClientMessage(CompoundNBT d) { data = d; } public static void encode(ClientMessage message, PacketBuffer buffer) { buffer.writeNbt(message.data); } public static ClientMessage decode(PacketBuffer buffer) { return new ClientMessage(buffer.readNbt()); } public static void handle(ClientMessage message, Supplier<NetworkEvent.Context> supplier) { NetworkEvent.Context context = supplier.get(); context.enqueueWork(() -> { if(context.getDirection().getReceptionSide().isClient() && context.getDirection().getOriginationSide().isServer()) { @SuppressWarnings("resource") ClientPlayerEntity p = Minecraft.getInstance().player; p.getEntity().getCapability(TitanShiftersProvider.TITAN_SHIFTERS_CAPABILITY).ifPresent(capability -> { Capability.IStorage<ITitanShifters> storage = TitanShiftersProvider.TITAN_SHIFTERS_CAPABILITY.getStorage(); storage.readNBT(TitanShiftersProvider.TITAN_SHIFTERS_CAPABILITY, capability, TitanShiftersMod.direction, message.data); }); } }); context.setPacketHandled(true); } } Here is my network class: (I made two networks for sending packets to server and to client) public class TitanShiftersNetwork { private static int id = 0; public static final String NETWORK_VERSION = "0.1.0"; private static ResourceLocation loc = new ResourceLocation(TitanShiftersMod.MOD_ID, "network"); private static ResourceLocation Clientloc = new ResourceLocation(TitanShiftersMod.MOD_ID, "networkclient"); public static final SimpleChannel CHANNEL = NetworkRegistry.newSimpleChannel(loc, () -> NETWORK_VERSION, version -> version.equals(NETWORK_VERSION), version -> version.equals(NETWORK_VERSION)); public static final SimpleChannel CLIENTCHANNEL = NetworkRegistry.ChannelBuilder.named(Clientloc).clientAcceptedVersions(s -> Objects.equals(s, "1")) .serverAcceptedVersions(s -> Objects.equals(s, "1")).networkProtocolVersion(() -> "1").simpleChannel(); public static void init() { CHANNEL.registerMessage(0, InputMessage.class, InputMessage::encode, InputMessage::decode, InputMessage::handle); CLIENTCHANNEL.messageBuilder(ClientMessage.class, id++).decoder(ClientMessage::decode).encoder(ClientMessage::encode).consumer(ClientMessage::handle).add(); } } Here is where the Init() method is being called: @SubscribeEvent public void commonSetup(final FMLCommonSetupEvent event) { TitanShiftersNetwork.init(); } And here is where I am trying to update the data on the client side: public static void InheritAttack(PlayerEntity player) { LazyOptional<ITitanShifters> titan = player.getCapability(TitanShiftersProvider.TITAN_SHIFTERS_CAPABILITY, TitanShiftersMod.direction); ITitanShifters titanShifter = titan.orElse(new TitanShifters()); TitanShiftersStats.setAttackTitan(true, player); pureUnshift(player); System.out.println(player.getScoreboardName() + " is pure titan: " + titanShifter.getPureTitan().toString()); ServerPlayerEntity p = (ServerPlayerEntity)player; if(!p.getCommandSenderWorld().isClientSide()) { p.getCapability(TitanShiftersProvider.TITAN_SHIFTERS_CAPABILITY).ifPresent(capability -> { CompoundNBT nbt = new CompoundNBT(); Capability<ITitanShifters> cap = TitanShiftersProvider.TITAN_SHIFTERS_CAPABILITY; Capability.IStorage<ITitanShifters> storage = cap.getStorage(); nbt.put(cap.getName(), storage.writeNBT(cap, capability, TitanShiftersMod.direction)); ClientMessage message = new ClientMessage(nbt); TitanShiftersNetwork.CLIENTCHANNEL.send(PacketDistributor.TRACKING_ENTITY_AND_SELF.with(() -> p), message); }); } System.out.println(player.getScoreboardName() + " has inherited the attack titan!"); } Rest of the code is here: https://github.com/TheDerpyParagon/TitanShiftersMod Any help is much appreciated!
    • When I downloaded forge and installed the client version it didn't make a extension so I went to the extension tab and tried to find it but it wasn't there I tried to download previous versions of it but they don't make an extension if someone could help that would be nice!
    • al instalar forge versión 1.18.2 (40.1.0) arroja un error: Failed to download version manifest, can not find client jar URL. que debería hacer?
    • I can now!!!! Thank you so much! I did what you say of putting more time to join and i delete cache (just in case) and i can now, thank you so much 😭
  • Topics

×
×
  • Create New...

Important Information

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