Giter Site home page Giter Site logo

attachment's Introduction

Attachment

Attach custom data to Entities, Worlds, and ItemStacks (NbtCompounds)

Gradle

repositories {
    maven {
        url = uri("https://storage.googleapis.com/devan-maven/")
    }
}

dependencies {
  modApi(include("net.devtech:Attachment:1.3.0"))
}

Entity

public class MyAttachments {
	public static final Identifier ID = new Identifier("mymod:entity_attachment");
	// all settings are optional
	public static final Attachment<Entity, Integer> ENTITY_ATTACHMENT = Attachments.ENTITY.registerAttachment(
			EntityAttachmentSetting.serializer(ID, Codec.INT), // saves the data when the entity is written to the disk
            EntityAttachmentSetting.preserveRespawn(), // copies over the data from the old to new player when they respawn
            EntityAttachmentSetting.sync(ID, TrackedDataHandlerRegistry.INTEGER) // syncs the data to the client
    );
}

World

World attachments are bound to BlockRenderView to allow them to be used in BakedModel rendering

public class MyAttachments {
	public static final Identifier ID = new Identifier("mymod:world_attachment");
	// all settings are optional
	public static final Attachment<BlockRenderView, Integer> WORLD_ATTACHMENT = Attachments.WORLD.registerAttachment(
			WorldAttachmentSetting.serializer(ID, Codec.INT), // saves the data when the world is written to the disk
            WorldAttachmentSetting.sync(ID, TrackedDataHandlerRegistry.INTEGER) // syncs the data to the client
    );
}

Item / NbtCompound

Nbt attachments are bound to NbtCompound to allow them to be used in ItemStacks and regular Nbt.

public class MyAttachments {
	public static final Identifier ID = new Identifier("mymod:item_attachment");
	// all settings are optional, but recommended
	public static final Attachment<NbtCompound, Integer> NBT_ATTACHMENT = Attachments.NBT.registerAttachment(
			NbtAttachmentSetting.serializer(ID, Codec.INT) // saves the data when the nbt tag is written to the disk
    );
	
	public static void set(ItemStack stack, int value) {
		NBT_ATTACHMENT.setValue(stack.getOrCreateNbt(), value);
    }
}

Server

public class MyAttachments {
	public static final Identifier ID = new Identifier("mymod:server_attachment");
	// all settings are optional, but recommended
	public static final Attachment<ServerRef, Integer> NBT_ATTACHMENT = Attachments.SERVER.registerAttachment(
			ServerAttachmentSetting.serializer(ID, Codec.INT), // saves the data when the nbt tag is written to the disk
			ServerAttachmentSetting.sync(ID, TrackedDataHandlerRegistry.INTEGER) // syncs the data to the client
	
	);
	
	public static void set(ServerRef stack, int value) {
		NBT_ATTACHMENT.setValue(stack.getOrCreateNbt(), value);
    }
}

attachment's People

Contributors

devan-kerman avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.