mirror of
https://github.com/LegacyModdingMC/ChunkAPI.git
synced 2026-11-17 10:55:03 +00:00
trying random stuff, nothing serious yet
This commit is contained in:
19 files changed
+327
-23
No files matched your search
@@ -0,0 +1,27 @@
|
||||
package com.falsepattern.chunk.internal;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import cpw.mods.fml.common.Mod;
|
||||
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||
|
||||
@Mod(modid = Tags.MODID,
|
||||
version = Tags.VERSION,
|
||||
name = Tags.MODNAME,
|
||||
acceptedMinecraftVersions = "[1.7.10]",
|
||||
dependencies = "required-after:falsepatternlib@[0.10.15,);")
|
||||
public class ChunkAPI {
|
||||
@Getter
|
||||
private static boolean registrationStage = false;
|
||||
|
||||
@Mod.EventHandler
|
||||
public void preInit(FMLPreInitializationEvent event) {
|
||||
registrationStage = true;
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
public void postInit(FMLPostInitializationEvent event) {
|
||||
registrationStage = false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package com.falsepattern.chunk.internal;
|
||||
|
||||
import com.falsepattern.chunk.api.ChunkDataManager;
|
||||
import com.falsepattern.chunk.api.exception.ManagerRegistrationException;
|
||||
import lombok.val;
|
||||
import lombok.var;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class ChunkDataRegistryImpl {
|
||||
private static final Map<String, ChunkDataManager> managers = new HashMap<>();
|
||||
private static final Set<String> disabledManagers = new HashSet<>();
|
||||
public static void registerDataManager(ChunkDataManager manager) throws ManagerRegistrationException {
|
||||
if (!ChunkAPI.isRegistrationStage()) {
|
||||
throw new ManagerRegistrationException("ChunkDataManager registration is not allowed at this time! " +
|
||||
"Please register your ChunkDataManager in the init phase of your mod.");
|
||||
}
|
||||
var id = manager.id();
|
||||
if (id == null) {
|
||||
throw new ManagerRegistrationException("ChunkDataManager " + manager + " has a null id!");
|
||||
}
|
||||
id = id.intern();
|
||||
if (managers.containsKey(id)) {
|
||||
throw new ManagerRegistrationException("ChunkDataManager " + manager + " has a duplicate id!");
|
||||
}
|
||||
|
||||
// If the manager was disabled, do not add it to the list of managers.
|
||||
if (disabledManagers.contains(id)) {
|
||||
return;
|
||||
}
|
||||
|
||||
managers.put(id, manager);
|
||||
}
|
||||
|
||||
public static void disableDataManager(String id) {
|
||||
if (!ChunkAPI.isRegistrationStage()) {
|
||||
throw new ManagerRegistrationException("ChunkDataManager disabling is not allowed at this time! " +
|
||||
"Please disable any ChunkDataManagers in the init phase of your mod.");
|
||||
}
|
||||
if (id == null) {
|
||||
throw new ManagerRegistrationException("ChunkDataManager id cannot be null!");
|
||||
}
|
||||
id = id.intern();
|
||||
Common.LOG.warn("Disabling ChunkDataManager " + id + ". See the stacktrace for the source of this event.", new Throwable());
|
||||
//Remove the manager from the list of managers, if it exists
|
||||
managers.remove(id);
|
||||
|
||||
//Add the manager to the list of disabled managers, in case it gets registered after this disable call.
|
||||
disabledManagers.add(id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.falsepattern.chunk.internal;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
/**
|
||||
* Non-minecraft stuff to avoid accidental classloading in spaghetti code
|
||||
*/
|
||||
public class Common {
|
||||
public static final Logger LOG = LogManager.getLogger(Tags.MODID);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.falsepattern.chunk.internal;
|
||||
|
||||
public class Tags {
|
||||
public static final String MODID = "GRADLETOKEN_MODID";
|
||||
public static final String MODNAME = "GRADLETOKEN_MODNAME";
|
||||
public static final String VERSION = "GRADLETOKEN_VERSION";
|
||||
public static final String GROUPNAME = "GRADLETOKEN_GROUPNAME";
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
package com.falsepattern.chunk.internal.mixin.mixins.common.vanilla;
|
||||
|
||||
import com.falsepattern.chunk.api.ChunkDataManager;
|
||||
import com.falsepattern.chunk.api.ModdedChunk;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* This mixin injects the {@link ModdedChunk} interface into {@link Chunk}, and also creates the data map.
|
||||
*/
|
||||
@Mixin(Chunk.class)
|
||||
public abstract class ChunkDataMixin implements ModdedChunk {
|
||||
private Map<String, Object> data;
|
||||
|
||||
@Inject(method = "<init>(Lnet/minecraft/world/World;II)V",
|
||||
at = @At("RETURN"))
|
||||
private void init(World p_i1995_1_, int p_i1995_2_, int p_i1995_3_, CallbackInfo ci) {
|
||||
data = new HashMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T getData(ChunkDataManager manager) {
|
||||
return (T) data.get(manager.id());
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> void setData(ChunkDataManager manager, T data) {
|
||||
this.data.put(manager.id(), data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasData(ChunkDataManager manager) {
|
||||
return data.containsKey(manager.id());
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T removeData(ChunkDataManager manager) {
|
||||
return (T) data.remove(manager.id());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* FalseTweaks
|
||||
*
|
||||
* Copyright (C) 2022 FalsePattern
|
||||
* All Rights Reserved
|
||||
*
|
||||
* The above copyright notice, this permission notice and the word "SNEED"
|
||||
* shall be included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.falsepattern.chunk.internal.mixin.plugin;
|
||||
|
||||
import com.falsepattern.lib.mixin.IMixin;
|
||||
import com.falsepattern.lib.mixin.ITargetedMod;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public enum Mixin implements IMixin {
|
||||
// @formatter:off
|
||||
;
|
||||
// @formatter:on
|
||||
|
||||
@Getter
|
||||
private final Side side;
|
||||
@Getter
|
||||
private final Predicate<List<ITargetedMod>> filter;
|
||||
@Getter
|
||||
private final String mixin;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* FalseTweaks
|
||||
*
|
||||
* Copyright (C) 2022 FalsePattern
|
||||
* All Rights Reserved
|
||||
*
|
||||
* The above copyright notice, this permission notice and the word "SNEED"
|
||||
* shall be included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.falsepattern.chunk.internal.mixin.plugin;
|
||||
|
||||
import com.falsepattern.chunk.internal.Tags;
|
||||
import com.falsepattern.lib.mixin.IMixin;
|
||||
import com.falsepattern.lib.mixin.IMixinPlugin;
|
||||
import com.falsepattern.lib.mixin.ITargetedMod;
|
||||
import lombok.Getter;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
public class MixinPlugin implements IMixinPlugin {
|
||||
@Getter
|
||||
private final Logger logger = IMixinPlugin.createLogger(Tags.MODNAME);
|
||||
|
||||
@Override
|
||||
public ITargetedMod[] getTargetedModEnumValues() {
|
||||
return TargetedMod.values();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMixin[] getMixinEnumValues() {
|
||||
return Mixin.values();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* FalseTweaks
|
||||
*
|
||||
* Copyright (C) 2022 FalsePattern
|
||||
* All Rights Reserved
|
||||
*
|
||||
* The above copyright notice, this permission notice and the word "SNEED"
|
||||
* shall be included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.falsepattern.chunk.internal.mixin.plugin;
|
||||
|
||||
import com.falsepattern.lib.mixin.ITargetedMod;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public enum TargetedMod implements ITargetedMod {
|
||||
;
|
||||
|
||||
@Getter
|
||||
private final String modName;
|
||||
@Getter
|
||||
private final boolean loadInDevelopment;
|
||||
@Getter
|
||||
private final Predicate<String> condition;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
/**
|
||||
* This package contains the internal classes of the ChunkAPI library. Do not use these classes directly.
|
||||
*/
|
||||
package com.falsepattern.chunk.internal;
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
package com.falsepattern.chunk.internal.stubpackage.net.minecraft.world.chunk;
|
||||
|
||||
import com.falsepattern.chunk.api.ModdedChunk;
|
||||
|
||||
import net.minecraft.world.World;
|
||||
|
||||
//Internal stub class, do not use
|
||||
public abstract class Chunk extends net.minecraft.world.chunk.Chunk implements ModdedChunk {
|
||||
private Chunk(World p_i1995_1_, int p_i1995_2_, int p_i1995_3_) {
|
||||
super(p_i1995_1_, p_i1995_2_, p_i1995_3_);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user