Skip to content

Commit

Permalink
made AntimatterPlatformUtils a java service
Browse files Browse the repository at this point in the history
  • Loading branch information
Trinsdar committed Oct 18, 2024
1 parent 5d709df commit 228991f
Show file tree
Hide file tree
Showing 48 changed files with 398 additions and 483 deletions.
4 changes: 2 additions & 2 deletions common/src/main/java/muramasa/antimatter/Antimatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,9 @@ public void onRegistrationEvent(RegistrationEvent event, Side side) {
if (map != null){
map.forEach((t, i) -> {
if (t instanceof MaterialTypeItem<?> typeItem){
AntimatterPlatformUtils.setBurnTime(typeItem.get(m), i);
AntimatterPlatformUtils.INSTANCE.setBurnTime(typeItem.get(m), i);
} else if (t instanceof MaterialTypeBlock<?> typeBlock && typeBlock.get() instanceof MaterialTypeBlock.IBlockGetter blockGetter){
AntimatterPlatformUtils.setBurnTime(blockGetter.get(m).asItem(), i);
AntimatterPlatformUtils.INSTANCE.setBurnTime(blockGetter.get(m).asItem(), i);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ public static void onRegistration(RegistrationEvent event) {
Antimatter.LOGGER.info("Registration event " + event);
Side side = getSIDE();
if (!REGISTRATION_EVENTS_HANDLED.add(event)) {
if (AntimatterPlatformUtils.isForge() && AntimatterPlatformUtils.getActiveNamespace().equals(Ref.ID))
if (AntimatterPlatformUtils.INSTANCE.isForge() && AntimatterPlatformUtils.INSTANCE.getActiveNamespace().equals(Ref.ID))
return;
throw new IllegalStateException("The RegistrationEvent " + event.name() + " has already been handled");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public static void createConfig(){
AXE_TIMBER = treefelling.addBool("axe_timber", true, "Allow Antimatter Axe types to fell trees - Default: true");
AXE_TIMBER_MAX = treefelling.addInt("axe_timber_max", 150, "Max height of a column of logs an Antimatter Axe type can fell - Default: 150")
.setMin(1).setMax(2304);
CONFIG_COMMON = AntimatterPlatformUtils.createConfig(Ref.ID, config);
CONFIG_COMMON = AntimatterPlatformUtils.INSTANCE.createConfig(Ref.ID, config);
CONFIG_COMMON.register();
if (AntimatterAPI.getSIDE().isClient()){
Config client = new Config("antimatter/client");
Expand All @@ -140,7 +140,7 @@ public static void createConfig(){
SHOW_ALL_ORES = general.addBool("show_all_ores", false, "Show all ore variants in jei/rei, not just stone variants - Default: false");
SHOW_ROCKS = general.addBool("show_rocks", false, "Show all block versions of rocks in jei/rei - Default: false");
OVERRIDE_BASALT_TEXTURE = general.addBool("override_basalt_texture", false, "Override vanilla basalt texture why my own version - Default: false").setRequiredReload(ReloadMode.GAME);
CONFIG_CLIENT = AntimatterPlatformUtils.createConfig(Ref.ID, client, ConfigSettings.withConfigType(ConfigType.CLIENT).withAutomations(AutomationType.AUTO_LOAD));
CONFIG_CLIENT = AntimatterPlatformUtils.INSTANCE.createConfig(Ref.ID, client, ConfigSettings.withConfigType(ConfigType.CLIENT).withAutomations(AutomationType.AUTO_LOAD));
CONFIG_CLIENT.register();
}
}
Expand Down
10 changes: 5 additions & 5 deletions common/src/main/java/muramasa/antimatter/Ref.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ public class Ref {
/**
* Creative Tabs
**/
public static final CreativeModeTab TAB_ITEMS = AntimatterPlatformUtils.createTab(ID, "items", () -> new ItemStack(Data.DEBUG_SCANNER));
public static final CreativeModeTab TAB_TOOLS = AntimatterPlatformUtils.createTab(ID, "tools", () -> new ItemStack(Data.DEBUG_SCANNER));
public static final CreativeModeTab TAB_BLOCKS = AntimatterPlatformUtils.createTab(ID, "blocks", () -> new ItemStack(Data.DEBUG_SCANNER));
public static final CreativeModeTab TAB_MATERIALS = AntimatterPlatformUtils.createTab(ID, "materials", () -> new ItemStack(Data.DEBUG_SCANNER));
public static final CreativeModeTab TAB_MACHINES = AntimatterPlatformUtils.createTab(ID, "machines", () -> new ItemStack(Data.DEBUG_SCANNER));
public static final CreativeModeTab TAB_ITEMS = AntimatterPlatformUtils.INSTANCE.createTab(ID, "items", () -> new ItemStack(Data.DEBUG_SCANNER));
public static final CreativeModeTab TAB_TOOLS = AntimatterPlatformUtils.INSTANCE.createTab(ID, "tools", () -> new ItemStack(Data.DEBUG_SCANNER));
public static final CreativeModeTab TAB_BLOCKS = AntimatterPlatformUtils.INSTANCE.createTab(ID, "blocks", () -> new ItemStack(Data.DEBUG_SCANNER));
public static final CreativeModeTab TAB_MATERIALS = AntimatterPlatformUtils.INSTANCE.createTab(ID, "materials", () -> new ItemStack(Data.DEBUG_SCANNER));
public static final CreativeModeTab TAB_MACHINES = AntimatterPlatformUtils.INSTANCE.createTab(ID, "machines", () -> new ItemStack(Data.DEBUG_SCANNER));

/**
* Sound Events
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public InteractionResult use(BlockState state, Level level, BlockPos pos, Player
if (fakeBlock.getController() != null){
if (fakeBlock.getController().getMachineType().has(MachineFlag.GUI) && fakeBlock.getController().canPlayerOpenGui(player)) {
if (!level.isClientSide){
AntimatterPlatformUtils.openGui((ServerPlayer) player, fakeBlock.getController(), extra -> {
AntimatterPlatformUtils.INSTANCE.openGui((ServerPlayer) player, fakeBlock.getController(), extra -> {
extra.writeBlockPos(fakeBlock.getController().getBlockPos());
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ public boolean checkStructure() {

public void serverTick(Level level, BlockPos pos, BlockState state) {
super.serverTick(level, pos, state);
if (level.getGameTime() % 100 == 0 && !validStructure && checkingStructure == 0 && !AntimatterPlatformUtils.isProduction()){
if (level.getGameTime() % 100 == 0 && !validStructure && checkingStructure == 0 && !AntimatterPlatformUtils.INSTANCE.isProduction()){
//checkStructure();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,12 +333,12 @@ public static boolean fire(Level aWorld, BlockPos pos, boolean aCheckFlammabilit
BlockState tBlock = aWorld.getBlockState(pos);
if (tBlock.getMaterial() == Material.LAVA || tBlock.getMaterial() == Material.FIRE) return false;
if (tBlock.getMaterial() == Material.CLOTH_DECORATION || tBlock.getCollisionShape(aWorld, pos).isEmpty()) {
if (AntimatterPlatformUtils.getFlammability(tBlock, aWorld, pos, Direction.NORTH) > 0) return aWorld.setBlock(pos, Blocks.FIRE.defaultBlockState(), 3);
if (AntimatterPlatformUtils.INSTANCE.getFlammability(tBlock, aWorld, pos, Direction.NORTH) > 0) return aWorld.setBlock(pos, Blocks.FIRE.defaultBlockState(), 3);
if (aCheckFlammability) {
for (Direction tSide : Direction.values()) {
BlockState tAdjacent = aWorld.getBlockState(pos.relative(tSide));
if (tAdjacent.getBlock() == Blocks.CHEST || tAdjacent.getBlock() == Blocks.TRAPPED_CHEST) return aWorld.setBlock(pos, Blocks.FIRE.defaultBlockState(), 3);
if (AntimatterPlatformUtils.getFlammability(tAdjacent, aWorld, pos.relative(tSide), tSide.getOpposite()) > 0) return aWorld.setBlock(pos, Blocks.FIRE.defaultBlockState(), 3);
if (AntimatterPlatformUtils.INSTANCE.getFlammability(tAdjacent, aWorld, pos.relative(tSide), tSide.getOpposite()) > 0) return aWorld.setBlock(pos, Blocks.FIRE.defaultBlockState(), 3);
}
} else {
return aWorld.setBlock(pos, Blocks.FIRE.defaultBlockState(), 3);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ public void deserialize(ListTag nbt) {
CompoundTag cnbt = (CompoundTag) tank;
if (i > tanks.length - 1)
break;
tanks[i++].setFluid(0, AntimatterPlatformUtils.fromTag(cnbt));
tanks[i++].setFluid(0, AntimatterPlatformUtils.INSTANCE.fromTag(cnbt));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ private boolean consume(boolean simulate) {
return !stack.isEmpty();
}
if (!(stack = tile.itemHandler.map(t -> t.consumeInputs(BURNABLE.get(), false)).orElse(Collections.emptyList())).isEmpty()) {
burnDuration += AntimatterPlatformUtils.getBurnTime(stack.get(0), null) * burnMultiplier;
burnDuration += AntimatterPlatformUtils.INSTANCE.getBurnTime(stack.get(0), null) * burnMultiplier;
return true;
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ public void deserialize(CompoundTag nbt) {
itemInputs = new ObjectArrayList<>();
fluidInputs = new ObjectArrayList<>();
nbt.getList("I", 10).forEach(t -> itemInputs.add(ItemStack.of((CompoundTag) t)));
nbt.getList("F", 10).forEach(t -> fluidInputs.add(AntimatterPlatformUtils.fromTag((CompoundTag) t)));
nbt.getList("F", 10).forEach(t -> fluidInputs.add(AntimatterPlatformUtils.INSTANCE.fromTag((CompoundTag) t)));
this.processingBlocked = nbt.getBoolean("PB");
this.currentProgress = nbt.getInt("P");
this.tickTimer = nbt.getInt("T");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ public static void addPlayerTickCallback(PlayerTickCallback callback){


public static void lootTableLoad(LootTable table, ResourceLocation name){
if (AntimatterPlatformUtils.getLootTableID(table).getPath().startsWith("blocks/")) {
ResourceLocation blockId = new ResourceLocation(AntimatterPlatformUtils.getLootTableID(table).getNamespace(), name.getPath().replace("blocks/", ""));
if (AntimatterPlatformUtils.blockExists(blockId)) {
Block block = AntimatterPlatformUtils.getBlockFromId(blockId);
if (AntimatterPlatformUtils.INSTANCE.getLootTableID(table).getPath().startsWith("blocks/")) {
ResourceLocation blockId = new ResourceLocation(AntimatterPlatformUtils.INSTANCE.getLootTableID(table).getNamespace(), name.getPath().replace("blocks/", ""));
if (AntimatterPlatformUtils.INSTANCE.blockExists(blockId)) {
Block block = AntimatterPlatformUtils.INSTANCE.getBlockFromId(blockId);
//Antimatter.LOGGER.info(blockId.toString());
if (block == Blocks.ICE || block == Blocks.PACKED_ICE || block == Blocks.BLUE_ICE) {
AntimatterPlatformUtils.addPool(table, LootPool.lootPool().setRolls(ConstantValue.exactly(1)).when(AntimatterBlockLootProvider.SAW).add(LootItem.lootTableItem(block)).build());
AntimatterPlatformUtils.INSTANCE.addPool(table, LootPool.lootPool().setRolls(ConstantValue.exactly(1)).when(AntimatterBlockLootProvider.SAW).add(LootItem.lootTableItem(block)).build());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ public CoverFactory getFactory() {
}

protected void markAndNotifySource(){
AntimatterPlatformUtils.markAndNotifyBlock(source().getTile().getLevel(), source().getTile().getBlockPos(), source().getTile().getLevel().getChunkAt(source().getTile().getBlockPos()), source().getTile().getBlockState(), source().getTile().getBlockState(), 1, 512);
AntimatterPlatformUtils.INSTANCE.markAndNotifyBlock(source().getTile().getLevel(), source().getTile().getBlockPos(), source().getTile().getLevel().getChunkAt(source().getTile().getBlockPos()), source().getTile().getBlockState(), source().getTile().getBlockState(), 1, 512);
}

}
2 changes: 1 addition & 1 deletion common/src/main/java/muramasa/antimatter/cover/ICover.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ default boolean hasGui() {
default boolean openGui(Player player, Direction side) {
if (!hasGui())
return false;
AntimatterPlatformUtils.openGui((ServerPlayer) player, this, packetBuffer -> {
AntimatterPlatformUtils.INSTANCE.openGui((ServerPlayer) player, this, packetBuffer -> {
packetBuffer.writeBlockPos(this.source().getTile().getBlockPos());
packetBuffer.writeInt(side.get3DDataValue());
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public static void clientProvider(String domain, Supplier<IAntimatterProvider> p

public static void runDataProvidersDynamically() {
AntimatterBlockLootProvider.init();
ProvidersEvent ev = AntimatterPlatformUtils.postProviderEvent(AntimatterAPI.getSIDE(), Antimatter.INSTANCE);
ProvidersEvent ev = AntimatterPlatformUtils.INSTANCE.postProviderEvent(AntimatterAPI.getSIDE(), Antimatter.INSTANCE);
Collection<IAntimatterProvider> providers = ev.getProviders();
long time = System.currentTimeMillis();
Stream<IAntimatterProvider> async = providers.stream().filter(IAntimatterProvider::async).parallel();
Expand All @@ -129,8 +129,8 @@ public static void runDataProvidersDynamically() {
AntimatterTagProvider.afterCompletion();
AntimatterBlockLootProvider.afterCompletion();
Antimatter.LOGGER.info("Time to run data providers: " + (System.currentTimeMillis() - time) + " ms.");
if (AntimatterConfig.EXPORT_DEFAULT_RECIPES.get() || !AntimatterPlatformUtils.isProduction()) {
RUNTIME_DATA_PACK.dump(AntimatterPlatformUtils.getConfigDir().getParent().resolve("dumped"));
if (AntimatterConfig.EXPORT_DEFAULT_RECIPES.get() || !AntimatterPlatformUtils.INSTANCE.isProduction()) {
RUNTIME_DATA_PACK.dump(AntimatterPlatformUtils.INSTANCE.getConfigDir().getParent().resolve("dumped"));
}
}

Expand All @@ -144,8 +144,8 @@ public static void runAssetProvidersDynamically() {
providers.forEach(IAntimatterProvider::onCompletion);
AntimatterLanguageProvider.postCompletion();
Antimatter.LOGGER.info("Time to run asset providers: " + (System.currentTimeMillis() - time) + " ms.");
if (!AntimatterPlatformUtils.isProduction()) {
DYNAMIC_RESOURCE_PACK.dump(AntimatterPlatformUtils.getConfigDir().getParent().resolve("dumped"));
if (!AntimatterPlatformUtils.INSTANCE.isProduction()) {
DYNAMIC_RESOURCE_PACK.dump(AntimatterPlatformUtils.INSTANCE.getConfigDir().getParent().resolve("dumped"));
}
}

Expand All @@ -155,7 +155,7 @@ public static void runAssetProvidersDynamically() {
* @param rec consumer for IFinishedRecipe.
*/
public static void collectRecipes(AntimatterRecipeProvider provider, Consumer<FinishedRecipe> rec) {
CraftingEvent ev = AntimatterPlatformUtils.postCraftingEvent(Antimatter.INSTANCE);
CraftingEvent ev = AntimatterPlatformUtils.INSTANCE.postCraftingEvent(Antimatter.INSTANCE);
for (ICraftingLoader loader : ev.getLoaders()) {
loader.loadRecipes(rec, provider);
}
Expand Down Expand Up @@ -238,7 +238,7 @@ public static void onResourceReload(boolean serverEvent) {
filter = Collections.emptySet();
}
Map<ResourceLocation, IRecipeRegistrate.IRecipeLoader> loaders = new Object2ObjectOpenHashMap<>(30);
AntimatterPlatformUtils.postLoaderEvent(Antimatter.INSTANCE, (a, b, c) -> {
AntimatterPlatformUtils.INSTANCE.postLoaderEvent(Antimatter.INSTANCE, (a, b, c) -> {
if (filter.contains(new ResourceLocation(a, b)))
return;
if (loaders.put(new ResourceLocation(a, b), c) != null) {
Expand All @@ -261,7 +261,7 @@ public static void onResourceReload(boolean serverEvent) {
runRegular = !ev.disableBuiltin;
}
if (runRegular) {
WorldGenEvent ev = AntimatterPlatformUtils.postWorldEvent(Antimatter.INSTANCE);
WorldGenEvent ev = AntimatterPlatformUtils.INSTANCE.postWorldEvent(Antimatter.INSTANCE);
veins.addAll(ev.VEINS);
veins.addAll(AntimatterWorldGenerator.readCustomJsonObjects(WorldGenVeinLayer.class, WorldGenVeinLayer::fromJson, "vein_layers"));
smallOres.addAll(ev.SMALL_ORES);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static void clearServer() {

public static void addRecipe(FinishedRecipe recipe) {
JsonObject recipeJson = recipe.serializeRecipe();
Path parent = AntimatterPlatformUtils.getConfigDir().getParent()
Path parent = AntimatterPlatformUtils.INSTANCE.getConfigDir().getParent()
.resolve("dumped/antimatter-dynamic-data/data");
if (AntimatterConfig.EXPORT_DEFAULT_RECIPES.get()){
writeJson(recipe.getId(), "recipes", parent, recipeJson);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public AntimatterItemModelBuilder bucketProperties(Fluid fluid) {
}

public AntimatterItemModelBuilder bucketProperties(Fluid fluid, boolean tint, boolean islighter) {
property("fluid", AntimatterPlatformUtils.getIdFromFluid(fluid).toString());
property("fluid", AntimatterPlatformUtils.INSTANCE.getIdFromFluid(fluid).toString());
property("flipGas", islighter);
property("applyTint", tint);
// property("coverIsMask", false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ private List<IRecipe> getRecipes(IRecipeMap recipeMap){

private RecipeManager getRecipeManager(){
if (AntimatterAPI.getSIDE().isServer()){
return AntimatterPlatformUtils.getCurrentServer().getRecipeManager();
return AntimatterPlatformUtils.INSTANCE.getCurrentServer().getRecipeManager();
} else {
if (getWorld() == null) return null;
return getWorld().getRecipeManager();
Expand Down Expand Up @@ -245,7 +245,7 @@ public void registerRecipeCatalysts(@NotNull IRecipeCatalystRegistration registr
AntimatterJEIREIPlugin.getREGISTRY().forEach((id, tuple) -> {
if (tuple.workstations.isEmpty()) return;
tuple.workstations.forEach(s -> {
ItemLike item = AntimatterPlatformUtils.getItemFromID(s);
ItemLike item = AntimatterPlatformUtils.INSTANCE.getItemFromID(s);
if (item == Items.AIR) return;
registration.addRecipeCatalyst(new ItemStack(item), tuple.map.getLoc());
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ public void setReplacement(String material, String item, MaterialType type){
if (material1 == Material.NULL){
return;
}
if (!AntimatterPlatformUtils.itemExists(new ResourceLocation(item))){
if (!AntimatterPlatformUtils.INSTANCE.itemExists(new ResourceLocation(item))){
return;
}
type.replacement(material1, () -> AntimatterPlatformUtils.getItemFromID(new ResourceLocation(item)));
type.replacement(material1, () -> AntimatterPlatformUtils.INSTANCE.getItemFromID(new ResourceLocation(item)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public static List<EntryIngredient> createOutputEntries(List<ItemStack> input, I
components.add(c);
}
if (recipe.getId() != null){
components.add(Utils.literal("Recipe by: ").append(Utils.literal(AntimatterPlatformUtils.getModName(recipe.getId().getNamespace())).withStyle(ChatFormatting.BLUE, ChatFormatting.ITALIC)));
components.add(Utils.literal("Recipe by: ").append(Utils.literal(AntimatterPlatformUtils.INSTANCE.getModName(recipe.getId().getNamespace())).withStyle(ChatFormatting.BLUE, ChatFormatting.ITALIC)));
Minecraft minecraft = Minecraft.getInstance();
boolean showAdvanced = minecraft.options.advancedItemTooltips || Screen.hasShiftDown();
if (showAdvanced){
Expand All @@ -87,7 +87,7 @@ public static List<EntryIngredient> createFluidOutputEntries(List<FluidStack> in
fluidStackEntryStack.setting(EntryStack.Settings.TOOLTIP_PROCESSOR, (entry, t) -> {
createFluidTooltip(t, fluidStackEntryStack.getValue());
if (recipe.getId() != null){
t.add(Utils.literal("Recipe by: ").append(Utils.literal(AntimatterPlatformUtils.getModName(recipe.getId().getNamespace())).withStyle(ChatFormatting.BLUE, ChatFormatting.ITALIC)));
t.add(Utils.literal("Recipe by: ").append(Utils.literal(AntimatterPlatformUtils.INSTANCE.getModName(recipe.getId().getNamespace())).withStyle(ChatFormatting.BLUE, ChatFormatting.ITALIC)));
Minecraft minecraft = Minecraft.getInstance();
boolean showAdvanced = minecraft.options.advancedItemTooltips || Screen.hasShiftDown();
if (showAdvanced){
Expand Down
Loading

0 comments on commit 228991f

Please sign in to comment.