Skip to content

Commit

Permalink
Some more work on Basic items
Browse files Browse the repository at this point in the history
  • Loading branch information
kindlich committed Apr 22, 2020
1 parent b762862 commit 7fd14c2
Show file tree
Hide file tree
Showing 9 changed files with 225 additions and 292 deletions.
10 changes: 10 additions & 0 deletions build.gradle
Expand Up @@ -45,6 +45,10 @@ minecraft {
contenttweaker {
source sourceSets.main
}

crafttweaker {
source project(":CraftTweaker").sourceSets.main
}
}
}

Expand All @@ -55,6 +59,9 @@ minecraft {
contenttweaker {
source sourceSets.main
}
crafttweaker {
source project(":CraftTweaker").sourceSets.main
}
}
}

Expand All @@ -67,6 +74,9 @@ minecraft {
contenttweaker {
source sourceSets.main
}
crafttweaker {
source project(":CraftTweaker").sourceSets.main
}
}
}
}
Expand Down
22 changes: 19 additions & 3 deletions src/main/java/com/blamejared/contenttweaker/ContentTweaker.java
@@ -1,24 +1,40 @@
package com.blamejared.contenttweaker;

import com.blamejared.crafttweaker.api.*;
import net.minecraft.item.*;
import net.minecraftforge.event.*;
import net.minecraftforge.fml.common.*;
import net.minecraftforge.fml.event.lifecycle.*;
import net.minecraftforge.fml.javafmlmod.*;
import net.minecraftforge.registries.*;
import org.apache.logging.log4j.*;

@Mod("contenttweaker")
public class ContentTweaker {

public static final String MODID = "@MODID@";
public static final String NAME = "@NAME@";
public static final String MOD_ID = "contenttweaker";
public static final String NAME = "ContentTweaker";

public static final Logger LOG = LogManager.getLogger(NAME);

public ContentTweaker() {
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::registerItems);
}

private void setup(final FMLCommonSetupEvent event) {
VanillaFactory.registerLocked = true;
LOG.info("{} has loaded successfully!", NAME);
}

private void registerItems(final RegistryEvent.Register<Item> registryEvent){
if(registryEvent.getRegistry() != ForgeRegistries.ITEMS) {
//Why though?
return;
}

CraftTweakerAPI.logWarning("Hello from CoT!");
VanillaFactory.registry = registryEvent.getRegistry();
CraftTweakerAPI.loadScripts(new ScriptLoadingOptions().execute().setLoaderName(MOD_ID));
VanillaFactory.registerLocked = true;
}
}
20 changes: 17 additions & 3 deletions src/main/java/com/blamejared/contenttweaker/VanillaFactory.java
@@ -1,11 +1,13 @@
package com.blamejared.contenttweaker;

import com.blamejared.contenttweaker.items.*;
import com.blamejared.contenttweaker.items.wrappers.*;
import com.blamejared.crafttweaker.api.*;
import com.blamejared.crafttweaker.api.actions.*;
import com.blamejared.crafttweaker.api.annotations.*;
import com.blamejared.crafttweaker.api.logger.*;
import com.blamejared.crafttweaker.impl.util.*;
import net.minecraft.item.*;
import net.minecraft.util.*;
import net.minecraftforge.fml.*;
import net.minecraftforge.registries.*;
Expand All @@ -16,9 +18,16 @@
public class VanillaFactory {

public static boolean registerLocked = false;
public static IForgeRegistry<Item> registry = null;

@ZenCodeType.Method
public static void registerItem(MCItemProperties properties, String name){
registerItem(new MCItemRepresentation(properties), name);
}

@ZenCodeType.Method
public static void registerItem(MCItemRepresentation representation, String name) {
registerItem(representation, new MCResourceLocation(new ResourceLocation(ContentTweaker.MODID, name)));
registerItem(representation, new MCResourceLocation(new ResourceLocation(ContentTweaker.MOD_ID, name)));
}

@ZenCodeType.Method
Expand All @@ -33,14 +42,19 @@ public void apply() {
@Override
public String describe() {
return String.format("Registering item %s with resource location %s", representation
.getDisplayName(), resourceLocation.getCommandString());
.toString(), resourceLocation.getCommandString());
}

@Override
public boolean validate(ILogger logger) {
if(registry == null){
logger.error("Registering items too early");
return false;
}

if(registerLocked) {
logger.error("Cannot register items after setupCommon!");
logger.error("Ignoring Registration for item " + representation.getDisplayName());
logger.error("Ignoring Registration for item " + representation.toString());
return false;
}

Expand Down
@@ -0,0 +1,22 @@
package com.blamejared.contenttweaker.items;

import com.blamejared.contenttweaker.items.wrappers.*;
import com.blamejared.crafttweaker.api.annotations.*;
import net.minecraft.item.*;
import org.openzen.zencode.java.*;

import java.util.*;

@ZenRegister
@ZenCodeType.Name("mods.contenttweaker.BracketHandlers")
public class BracketHandlers {

@BracketResolver("itemgroup")
public static MCItemGroup getItemGroup(String tokens) {
return Arrays.stream(ItemGroup.GROUPS)
.filter(g -> g.getPath().equals(tokens))
.map(MCItemGroup::new)
.findAny()
.orElseThrow(() -> new IllegalArgumentException("Could not find itemgroup for '<itemgroup:" + tokens + ">'!"));
}
}

0 comments on commit 7fd14c2

Please sign in to comment.