Skip to content

Commit

Permalink
Implement autoplace (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
Glease authored Aug 8, 2022
1 parent e8f5cd6 commit 609e504
Show file tree
Hide file tree
Showing 60 changed files with 3,685 additions and 688 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@ Originally created by TecTech authors, taken with permission. It's under MIT lic
}
```
Replace `master-SNAPSHOT` with a commit hash or a tag name (if any) of your choice to prevent unexpected upstream changes.
2. Add `required-after:structurelib;` to your `@Mod(dependencies = "..")` tring.
2. Add `required-after:structurelib;` to your `@Mod(dependencies = "..")` tring.
3. Add `structurelib` to your `mcmod.info`.
## Contribution
The project is developed using IDEA. Please manually configure the build to not delegate to gradle for textures to show up in dev.
## Current license
Due to me adding in ItemStackMap, which was derived from code from CodeChicken's LGPL mod NEI. This mod is effectively considered
licensed under LGPL in its entirety since commit ebef584b8c518f8202cfe0984fb28a6d23e52b3d.
372 changes: 281 additions & 91 deletions build.gradle

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
plugins {
id 'com.diffplug.blowdryerSetup' version '1.6.0'
}

apply plugin: 'com.diffplug.blowdryerSetup'

blowdryerSetup {
github('GTNewHorizons/ExampleMod1.7.10', 'tag', '0.1.4')
//devLocal '.' // Use this when testing config updates locally
}
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
package com.gtnewhorizon.structurelib.proxy;
package com.gtnewhorizon.structurelib;

import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import com.gtnewhorizon.structurelib.ConfigurationHandler;
import com.gtnewhorizon.structurelib.entity.fx.EntityFXBlockHint;
import com.gtnewhorizon.structurelib.entity.fx.WeightlessParticleFX;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiNewChat;
import net.minecraft.client.particle.EntityFX;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.world.WorldEvent;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
public class ClientProxy extends CommonProxy {

import static com.gtnewhorizon.structurelib.StructureLib.RANDOM;
private static final short[] NO_TINT = {255, 255, 255, 0};

public class ClientProxy extends CommonProxy {
@Override
public void hintParticleTinted(World w, int x, int y, int z, IIcon[] icons, short[] RGBa) {
EntityFXBlockHint hint = new EntityFXBlockHint(w, x, y, z, icons).withColorTint(RGBa);
Expand All @@ -46,10 +44,6 @@ public void hintParticleTinted(World w, int x, int y, int z, IIcon[] icons, shor
allHints.forcePut(hint, info);
}
currentHints.add(hint);

EntityFX particle = new WeightlessParticleFX(w, x + RANDOM.nextFloat() * 0.5F, y + RANDOM.nextFloat() * 0.5F, z + RANDOM.nextFloat() * 0.5F, 0, 0, 0);
particle.setRBGColorF(0, 0.6F * RANDOM.nextFloat(), 0.8f);
Minecraft.getMinecraft().effectRenderer.addEffect(particle);
}

@Override
Expand All @@ -59,12 +53,25 @@ public void hintParticleTinted(World w, int x, int y, int z, Block block, int me

@Override
public void hintParticle(World w, int x, int y, int z, IIcon[] icons) {
hintParticleTinted(w, x, y, z, icons, new short[]{255, 255, 255, 0});
hintParticleTinted(w, x, y, z, icons, NO_TINT);
}

@Override
public void hintParticle(World w, int x, int y, int z, Block block, int meta) {
hintParticleTinted(w, x, y, z, createIIconFromBlock(block, meta), new short[]{255, 255, 255, 0});
hintParticleTinted(w, x, y, z, createIIconFromBlock(block, meta), NO_TINT);
}

@Override
public boolean updateHintParticleTint(EntityPlayer player, World w, int x, int y, int z, short[] rgBa) {
if (player instanceof EntityPlayerMP) return super.updateHintParticleTint(player, w, x, y, z, rgBa);
if (player != getCurrentPlayer()) return false; // how?
HintParticleInfo info = new HintParticleInfo(x, y, z, null);
EntityFXBlockHint existing = allHints.inverse().get(info);
if (existing != null) {
existing.withColorTint(rgBa);
return true;
}
return false;
}

private static IIcon[] createIIconFromBlock(Block block, int meta) {
Expand Down Expand Up @@ -98,43 +105,36 @@ public boolean isCurrentPlayer(EntityPlayer player) {
private static List<EntityFXBlockHint> currentHints;

public static void onHintDead(EntityFXBlockHint fx) {
if (ConfigurationHandler.INSTANCE.isRemoveCollidingHologram())
allHints.remove(fx);
if (ConfigurationHandler.INSTANCE.isRemoveCollidingHologram()) allHints.remove(fx);
for (Iterator<List<EntityFXBlockHint>> iterator = hintOwners.iterator(); iterator.hasNext(); ) {
List<EntityFXBlockHint> list = iterator.next();
if (list.remove(fx)) {
if (list.isEmpty())
iterator.remove();
if (list.isEmpty()) iterator.remove();
break;
}
}
}

@Override
public void startHinting(World w) {
if (!w.isRemote)
return;
if (currentHints != null)
hintOwners.add(currentHints);
if (!w.isRemote) return;
if (currentHints != null) hintOwners.add(currentHints);
currentHints = new LinkedList<>();
}

private void ensureHinting() {
if (currentHints == null)
currentHints = new LinkedList<>();
if (currentHints == null) currentHints = new LinkedList<>();
}

@Override
public void endHinting(World w) {
if (!w.isRemote)
return;
if (!w.isRemote) return;
while (!hintOwners.isEmpty() && hintOwners.size() >= ConfigurationHandler.INSTANCE.getMaxCoexistingHologram()) {
List<EntityFXBlockHint> list = hintOwners.remove(0);
list.forEach(EntityFXBlockHint::setDead);
list.clear();
}
if (!currentHints.isEmpty())
hintOwners.add(currentHints);
if (!currentHints.isEmpty()) hintOwners.add(currentHints);
currentHints = null;
}

Expand All @@ -143,6 +143,12 @@ public void preInit(FMLPreInitializationEvent e) {
MinecraftForge.EVENT_BUS.register(new ForgeEventHandler());
}

@Override
public long getOverworldTime() {
// there is no overworld, better just hope current world time is ok...
return Minecraft.getMinecraft().theWorld.getTotalWorldTime();
}

private static class HintParticleInfo {
private final int x, y, z;
private final List<EntityFXBlockHint> owner;
Expand Down
51 changes: 51 additions & 0 deletions src/main/java/com/gtnewhorizon/structurelib/CommonProxy.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.gtnewhorizon.structurelib;

import com.gtnewhorizon.structurelib.net.UpdateHintParticleMessage;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;

public class CommonProxy {
public void hintParticleTinted(World w, int x, int y, int z, IIcon[] icons, short[] RGBa) {}

public void hintParticleTinted(World w, int x, int y, int z, Block block, int meta, short[] RGBa) {}

public void hintParticle(World w, int x, int y, int z, IIcon[] icons) {}

public void hintParticle(World w, int x, int y, int z, Block block, int meta) {}

public boolean updateHintParticleTint(EntityPlayer player, World w, int x, int y, int z, short[] rgBa) {
if (player instanceof EntityPlayerMP) { // just in case
StructureLib.net.sendTo(
new UpdateHintParticleMessage(x, (short) y, z, rgBa[0], rgBa[1], rgBa[2], rgBa[3]),
(EntityPlayerMP) player);
return true;
} else {
return false;
}
}

public EntityPlayer getCurrentPlayer() {
return null;
}

public boolean isCurrentPlayer(EntityPlayer player) {
return false;
}

public void addClientSideChatMessages(String... messages) {}

public void startHinting(World w) {}

public void endHinting(World w) {}

public void preInit(FMLPreInitializationEvent e) {}

public long getOverworldTime() {
return MinecraftServer.getServer().getEntityWorld().getTotalWorldTime();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
import cpw.mods.fml.client.event.ConfigChangedEvent;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import java.io.File;
import java.util.Map;
import net.minecraftforge.common.config.ConfigCategory;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.common.config.Property;

import java.io.File;
import java.util.Map;

public enum ConfigurationHandler {
INSTANCE;

Expand Down Expand Up @@ -39,8 +38,18 @@ private void setLanguageKeys() {
}

private void loadConfig() {
maxCoexistingHologram = config.getInt("maxCoexisting", "client.hologram", 1, 1, 100, "An attempt will be made to prune old holograms when a new hologram is about to be projected");
removeCollidingHologram = config.getBoolean("removeColliding", "client.hologram", true, "An attempt will be made to remove an existing hologram if it collides with a new hologram.");
maxCoexistingHologram = config.getInt(
"maxCoexisting",
"client.hologram",
1,
1,
100,
"An attempt will be made to prune old holograms when a new hologram is about to be projected");
removeCollidingHologram = config.getBoolean(
"removeColliding",
"client.hologram",
true,
"An attempt will be made to remove an existing hologram if it collides with a new hologram.");

if (config.hasChanged()) {
config.save();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
package com.gtnewhorizon.structurelib;

import net.minecraftforge.common.config.Configuration;

import javax.annotation.Nullable;
import java.util.Arrays;
import java.util.Objects;
import javax.annotation.Nullable;
import net.minecraftforge.common.config.Configuration;

enum ConfigurationVersion {
V1 {
@Override
protected void step(Configuration c) {
}
protected void step(Configuration c) {}
};

private static final ConfigurationVersion[] VALUES = values();
Expand All @@ -32,7 +30,10 @@ public static ConfigurationVersion latest() {
}

public static ConfigurationVersion identify(Configuration c) {
return Arrays.stream(VALUES).filter(v -> Objects.equals(c.getLoadedConfigVersion(), v.getVersionMarker())).findFirst().orElse(V1);
return Arrays.stream(VALUES)
.filter(v -> Objects.equals(c.getLoadedConfigVersion(), v.getVersionMarker()))
.findFirst()
.orElse(V1);
}

@Nullable
Expand Down
8 changes: 3 additions & 5 deletions src/main/java/com/gtnewhorizon/structurelib/GuiFactory.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package com.gtnewhorizon.structurelib;

import cpw.mods.fml.client.IModGuiFactory;
import java.util.Set;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;

import java.util.Set;

public class GuiFactory implements IModGuiFactory {
@Override
public void initialize(Minecraft minecraftInstance) {
}
public void initialize(Minecraft minecraftInstance) {}

@Override
public Class<? extends GuiScreen> mainConfigGuiClass() {
Expand All @@ -25,4 +23,4 @@ public Set<RuntimeOptionCategoryElement> runtimeGuiCategories() {
public RuntimeOptionGuiHandler getHandlerFor(RuntimeOptionCategoryElement element) {
return null;
}
}
}
20 changes: 13 additions & 7 deletions src/main/java/com/gtnewhorizon/structurelib/GuiModConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,30 @@

import cpw.mods.fml.client.config.GuiConfig;
import cpw.mods.fml.client.config.IConfigElement;
import java.util.List;
import java.util.stream.Collectors;
import net.minecraft.client.gui.GuiScreen;
import net.minecraftforge.common.config.ConfigElement;
import net.minecraftforge.common.config.Configuration;

import java.util.List;
import java.util.stream.Collectors;

public class GuiModConfig extends GuiConfig {
public GuiModConfig(GuiScreen guiScreen) {
super(guiScreen, getConfigElements(), StructureLibAPI.MOD_ID, false, false, GuiConfig.getAbridgedConfigPath(ConfigurationHandler.INSTANCE.getConfig().toString()));
super(
guiScreen,
getConfigElements(),
StructureLibAPI.MOD_ID,
false,
false,
GuiConfig.getAbridgedConfigPath(
ConfigurationHandler.INSTANCE.getConfig().toString()));
}

@SuppressWarnings("rawtypes")
private static List<IConfigElement> getConfigElements() {
final Configuration config = ConfigurationHandler.INSTANCE.getConfig();
return config.getCategoryNames().stream()
.filter(name -> name.indexOf('.') == -1)
.map(name -> new ConfigElement(config.getCategory(name)))
.collect(Collectors.toList());
.filter(name -> name.indexOf('.') == -1)
.map(name -> new ConfigElement(config.getCategory(name)))
.collect(Collectors.toList());
}
}
Loading

0 comments on commit 609e504

Please sign in to comment.