Skip to content

Commit

Permalink
chore: replace references to java.awt.Color with custom constants
Browse files Browse the repository at this point in the history
Prevents issues with servers without awt installed in their JRE

See: a06546b#commitcomment-101130147

kept references to fromHSB as they were all clientside

Also optimized all imports to make finding remaining  serverside AWT uses easier
  • Loading branch information
klikli-dev committed Feb 19, 2023
1 parent 79ae403 commit fe937c2
Show file tree
Hide file tree
Showing 59 changed files with 83 additions and 137 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,24 @@ public static class Divination {
public static final String LINKED_BLOCK_ID = PREFIX + "divination.linked_block_id";
}
}


/**
* Use constants in this class instead of java.awt as that is not present in some server JREs and causes crashes
*/
public static class Color {
public static final int WHITE = 0xFFFFFF;
public static final int RED = 0xFF0000;
public static final int GREEN = 0x00FF00;
public static final int BLUE = 0x0000FF;
public static final int YELLOW = 0xFFFF00;

public static final int ORANGE = 0xFFA500;

public static final int CYAN = 0x00FFFF;

public static final int MAGENTA = 0xFF00FF;

public static final int BLACK = 0x000000;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
package com.github.klikli_dev.occultism.api.common.data;

import net.minecraft.core.BlockPos;
import net.minecraft.core.Registry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.FriendlyByteBuf;
Expand All @@ -33,7 +31,6 @@
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraftforge.common.util.INBTSerializable;
import net.minecraftforge.registries.ForgeRegistries;

import java.util.Objects;
import java.util.StringJoiner;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
package com.github.klikli_dev.occultism.client.gui.spirit;

import com.github.klikli_dev.occultism.Occultism;
import com.github.klikli_dev.occultism.OccultismConstants;
import com.github.klikli_dev.occultism.api.common.data.WorkAreaSize;
import com.github.klikli_dev.occultism.client.gui.controls.LabelWidget;
import com.github.klikli_dev.occultism.common.item.spirit.BookOfCallingItem;
Expand All @@ -34,8 +35,6 @@
import net.minecraft.network.chat.Component;
import net.minecraftforge.client.gui.widget.ExtendedButton;

import java.awt.*;

public class BookOfCallingGui extends Screen {

//region Fields
Expand Down Expand Up @@ -75,7 +74,7 @@ protected void init() {


LabelWidget modeLabel = new LabelWidget(guiLeft - 80,
guiTop + 66, false, -1, 2, Color.WHITE.getRGB()).alignRight(true);
guiTop + 66, false, -1, 2, OccultismConstants.Color.WHITE).alignRight(true);
modeLabel.addLine("gui." + Occultism.MODID + ".book_of_calling.mode", true);
this.addRenderableWidget(modeLabel);

Expand All @@ -90,7 +89,7 @@ protected void init() {
boolean showSize = this.mode.getItemMode() == BookOfCallingItem.ItemMode.SET_BASE;
if (showSize) {
LabelWidget workAreaLabel = new LabelWidget(
guiLeft - 80, guiTop + 91, true, -1, 2, Color.WHITE.getRGB()).alignRight(true);
guiLeft - 80, guiTop + 91, true, -1, 2, OccultismConstants.Color.WHITE).alignRight(true);
workAreaLabel.addLine("gui." + Occultism.MODID + ".book_of_calling.work_area", true);
this.addRenderableWidget(workAreaLabel);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
package com.github.klikli_dev.occultism.client.gui.spirit;

import com.github.klikli_dev.occultism.Occultism;
import com.github.klikli_dev.occultism.OccultismConstants;
import com.github.klikli_dev.occultism.api.common.data.MachineReference;
import com.github.klikli_dev.occultism.client.gui.controls.LabelWidget;
import com.github.klikli_dev.occultism.network.MessageSetManagedMachine;
Expand All @@ -36,8 +37,6 @@
import net.minecraftforge.client.gui.widget.ExtendedButton;
import org.apache.commons.lang3.StringUtils;

import java.awt.*;

public class BookOfCallingManagedMachineGui extends Screen {

//region Fields
Expand Down Expand Up @@ -120,7 +119,7 @@ public void init() {
guiTop + buttonTop + buttonHeight * 2 + buttonMargin * 2, textWidth, buttonHeight, Component.literal(""));
this.text.setMaxLength(30);
this.text.setVisible(true);
this.text.setTextColor(Color.WHITE.getRGB());
this.text.setTextColor(OccultismConstants.Color.WHITE);
this.text.setFocus(true);

this.text.setValue(this.customName);
Expand All @@ -134,17 +133,17 @@ public void init() {

buttonTop += 5;
LabelWidget insertFacingLabel = new LabelWidget(guiLeft - 80, guiTop + buttonTop, false, -1, 2,
Color.WHITE.getRGB()).alignRight(true);
OccultismConstants.Color.WHITE).alignRight(true);
insertFacingLabel.addLine("gui." + Occultism.MODID + ".book_of_calling.manage_machine.insert", true);
this.addRenderableWidget(insertFacingLabel);

LabelWidget extractFacingLabel = new LabelWidget(guiLeft - 80, guiTop + buttonTop + buttonHeight + buttonMargin,
false, -1, 2, Color.WHITE.getRGB()).alignRight(true);
false, -1, 2, OccultismConstants.Color.WHITE).alignRight(true);
extractFacingLabel.addLine("gui." + Occultism.MODID + ".book_of_calling.manage_machine.extract", true);
this.addRenderableWidget(extractFacingLabel);

LabelWidget customNameLabel = new LabelWidget(guiLeft - 80,
guiTop + buttonTop + buttonHeight * 2 + buttonMargin * 2 + 1, false, -1, 2, Color.WHITE.getRGB()).alignRight(true);
guiTop + buttonTop + buttonHeight * 2 + buttonMargin * 2 + 1, false, -1, 2, OccultismConstants.Color.WHITE).alignRight(true);
customNameLabel.addLine("gui." + Occultism.MODID + ".book_of_calling.manage_machine.custom_name", true);
this.addRenderableWidget(customNameLabel);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
package com.github.klikli_dev.occultism.client.gui.spirit;

import com.github.klikli_dev.occultism.Occultism;
import com.github.klikli_dev.occultism.OccultismConstants;
import com.github.klikli_dev.occultism.client.gui.controls.SizedImageButton;
import com.github.klikli_dev.occultism.common.container.spirit.SpiritTransporterContainer;
import com.github.klikli_dev.occultism.network.MessageSetFilterMode;
Expand All @@ -40,7 +41,6 @@
import net.minecraft.world.entity.player.Inventory;
import org.apache.commons.lang3.StringUtils;

import java.awt.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
Expand Down Expand Up @@ -122,7 +122,7 @@ public void init() {

this.tagFilterTextField.setBordered(false);
this.tagFilterTextField.setVisible(true);
this.tagFilterTextField.setTextColor(Color.WHITE.getRGB());
this.tagFilterTextField.setTextColor(OccultismConstants.Color.WHITE);
this.tagFilterTextField.setFocus(false);

if (!StringUtils.isBlank(this.getTagFilterText())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
package com.github.klikli_dev.occultism.client.gui.storage;

import com.github.klikli_dev.occultism.Occultism;
import com.github.klikli_dev.occultism.OccultismConstants;
import com.github.klikli_dev.occultism.api.client.gui.IStorageControllerGui;
import com.github.klikli_dev.occultism.api.client.gui.IStorageControllerGuiContainer;
import com.github.klikli_dev.occultism.api.common.container.IStorageControllerContainer;
Expand Down Expand Up @@ -234,7 +235,7 @@ public void init() {

this.searchBar.setBordered(false);
this.searchBar.setVisible(true);
this.searchBar.setTextColor(Color.WHITE.getRGB());
this.searchBar.setTextColor(OccultismConstants.Color.WHITE);
this.searchBar.setFocus(focus);

this.searchBar.setValue(searchBarText);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

package com.github.klikli_dev.occultism.client.model.entity;

import com.github.klikli_dev.occultism.common.entity.spirit.AfritEntity;
import com.github.klikli_dev.occultism.common.entity.spirit.AfritWildEntity;
import net.minecraft.client.model.HumanoidModel;
import net.minecraft.client.model.geom.ModelPart;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,13 @@
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
import net.minecraft.resources.ResourceLocation;
import org.joml.Matrix4f;
import software.bernie.geckolib.cache.object.BakedGeoModel;
import software.bernie.geckolib.cache.object.GeoBone;
import software.bernie.geckolib.constant.DataTickets;
import software.bernie.geckolib.core.animation.AnimationState;
import software.bernie.geckolib.core.object.Color;
import software.bernie.geckolib.model.GeoModel;
import software.bernie.geckolib.renderer.GeoBlockRenderer;
import software.bernie.geckolib.renderer.GeoRenderer;

import javax.annotation.Nullable;

public class StorageControllerGeoRenderer extends GeoBlockRenderer<StorageControllerBlockEntity> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
import com.github.klikli_dev.occultism.api.common.data.SortType;
import com.github.klikli_dev.occultism.common.block.storage.StorageStabilizerBlock;
import com.github.klikli_dev.occultism.common.container.storage.StorageControllerContainer;
import com.github.klikli_dev.occultism.common.entity.spirit.SpiritEntity;
import com.github.klikli_dev.occultism.common.entity.job.ManageMachineJob;
import com.github.klikli_dev.occultism.common.entity.spirit.SpiritEntity;
import com.github.klikli_dev.occultism.common.misc.DepositOrder;
import com.github.klikli_dev.occultism.common.misc.ItemStackComparator;
import com.github.klikli_dev.occultism.common.misc.StorageControllerItemStackHandler;
Expand Down Expand Up @@ -69,7 +69,6 @@
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;
import software.bernie.geckolib.animatable.GeoBlockEntity;
import software.bernie.geckolib.core.animatable.GeoAnimatable;
import software.bernie.geckolib.core.animatable.instance.AnimatableInstanceCache;
import software.bernie.geckolib.core.animation.AnimatableManager;
import software.bernie.geckolib.core.animation.AnimationController;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import com.github.klikli_dev.occultism.network.MessageUpdateLinkedMachines;
import com.github.klikli_dev.occultism.network.OccultismPackets;
import com.github.klikli_dev.occultism.registry.OccultismContainers;
import com.github.klikli_dev.occultism.util.BlockEntityUtil;
import com.github.klikli_dev.occultism.util.CuriosUtil;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.Tag;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.klikli_dev.occultism.common.entity.ai.behaviour;

import com.github.klikli_dev.occultism.Occultism;
import com.github.klikli_dev.occultism.OccultismConstants;
import com.github.klikli_dev.occultism.common.entity.spirit.SpiritEntity;
import com.github.klikli_dev.occultism.network.MessageSelectBlock;
import com.github.klikli_dev.occultism.network.OccultismPackets;
Expand All @@ -13,7 +14,6 @@
import net.tslat.smartbrainlib.api.core.behaviour.ExtendedBehaviour;
import net.tslat.smartbrainlib.util.BrainUtils;

import java.awt.*;
import java.util.HashSet;
import java.util.List;

Expand Down Expand Up @@ -41,7 +41,7 @@ protected void start(E entity) {
BrainUtils.clearMemory(entity, OccultismMemoryTypes.WALK_TARGET_UNREACHABLE.get());

if (Occultism.DEBUG.debugAI) {
OccultismPackets.sendToTracking(entity, new MessageSelectBlock(walkTarget.getTarget().currentBlockPosition(), 50000, Color.RED.getRGB()));
OccultismPackets.sendToTracking(entity, new MessageSelectBlock(walkTarget.getTarget().currentBlockPosition(), 50000, OccultismConstants.Color.RED));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.mojang.datafixers.util.Pair;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.ai.behavior.BlockPosTracker;
import net.minecraft.world.entity.ai.behavior.EntityTracker;
import net.minecraft.world.entity.ai.memory.MemoryModuleType;
import net.minecraft.world.entity.ai.memory.MemoryStatus;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.klikli_dev.occultism.common.entity.ai.behaviour;

import com.github.klikli_dev.occultism.Occultism;
import com.github.klikli_dev.occultism.OccultismConstants;
import com.github.klikli_dev.occultism.common.entity.spirit.SpiritEntity;
import com.github.klikli_dev.occultism.exceptions.ItemHandlerMissingException;
import com.github.klikli_dev.occultism.network.MessageSelectBlock;
Expand All @@ -20,7 +21,6 @@
import net.tslat.smartbrainlib.api.core.behaviour.ExtendedBehaviour;
import net.tslat.smartbrainlib.util.BrainUtils;

import java.awt.*;
import java.util.HashSet;
import java.util.List;

Expand Down Expand Up @@ -66,8 +66,8 @@ protected void start(E entity) {

if (Occultism.DEBUG.debugAI) {

OccultismPackets.sendToTracking(entity, new MessageSelectBlock(depositPos, 5000, Color.MAGENTA.getRGB()));
OccultismPackets.sendToTracking(entity, new MessageSelectBlock(walkPos, 5000, Color.GREEN.getRGB()));
OccultismPackets.sendToTracking(entity, new MessageSelectBlock(depositPos, 5000, OccultismConstants.Color.MAGENTA));
OccultismPackets.sendToTracking(entity, new MessageSelectBlock(walkPos, 5000, OccultismConstants.Color.GREEN));
}

} else {
Expand All @@ -76,7 +76,7 @@ protected void start(E entity) {
BrainUtils.clearMemory(entity, MemoryModuleType.WALK_TARGET);

if (Occultism.DEBUG.debugAI) {
OccultismPackets.sendToTracking(entity, new MessageSelectBlock(depositPos, 50000, Color.RED.getRGB()));
OccultismPackets.sendToTracking(entity, new MessageSelectBlock(depositPos, 50000, OccultismConstants.Color.RED));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.klikli_dev.occultism.common.entity.ai.behaviour;

import com.github.klikli_dev.occultism.Occultism;
import com.github.klikli_dev.occultism.OccultismConstants;
import com.github.klikli_dev.occultism.common.entity.spirit.SpiritEntity;
import com.github.klikli_dev.occultism.network.MessageSelectBlock;
import com.github.klikli_dev.occultism.network.OccultismPackets;
Expand All @@ -15,7 +16,6 @@
import net.tslat.smartbrainlib.api.core.behaviour.ExtendedBehaviour;
import net.tslat.smartbrainlib.util.BrainUtils;

import java.awt.*;
import java.util.List;

/**
Expand Down Expand Up @@ -45,7 +45,7 @@ protected void start(E entity) {
BrainUtils.setMemory(entity, MemoryModuleType.WALK_TARGET, new WalkTarget(jobItem, 1.0f, 0));

if (Occultism.DEBUG.debugAI) {
OccultismPackets.sendToTracking(entity, new MessageSelectBlock(jobItem.blockPosition(), 5000, Color.GREEN.getRGB()));
OccultismPackets.sendToTracking(entity, new MessageSelectBlock(jobItem.blockPosition(), 5000, OccultismConstants.Color.GREEN));
}
}
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.klikli_dev.occultism.common.entity.ai.behaviour;

import com.github.klikli_dev.occultism.Occultism;
import com.github.klikli_dev.occultism.OccultismConstants;
import com.github.klikli_dev.occultism.common.entity.spirit.SpiritEntity;
import com.github.klikli_dev.occultism.exceptions.ItemHandlerMissingException;
import com.github.klikli_dev.occultism.network.MessageSelectBlock;
Expand All @@ -19,7 +20,6 @@
import net.tslat.smartbrainlib.api.core.behaviour.ExtendedBehaviour;
import net.tslat.smartbrainlib.util.BrainUtils;

import java.awt.*;
import java.util.List;

/**
Expand Down Expand Up @@ -48,7 +48,7 @@ protected void start(E entity) {
BrainUtils.setMemory(entity, MemoryModuleType.WALK_TARGET, new WalkTarget(treePos, 1.0f, 0));

if (Occultism.DEBUG.debugAI) {
OccultismPackets.sendToTracking(entity, new MessageSelectBlock(treePos, 5000, Color.GREEN.getRGB()));
OccultismPackets.sendToTracking(entity, new MessageSelectBlock(treePos, 5000, OccultismConstants.Color.GREEN));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.klikli_dev.occultism.common.entity.ai.behaviour;

import com.github.klikli_dev.occultism.Occultism;
import com.github.klikli_dev.occultism.OccultismConstants;
import com.github.klikli_dev.occultism.common.entity.spirit.SpiritEntity;
import com.github.klikli_dev.occultism.network.MessageSelectBlock;
import com.github.klikli_dev.occultism.network.OccultismPackets;
Expand All @@ -17,7 +18,6 @@
import net.tslat.smartbrainlib.api.core.behaviour.ExtendedBehaviour;
import net.tslat.smartbrainlib.util.BrainUtils;

import java.awt.*;
import java.util.HashSet;
import java.util.List;

Expand Down Expand Up @@ -62,8 +62,8 @@ protected void start(E entity) {
BrainUtils.setMemory(entity, OccultismMemoryTypes.LAST_TREE_WALK_TARGET.get(), new WalkTarget(walkPos, 1.0f, 1));

if (Occultism.DEBUG.debugAI) {
OccultismPackets.sendToTracking(entity, new MessageSelectBlock(treePos, 5000, Color.MAGENTA.getRGB()));
OccultismPackets.sendToTracking(entity, new MessageSelectBlock(walkPos, 5000, Color.GREEN.getRGB()));
OccultismPackets.sendToTracking(entity, new MessageSelectBlock(treePos, 5000, OccultismConstants.Color.MAGENTA));
OccultismPackets.sendToTracking(entity, new MessageSelectBlock(walkPos, 5000, OccultismConstants.Color.GREEN));
}

} else {
Expand All @@ -76,7 +76,7 @@ protected void start(E entity) {
BrainUtils.clearMemory(entity, OccultismMemoryTypes.NEAREST_TREE.get());

if (Occultism.DEBUG.debugAI) {
OccultismPackets.sendToTracking(entity, new MessageSelectBlock(treePos, 50000, Color.RED.getRGB()));
OccultismPackets.sendToTracking(entity, new MessageSelectBlock(treePos, 50000, OccultismConstants.Color.RED));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,8 @@
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.ClipContext;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.ChestBlockEntity;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraftforge.common.capabilities.ForgeCapabilities;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.items.IItemHandler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@

import com.github.klikli_dev.occultism.api.common.blockentity.IStorageControllerProxy;
import com.github.klikli_dev.occultism.common.entity.ai.BlockSorter;
import com.github.klikli_dev.occultism.common.entity.spirit.SpiritEntity;
import com.github.klikli_dev.occultism.common.entity.job.ManageMachineJob;
import com.github.klikli_dev.occultism.common.entity.spirit.SpiritEntity;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.InteractionHand;
Expand Down
Loading

0 comments on commit fe937c2

Please sign in to comment.