Skip to content

Commit

Permalink
Add block builders
Browse files Browse the repository at this point in the history
Signed-off-by: TheSilkMiner <thesilkminer@outlook.com>
  • Loading branch information
TheSilkMiner committed Jun 18, 2022
1 parent 12c56d6 commit f1777de
Show file tree
Hide file tree
Showing 23 changed files with 2,117 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.blamejared.contenttweaker.core.api.zen.util;

import com.blamejared.contenttweaker.core.api.ContentTweakerConstants;
import com.blamejared.contenttweaker.core.api.zen.ContentTweakerZenConstants;
import com.blamejared.crafttweaker.api.annotation.ZenRegister;
import org.openzen.zencode.java.ZenCodeType;

@ZenCodeType.Name(ContentTweakerZenConstants.UTIL_PACKAGE + ".Color")
@ZenRegister(loaders = ContentTweakerConstants.CONTENT_LOADER_ID)
public final class Color {
private final int color;

private Color(final int color) {
this.color = color;
}

@ZenCodeType.Method("packedRgba")
public static Color packedRgba(final int color) {
return new Color(color);
}

@ZenCodeType.Method("packedRgb")
public static Color packedRgb(final int color) {
return packedRgba((color << 8) | 0xFF);
}

@ZenCodeType.Method("rgba")
public static Color rgba(final int r, final int g, final int b, final int a) {
return packedRgba(((r & 0xFF) << 24) | ((g & 0xFF) << 16) | ((b & 0xFF) << 8) | (a & 0xFF));
}

@ZenCodeType.Method("rgb")
public static Color rgb(final int r, final int g, final int b) {
return rgba(r, g, b, 0xFF);
}

@ZenCodeType.Getter("r")
public int r() {
return (this.color >> 24) & 0xFF;
}

@ZenCodeType.Getter("g")
public int g() {
return (this.color >> 16) & 0xFF;
}

@ZenCodeType.Getter("b")
public int b() {
return (this.color >> 8) & 0xFF;
}

@ZenCodeType.Getter("a")
public int a() {
return this.color & 0xFF;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
import com.blamejared.contenttweaker.core.api.plugin.FactoryMappingRegistration;
import com.blamejared.contenttweaker.core.api.plugin.ObjectTypeRegistration;
import com.blamejared.contenttweaker.core.api.plugin.ReferenceFactoryRegistration;
import com.blamejared.contenttweaker.vanilla.api.zen.object.BlockReference;
import com.blamejared.contenttweaker.vanilla.api.zen.object.SoundEventReference;
import com.blamejared.contenttweaker.vanilla.object.VanillaObjectTypes;
import com.blamejared.contenttweaker.vanilla.zen.bracket.ContentTweakerVanillaBrackets;
import com.blamejared.contenttweaker.vanilla.zen.factory.BlockFactory;
import com.blamejared.contenttweaker.vanilla.zen.factory.ItemFactory;
import com.blamejared.contenttweaker.vanilla.api.zen.object.ItemReference;
import com.blamejared.contenttweaker.vanilla.zen.factory.SoundEventFactory;
Expand All @@ -20,19 +22,22 @@
public final class ContentTweakerVanillaPlugin implements ContentTweakerPluginProvider {
@Override
public void registerObjectTypes(final ObjectTypeRegistration registration) {
registration.registerType(VanillaObjectTypes.BLOCK);
registration.registerType(VanillaObjectTypes.ITEM);
registration.registerType(VanillaObjectTypes.SOUND_EVENT);
}

@Override
public void registerFactoryMappings(final FactoryMappingRegistration registration) {
registration.registerMapping(VanillaObjectTypes.BLOCK, BlockFactory.class);
registration.registerMapping(VanillaObjectTypes.ITEM, ItemFactory.class);
registration.registerMapping(VanillaObjectTypes.SOUND_EVENT, SoundEventFactory.class);
}

@Override
@SuppressWarnings("Convert2Diamond") // This breaks javac (^-^)
public void registerReferenceFactories(final ReferenceFactoryRegistration registration) {
registration.register(VanillaObjectTypes.BLOCK, ReferenceFactory.of(new TypeToken<BlockReference>() {}, BlockReference::of));
registration.register(VanillaObjectTypes.ITEM, ReferenceFactory.of(new TypeToken<ItemReference>() {}, ItemReference::of));
registration.register(VanillaObjectTypes.SOUND_EVENT, ReferenceFactory.of(new TypeToken<SoundEventReference>() {}, SoundEventReference::of));
}
Expand Down

0 comments on commit f1777de

Please sign in to comment.