Add latest revisions after getting it functional
This commit is contained in:
parent
9653e273e4
commit
ffcecb8e8e
1443 changed files with 258988 additions and 6046 deletions
71
src/main/java/com/zontreck/AriasEssentials.java
Normal file
71
src/main/java/com/zontreck/AriasEssentials.java
Normal file
|
@ -0,0 +1,71 @@
|
|||
package com.zontreck;
|
||||
|
||||
import com.zontreck.block.DeprecatedModBlocks;
|
||||
import com.zontreck.block.ModBlocks;
|
||||
import com.zontreck.client.TimeBoostEntityRenderer;
|
||||
import com.zontreck.commands.CommandRegistry;
|
||||
import com.zontreck.configs.client.AEClientConfig;
|
||||
import com.zontreck.configs.server.AEServerConfig;
|
||||
import com.zontreck.effects.ModEffects;
|
||||
import com.zontreck.effects.ModPotions;
|
||||
import com.zontreck.enchantments.ModEnchantments;
|
||||
import com.zontreck.entities.ModEntities;
|
||||
import com.zontreck.items.DeprecatedModItems;
|
||||
import com.zontreck.items.ModItems;
|
||||
import com.zontreck.libzontreck.config.ServerConfig;
|
||||
import net.minecraft.client.renderer.entity.EntityRenderers;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.eventbus.api.IEventBus;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.ModLoadingContext;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import org.slf4j.ILoggerFactory;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.Random;
|
||||
import java.util.logging.LogManager;
|
||||
|
||||
@Mod(AriasEssentials.MOD_ID)
|
||||
public final class AriasEssentials {
|
||||
public static Logger LOGGER = LoggerFactory.getLogger("ariaessentials");
|
||||
public static final String MOD_ID = "ariasessentials";
|
||||
public static final Random random = new Random(Instant.now().getEpochSecond());
|
||||
|
||||
public AriasEssentials() {
|
||||
// This code runs as soon as Minecraft is in a mod-load-ready state.
|
||||
// However, some things (like registries and resources) may still be uninitialized.
|
||||
// Proceed with mild caution.
|
||||
|
||||
IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus();
|
||||
LOGGER.info("/!\\ Loading Aria's Essentials Configuration Files /!\\");
|
||||
AEServerConfig.loadFromFile();
|
||||
AEClientConfig.loadFromFile();
|
||||
ServerConfig.init();
|
||||
LOGGER.info("/!\\ DONE LOADING AECONFIG /!\\");
|
||||
|
||||
ModItems.ITEMS.register(bus);
|
||||
ModEntities.register(bus);
|
||||
ModEffects.register(bus);
|
||||
ModPotions.register(bus);
|
||||
DeprecatedModItems.register(bus);
|
||||
ModEnchantments.register(bus);
|
||||
DeprecatedModBlocks.register(bus);
|
||||
ModBlocks.register(bus);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD, value = Dist.CLIENT)
|
||||
public static class ClientModEvents {
|
||||
@SubscribeEvent
|
||||
public static void onClientSetup(FMLClientSetupEvent ev) {
|
||||
EntityRenderers.register(ModEntities.TIAB_ENTITY.get(), TimeBoostEntityRenderer::new);
|
||||
}
|
||||
}
|
||||
}
|
204
src/main/java/com/zontreck/Messages.java
Normal file
204
src/main/java/com/zontreck/Messages.java
Normal file
|
@ -0,0 +1,204 @@
|
|||
package com.zontreck;
|
||||
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
|
||||
public class Messages {
|
||||
public static final String ESSENTIALS_PREFIX;
|
||||
public static final String RTP_SEARCHING;
|
||||
public static final String RTP_CANCELLED;
|
||||
public static final String RTP_ABORTED;
|
||||
public static final String CONDITIONAL_RTP_ABORT;
|
||||
|
||||
public static final String HOVER_WARP_INFO;
|
||||
public static final String WARP_OWNER;
|
||||
public static final String WARP_HOVER_FORMAT;
|
||||
public static final String WARP_RTP;
|
||||
public static final String COUNT;
|
||||
public static final String WARP_STANDARD;
|
||||
|
||||
public static final String WARP_ACCESS_FORMAT;
|
||||
public static final String PUBLIC;
|
||||
public static final String PRIVATE;
|
||||
|
||||
public static final String WARP_NAME_REQUIRED;
|
||||
public static final String WARP_NOT_EXIST;
|
||||
public static final String WARP_ATTEMPTING;
|
||||
public static final String WARPING;
|
||||
public static final String WARP_CREATED;
|
||||
public static final String WARP_CREATE_ERROR;
|
||||
public static final String WARP_RTP_CREATED;
|
||||
public static final String WARP_RTP_FOUND;
|
||||
public static final String WARP_DELETE_SUCCESS;
|
||||
public static final String WARP_DELETE_FAIL;
|
||||
|
||||
public static final String TELEPORT_REQUEST_NOT_FOUND;
|
||||
public static final String TELEPORT_REQUEST_DENIED;
|
||||
public static final String TELEPORT_REQUEST_CANCELLED;
|
||||
|
||||
public static final String TELEPORT_ACCEPT;
|
||||
public static final String TELEPORT_DENY;
|
||||
public static final SoundEvent TPA_SOUND;
|
||||
public static final String TPA_HERE;
|
||||
|
||||
public static final String PLAYER_NOT_FOUND;
|
||||
public static final String NO_TP_TO_SELF;
|
||||
public static final String NO_MORE_THAN_ONE_TPA;
|
||||
public static final String TPA;
|
||||
|
||||
public static final String HOME_FORMAT;
|
||||
public static final String HOME_HOVER_TEXT;
|
||||
public static final String HOME_COUNT;
|
||||
|
||||
public static final String TELEPORT_REQUEST_ACCEPTED;
|
||||
|
||||
public static final String TELEPORTING_HOME;
|
||||
public static final String TELEPORT_HOME_FAIL;
|
||||
|
||||
public static final String HOME_DELETE_SUCCESS;
|
||||
public static final String HOME_DELETE_FAIL;
|
||||
|
||||
public static final String HOME_CREATE_SUCCESS;
|
||||
public static final String HOME_CREATE_FAIL;
|
||||
|
||||
public static final String PAYMENT_ATTEMPTING;
|
||||
public static final String PAYMENT_FAILED;
|
||||
public static final String PAYMENT_SUCCESS;
|
||||
|
||||
public static final String HEARTS_USAGE;
|
||||
public static final String HEARTS_UPDATED;
|
||||
public static final String RESPAWNING;
|
||||
public static final String RTP_CACHED;
|
||||
public static final String NO_BACK;
|
||||
public static final String TELEPORT_BACK;
|
||||
public static final String TELEPORT_BACK_DISABLED;
|
||||
public static final String TELEPORT_BACK_LAST;
|
||||
public static final String TELEPORT_BACK_NO_LAST;
|
||||
public static final String USE_BACK_INTRO;
|
||||
public static final String COOLDOWN_IN_PROGRESS;
|
||||
public static final String TP_EFFECTS_TOGGLED;
|
||||
|
||||
|
||||
|
||||
public static final String PREFIX_UPDATED;
|
||||
public static final String PREFIX_COLOR_UPDATED;
|
||||
public static final String NICK_UPDATED;
|
||||
public static final String NAME_COLOR_UPDATED;
|
||||
public static final String CHAT_COLOR_UPDATED;
|
||||
public static final String CONSOLE_ERROR;
|
||||
public static final String STARTER_FAILURE_PERMISSIONS;
|
||||
public static final String STARTER_KIT_GIVEN;
|
||||
|
||||
public static final String FLIGHT_GIVEN;
|
||||
public static final String FLIGHT_REMOVED;
|
||||
public static final String BUILDER_DIMENSION_DISALLOWED;
|
||||
|
||||
|
||||
static{
|
||||
ESSENTIALS_PREFIX = "!Gray![!Dark_Green!AE!Gray!] ";
|
||||
|
||||
WARP_ATTEMPTING = ESSENTIALS_PREFIX + "!Dark_Green!Attempting to find a safe landing location. This may take a minute";
|
||||
WARPING = ESSENTIALS_PREFIX+"!Dark_Green!Warping";
|
||||
|
||||
WARP_RTP_FOUND = ESSENTIALS_PREFIX + "!Dark_Green!A suitable location has been found";
|
||||
RTP_SEARCHING = ESSENTIALS_PREFIX + "!Dark_Purple!Searching... Attempt !Gold![0]!White!/!Dark_Red![1]";
|
||||
RTP_CANCELLED = ESSENTIALS_PREFIX + "!Dark_Red!Last position was good, but another mod asked us not to send you there. This could happen with a claims mod.";
|
||||
RTP_ABORTED = ESSENTIALS_PREFIX + "!Dark_Red!Could not find a suitable location in [0] attempts. Giving up. [1]";
|
||||
CONDITIONAL_RTP_ABORT = "!Dark_Red!You may try again in !Gold![0] !Dark_Red!minutes and !Gold![1] !Dark_Red!second(s)";
|
||||
|
||||
HOVER_WARP_INFO = " !Gold![Hover to see the Warp's info]";
|
||||
WARP_HOVER_FORMAT = "[0] \n[1]"; // 0 = owner, 1 = public infos
|
||||
WARP_RTP = "!Dark_Purple!This warp is a RTP. It will position you randomly in the dimension [0]";
|
||||
WARP_STANDARD = "!Green!This is a standard warp.";
|
||||
WARP_OWNER = "!Dark_Purple!The warp's owner is [0][1]";
|
||||
COUNT = ESSENTIALS_PREFIX + "!Dark_Purple!There are [0] [1](s) available";
|
||||
|
||||
WARP_ACCESS_FORMAT = "!Dark_Purple!This warp is [0]";
|
||||
PUBLIC = "!Dark_Green!Public";
|
||||
PRIVATE = "!Dark_Red!Private";
|
||||
|
||||
WARP_NAME_REQUIRED = ESSENTIALS_PREFIX + "!Dark_Red!The warp name is required in order to warp. You can click this message to get a full list of the warps you have access to.";
|
||||
WARP_NOT_EXIST = ESSENTIALS_PREFIX + "!Dark_Red!No Such Warp";
|
||||
|
||||
WARP_CREATED = ESSENTIALS_PREFIX + "!Dark_Green!Warp created successfully";
|
||||
WARP_CREATE_ERROR = ESSENTIALS_PREFIX + "!Dark_Red!Warp could not be created due to [0]";
|
||||
|
||||
WARP_RTP_CREATED = WARP_CREATED+" with RTP properties";
|
||||
|
||||
|
||||
WARP_DELETE_SUCCESS = ESSENTIALS_PREFIX + "!Dark_Green!Warp successfully deleted";
|
||||
WARP_DELETE_FAIL = ESSENTIALS_PREFIX + "!Dark_Red!Warp could not be deleted";
|
||||
|
||||
|
||||
TELEPORT_REQUEST_NOT_FOUND = ESSENTIALS_PREFIX + "!Dark_Red!The teleport request could not be found. Perhaps it already expired or was cancelled/denied already.";
|
||||
TELEPORT_REQUEST_DENIED = ESSENTIALS_PREFIX + "!Dark_Red!Teleport request was denied";
|
||||
TELEPORT_REQUEST_CANCELLED = ESSENTIALS_PREFIX + "!Dark_Red!Teleport request was cancelled";
|
||||
TELEPORT_REQUEST_ACCEPTED = ESSENTIALS_PREFIX + "!Dark_Green!Teleport request was accepted";
|
||||
|
||||
TPA_SOUND = SoundEvents.ANVIL_FALL;
|
||||
TELEPORT_ACCEPT = "!Dark_Gray![!Dark_Green!Accept!Dark_Gray!]";
|
||||
TELEPORT_DENY = "!Dark_Gray![!Dark_Red!Deny!Dark_Gray!]";
|
||||
|
||||
TPA_HERE = "[0] !Bold!!Dark_Purple!is requesting you to teleport to them!\n\n";
|
||||
|
||||
PLAYER_NOT_FOUND = ESSENTIALS_PREFIX + "!Dark_Red!Error: Player not found";
|
||||
NO_TP_TO_SELF = ESSENTIALS_PREFIX + "!Dark_Red!You cannot teleport to yourself!";
|
||||
NO_MORE_THAN_ONE_TPA = ESSENTIALS_PREFIX + "!Dark_Red!You already have a TPA Request active, wait for it to expire, or use the cancel button/command";
|
||||
|
||||
TPA = "[0] !Bold!!Dark_Purple! is requesting to teleport to you!\n\n";
|
||||
|
||||
HOME_FORMAT = "!Dark_Gray![!Gold!Home!Dark_Gray!] !Bold!!Dark_Purple![0]";
|
||||
HOME_HOVER_TEXT = "!Bold!!Dark_Green!Click here to go to this home";
|
||||
HOME_COUNT = ESSENTIALS_PREFIX + "!Bold!!Dark_Purple!You have [0] total homes.";
|
||||
|
||||
TELEPORTING_HOME = ESSENTIALS_PREFIX + "!Dark_Green!Teleporting home now!";
|
||||
TELEPORT_HOME_FAIL = ESSENTIALS_PREFIX + "!Dark_Red!Home not found";
|
||||
|
||||
HOME_DELETE_FAIL = ESSENTIALS_PREFIX + "!Dark_Red!Home could not be deleted due to an unknown error";
|
||||
HOME_DELETE_SUCCESS = ESSENTIALS_PREFIX + "!Dark_Green!Home was successfully deleted";
|
||||
|
||||
HOME_CREATE_SUCCESS = ESSENTIALS_PREFIX + "!Dark_Green!Home was created or updated successfully";
|
||||
HOME_CREATE_FAIL = ESSENTIALS_PREFIX + "!Dark_Red!Home could not be created or updated";
|
||||
|
||||
PAYMENT_ATTEMPTING = ESSENTIALS_PREFIX + "!Dark_Green!Please wait... Attempting to pay [0] to [1]";
|
||||
PAYMENT_FAILED = ESSENTIALS_PREFIX + "!Dark_Red!Payment failed";
|
||||
PAYMENT_SUCCESS = ESSENTIALS_PREFIX + "!Dark_Green!Payment successful";
|
||||
|
||||
HEARTS_USAGE = ESSENTIALS_PREFIX + "!Dark_Green!This command allows you to toggle on and off the compressed hearts feature without editing the config file.\n\n!Gold!/hearts [true/false]";
|
||||
|
||||
HEARTS_UPDATED = ESSENTIALS_PREFIX + "!Dark_Red!Your hearts preferences have been updated";
|
||||
|
||||
RESPAWNING = ESSENTIALS_PREFIX + "!Dark_Green!Respawning at World Spawn";
|
||||
|
||||
RTP_CACHED = ESSENTIALS_PREFIX + "!Dark_Green!A new RTP location has been cached for [0]";
|
||||
|
||||
NO_BACK = ESSENTIALS_PREFIX + "!Dark_Green!Good news! You have not died recently, there is no saved back position";
|
||||
TELEPORT_BACK = ESSENTIALS_PREFIX + "!Dark_Purple!You are being taken back to your last death location now.";
|
||||
|
||||
TELEPORT_BACK_DISABLED = ESSENTIALS_PREFIX + "!Dark_Red!You are not an op, and the back command is disabled on this server.";
|
||||
|
||||
TELEPORT_BACK_NO_LAST = ESSENTIALS_PREFIX + "!Dark_Red!You have not teleported recently, nor died. There is nothing to go back to.";
|
||||
|
||||
TELEPORT_BACK_LAST = ESSENTIALS_PREFIX + "!Dark_Purple!You are being taken back to your last death or teleport location.";
|
||||
|
||||
USE_BACK_INTRO = ESSENTIALS_PREFIX + "!Dark_Purple!You died! Use the !Dark_Red!/back!Dark_Purple! command to go back to your last death location";
|
||||
|
||||
COOLDOWN_IN_PROGRESS = ESSENTIALS_PREFIX + "!Dark_Red!The command [0] is still on cooldown for another [1]";
|
||||
|
||||
TP_EFFECTS_TOGGLED = ESSENTIALS_PREFIX + "!Dark_Purple!The teleport effects preferences have been toggled to: [0]";
|
||||
|
||||
|
||||
|
||||
PREFIX_UPDATED = ESSENTIALS_PREFIX + " !Dark_Purple!Your prefix has been updated";
|
||||
PREFIX_COLOR_UPDATED = ESSENTIALS_PREFIX + "!Dark_Purple!Your prefix color has been updated";
|
||||
NICK_UPDATED = ESSENTIALS_PREFIX + "!Dark_Purple! Your nickname has been updated";
|
||||
NAME_COLOR_UPDATED = ESSENTIALS_PREFIX + "!Dark_Purple!Your name color has been updated";
|
||||
CHAT_COLOR_UPDATED = ESSENTIALS_PREFIX + "!Dark_Purple!Your chat color has been updated";
|
||||
CONSOLE_ERROR = ESSENTIALS_PREFIX + "!Dark_Red!This command can only be executed from within the game, and by a player";
|
||||
STARTER_FAILURE_PERMISSIONS = ESSENTIALS_PREFIX + "!Dark_Red!This command can only be executed by server operators";
|
||||
STARTER_KIT_GIVEN = ESSENTIALS_PREFIX + "!Dark_Purple!You have been given a starter kit. Welcome to the server.";
|
||||
FLIGHT_GIVEN = ESSENTIALS_PREFIX + "!Dark_Green!You start to feel lighter than a feather";
|
||||
FLIGHT_REMOVED = ESSENTIALS_PREFIX + "!Dark_Red!You have a sinking feeling you are no longer lighter than a feather.";
|
||||
BUILDER_DIMENSION_DISALLOWED = ESSENTIALS_PREFIX+"!Dark_Red!The builder dimension is disallowed for regular users. You must be a server operator.";
|
||||
}
|
||||
}
|
9
src/main/java/com/zontreck/ariaslib/http/HTTPMethod.java
Normal file
9
src/main/java/com/zontreck/ariaslib/http/HTTPMethod.java
Normal file
|
@ -0,0 +1,9 @@
|
|||
package dev.zontreck.ariaslib.http;
|
||||
|
||||
public enum HTTPMethod
|
||||
{
|
||||
GET,
|
||||
POST,
|
||||
PUT,
|
||||
DELETE
|
||||
}
|
15
src/main/java/com/zontreck/ariaslib/http/HTTPRequest.java
Normal file
15
src/main/java/com/zontreck/ariaslib/http/HTTPRequest.java
Normal file
|
@ -0,0 +1,15 @@
|
|||
package dev.zontreck.ariaslib.http;
|
||||
|
||||
public class HTTPRequest
|
||||
{
|
||||
|
||||
public String url;
|
||||
|
||||
public String method;
|
||||
public String body;
|
||||
public String contentType;
|
||||
|
||||
protected HTTPRequest(){
|
||||
|
||||
}
|
||||
}
|
134
src/main/java/com/zontreck/ariaslib/http/HTTPRequestBuilder.java
Normal file
134
src/main/java/com/zontreck/ariaslib/http/HTTPRequestBuilder.java
Normal file
|
@ -0,0 +1,134 @@
|
|||
package dev.zontreck.ariaslib.http;
|
||||
|
||||
|
||||
import java.io.*;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
public class HTTPRequestBuilder
|
||||
{
|
||||
|
||||
private HttpURLConnection connection;
|
||||
private URL url;
|
||||
private HTTPRequest request = new HTTPRequest();
|
||||
|
||||
public static HTTPRequestBuilder builder()
|
||||
{
|
||||
return new HTTPRequestBuilder();
|
||||
}
|
||||
|
||||
protected HTTPRequestBuilder()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the url in this request to the one supplied
|
||||
* @param url The url to connect to
|
||||
* @return Builder instance
|
||||
* @throws MalformedURLException If the URL supplied was invalid
|
||||
*/
|
||||
public HTTPRequestBuilder withURL( String url) throws MalformedURLException {
|
||||
request.url = url;
|
||||
this.url = new URL(url);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the HTTP Request method
|
||||
* @param method The method you want to use
|
||||
* @see HTTPMethod
|
||||
* @return Builder instance
|
||||
*/
|
||||
public HTTPRequestBuilder withMethod(HTTPMethod method)
|
||||
{
|
||||
switch(method)
|
||||
{
|
||||
case GET:
|
||||
{
|
||||
request.method = "GET";
|
||||
break;
|
||||
}
|
||||
case POST: {
|
||||
request.method = "POST";
|
||||
if(request.contentType.isEmpty()) request.contentType = "application/x-www-form-urlencoded";
|
||||
break;
|
||||
}
|
||||
case DELETE:{
|
||||
request.method = "DELETE";
|
||||
break;
|
||||
}
|
||||
case PUT:{
|
||||
request.method = "PUT";
|
||||
if(request.contentType.isEmpty()) request.contentType = "application/x-www-form-urlencoded";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the request body. This may only be processed by the server when using POST or PUT, depending on the server's setup
|
||||
* @param body The body to upload
|
||||
* @return Builder Instance
|
||||
*/
|
||||
public HTTPRequestBuilder withBody(String body)
|
||||
{
|
||||
request.body = body;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the content type header
|
||||
* Default: application/x-www-form-urlencoded for POST/PUT, and null/not present for GET
|
||||
* @param type
|
||||
* @return
|
||||
*/
|
||||
public HTTPRequestBuilder withContentType(String type)
|
||||
{
|
||||
request.contentType = type;
|
||||
return this;
|
||||
}
|
||||
|
||||
public HTTPResponse build()
|
||||
{
|
||||
try {
|
||||
connection = (HttpURLConnection) url.openConnection();
|
||||
connection.setRequestMethod(request.method);
|
||||
byte[] array = request.body.getBytes("UTF-8");
|
||||
connection.setRequestProperty("Content-Length" , "" + array.length);
|
||||
connection.setRequestProperty("Content-Type", request.contentType);
|
||||
connection.setDoInput(true);
|
||||
connection.setUseCaches(false);
|
||||
connection.setDoOutput(true);
|
||||
DataOutputStream dos = new DataOutputStream(connection.getOutputStream());
|
||||
dos.write(array);
|
||||
dos.flush();
|
||||
dos.close();
|
||||
|
||||
|
||||
// Get the response body
|
||||
InputStream inputStream = connection.getInputStream();
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
|
||||
StringBuilder response = new StringBuilder();
|
||||
String line;
|
||||
|
||||
while ((line = reader.readLine()) != null) {
|
||||
response.append(line);
|
||||
}
|
||||
reader.close();
|
||||
inputStream.close();
|
||||
|
||||
String responseBody = response.toString();
|
||||
|
||||
return new HTTPResponse(connection.getContentType(), connection.getResponseCode(), responseBody, request);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}finally {
|
||||
connection.disconnect();
|
||||
}
|
||||
}
|
||||
}
|
33
src/main/java/com/zontreck/ariaslib/http/HTTPResponse.java
Normal file
33
src/main/java/com/zontreck/ariaslib/http/HTTPResponse.java
Normal file
|
@ -0,0 +1,33 @@
|
|||
package dev.zontreck.ariaslib.http;
|
||||
|
||||
public class HTTPResponse
|
||||
{
|
||||
private String ContentType;
|
||||
private int ResponseCode;
|
||||
private String ResponseBody;
|
||||
private HTTPRequest OriginalRequest;
|
||||
|
||||
protected HTTPResponse(String contentType, int code, String body, HTTPRequest request){
|
||||
this.ContentType = contentType;
|
||||
this.ResponseCode = code;
|
||||
this.ResponseBody = body;
|
||||
this.OriginalRequest = request;
|
||||
|
||||
}
|
||||
|
||||
public String getContentType() {
|
||||
return ContentType;
|
||||
}
|
||||
|
||||
public int getResponseCode() {
|
||||
return ResponseCode;
|
||||
}
|
||||
|
||||
public String getResponseBody() {
|
||||
return ResponseBody;
|
||||
}
|
||||
|
||||
public HTTPRequest getOriginalRequest() {
|
||||
return OriginalRequest;
|
||||
}
|
||||
}
|
47
src/main/java/com/zontreck/ariaslib/terminal/Banners.java
Normal file
47
src/main/java/com/zontreck/ariaslib/terminal/Banners.java
Normal file
|
@ -0,0 +1,47 @@
|
|||
package com.zontreck.ariaslib.terminal;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Banners
|
||||
{
|
||||
|
||||
public static String generateBanner(String text) {
|
||||
int maxLength = calculateMaxLength(text);
|
||||
List<String> bannerLines = new ArrayList<>();
|
||||
StringBuilder border = new StringBuilder();
|
||||
for (int i = 0; i < maxLength + 4; i++) {
|
||||
border.append("*");
|
||||
}
|
||||
bannerLines.add(border.toString());
|
||||
bannerLines.add("* " + centerText(text, maxLength) + " *");
|
||||
bannerLines.add(border.toString());
|
||||
return String.join("\n", bannerLines);
|
||||
}
|
||||
|
||||
private static String centerText(String text, int maxLength) {
|
||||
StringBuilder centeredText = new StringBuilder();
|
||||
int spacesToAdd = (maxLength - text.length()) / 2;
|
||||
for (int i = 0; i < spacesToAdd; i++) {
|
||||
centeredText.append(" ");
|
||||
}
|
||||
centeredText.append(text);
|
||||
for (int i = 0; i < spacesToAdd; i++) {
|
||||
centeredText.append(" ");
|
||||
}
|
||||
if (centeredText.length() < maxLength) {
|
||||
centeredText.append(" ");
|
||||
}
|
||||
return centeredText.toString();
|
||||
}
|
||||
|
||||
private static int calculateMaxLength(String text) {
|
||||
int maxLength = 0;
|
||||
for (String line : text.split("\n")) {
|
||||
if (line.length() > maxLength) {
|
||||
maxLength = line.length();
|
||||
}
|
||||
}
|
||||
return maxLength;
|
||||
}
|
||||
}
|
86
src/main/java/com/zontreck/ariaslib/terminal/Task.java
Normal file
86
src/main/java/com/zontreck/ariaslib/terminal/Task.java
Normal file
|
@ -0,0 +1,86 @@
|
|||
package com.zontreck.ariaslib.terminal;
|
||||
|
||||
import com.zontreck.ariaslib.util.Progress;
|
||||
|
||||
import java.util.TimerTask;
|
||||
|
||||
public abstract class Task extends TimerTask implements Runnable {
|
||||
public final String TASK_NAME;
|
||||
private TaskCompletionToken token = new TaskCompletionToken ( );
|
||||
|
||||
public static final String CHECK = "P";
|
||||
public static final String FAIL = "F";
|
||||
// Else use the progress spinner from the Progress class
|
||||
private boolean isSilent = false;
|
||||
|
||||
public Task ( String name ) {
|
||||
TASK_NAME = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* This constructor is meant to be used to create silent tasks that do not output to the console. (Example usage: DelayedExecutionService)
|
||||
*
|
||||
* @param name Task name
|
||||
* @param silent Whether to print to the terminal
|
||||
*/
|
||||
public Task ( String name , boolean silent ) {
|
||||
this ( name );
|
||||
isSilent = silent;
|
||||
}
|
||||
|
||||
|
||||
public boolean isComplete ( ) {
|
||||
return token.get ( );
|
||||
}
|
||||
|
||||
public void startTask ( ) {
|
||||
Thread tx = new Thread(this);
|
||||
tx.start();
|
||||
|
||||
if(! isSilent)
|
||||
{
|
||||
Thread tx2 = new Thread(new SpinnerTask(token, this));
|
||||
tx2.start();
|
||||
}
|
||||
}
|
||||
|
||||
public void stopTask ( ) {
|
||||
if ( token.get ( ) && ! isSilent ) {
|
||||
System.out.printf ( "\r" + TASK_NAME + "\t\t[" + token.status + "]\n" );
|
||||
}
|
||||
}
|
||||
|
||||
public void setSuccess ( ) {
|
||||
token.completed ( CHECK );
|
||||
}
|
||||
|
||||
public void setFail ( ) {
|
||||
token.completed ( FAIL );
|
||||
}
|
||||
|
||||
public class SpinnerTask extends Task {
|
||||
public final Task task;
|
||||
public final TaskCompletionToken token;
|
||||
private final Progress spinner = new Progress ( 100 );
|
||||
|
||||
public SpinnerTask ( TaskCompletionToken token , Task parent ) {
|
||||
super ( "spinner" , true );
|
||||
this.token = token;
|
||||
this.task = parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run ( ) {
|
||||
while ( ! task.isComplete ( ) ) {
|
||||
try {
|
||||
Thread.sleep ( 50L );
|
||||
|
||||
if ( ! task.isSilent && ! task.isComplete ( ) )
|
||||
System.out.printf ( "\r" + task.TASK_NAME + "\t\t" + spinner.getSpinnerTick ( ) + "\r" );
|
||||
} catch ( Exception e ) {
|
||||
e.printStackTrace ( );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package com.zontreck.ariaslib.terminal;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
/**
|
||||
* Should not be re-used for multiple tasks!!!
|
||||
*/
|
||||
public class TaskCompletionToken
|
||||
{
|
||||
private AtomicBoolean complete = new AtomicBoolean(false);
|
||||
public String status = "";
|
||||
public void completed(String reason){
|
||||
status=reason;
|
||||
complete.set(true);
|
||||
}
|
||||
|
||||
public boolean get(){
|
||||
return complete.get();
|
||||
}
|
||||
}
|
51
src/main/java/com/zontreck/ariaslib/util/FileIO.java
Normal file
51
src/main/java/com/zontreck/ariaslib/util/FileIO.java
Normal file
|
@ -0,0 +1,51 @@
|
|||
package com.zontreck.ariaslib.util;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
public class FileIO
|
||||
{
|
||||
|
||||
public static String readFile(String filePath) {
|
||||
try {
|
||||
byte[] fileBytes = Files.readAllBytes(Paths.get(filePath));
|
||||
return new String(fileBytes);
|
||||
} catch (IOException e) {
|
||||
return "An error occurred: " + e.getMessage();
|
||||
}
|
||||
}
|
||||
public static void writeFile(String filePath, String newContent) {
|
||||
try {
|
||||
Files.write(Paths.get(filePath), newContent.getBytes());
|
||||
} catch (IOException e) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Recursively delete a directory
|
||||
* @param directory The folder to delete
|
||||
*/
|
||||
public static void deleteDirectory(File directory) {
|
||||
if (directory.exists()) {
|
||||
File[] files = directory.listFiles();
|
||||
if (files != null) {
|
||||
for (File file : files) {
|
||||
if (file.isDirectory()) {
|
||||
deleteDirectory(file);
|
||||
} else {
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
// Now directory is empty, so delete it
|
||||
directory.delete();
|
||||
System.out.println("Directory deleted: " + directory.getAbsolutePath());
|
||||
} else {
|
||||
System.out.println("Directory does not exist: " + directory.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
120
src/main/java/com/zontreck/ariaslib/util/Hashing.java
Normal file
120
src/main/java/com/zontreck/ariaslib/util/Hashing.java
Normal file
|
@ -0,0 +1,120 @@
|
|||
package com.zontreck.ariaslib.util;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
public class Hashing
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* A md5 hashing function that is compatible with literally every other hashing function out there
|
||||
* @param input The string to hash
|
||||
* @return The hash
|
||||
*/
|
||||
public static String md5(String input) {
|
||||
try {
|
||||
MessageDigest md = MessageDigest.getInstance("MD5");
|
||||
md.update(input.getBytes());
|
||||
|
||||
byte[] byteData = md.digest();
|
||||
|
||||
// Convert the byte array to a hexadecimal string
|
||||
StringBuilder hexString = new StringBuilder();
|
||||
for (byte aByteData : byteData) {
|
||||
String hex = Integer.toHexString(0xff & aByteData);
|
||||
if (hex.length() == 1) {
|
||||
hexString.append('0');
|
||||
}
|
||||
hexString.append(hex);
|
||||
}
|
||||
return hexString.toString();
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* A md5 hashing function that is compatible with literally every other hashing function out there
|
||||
* @param input The bytes to hash
|
||||
* @return The hash
|
||||
*/
|
||||
public static String md5(byte[] input) {
|
||||
try {
|
||||
MessageDigest md = MessageDigest.getInstance("MD5");
|
||||
md.update(input);
|
||||
|
||||
byte[] byteData = md.digest();
|
||||
|
||||
// Convert the byte array to a hexadecimal string
|
||||
StringBuilder hexString = new StringBuilder();
|
||||
for (byte aByteData : byteData) {
|
||||
String hex = Integer.toHexString(0xff & aByteData);
|
||||
if (hex.length() == 1) {
|
||||
hexString.append('0');
|
||||
}
|
||||
hexString.append(hex);
|
||||
}
|
||||
return hexString.toString();
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A sha256 hashing function that is compatible with literally every other hashing function out there
|
||||
* @param input The string to hash
|
||||
* @return The hash
|
||||
*/
|
||||
public static String sha256(String input) {
|
||||
try {
|
||||
MessageDigest md = MessageDigest.getInstance("SHA256");
|
||||
md.update(input.getBytes());
|
||||
|
||||
byte[] byteData = md.digest();
|
||||
|
||||
// Convert the byte array to a hexadecimal string
|
||||
StringBuilder hexString = new StringBuilder();
|
||||
for (byte aByteData : byteData) {
|
||||
String hex = Integer.toHexString(0xff & aByteData);
|
||||
if (hex.length() == 1) {
|
||||
hexString.append('0');
|
||||
}
|
||||
hexString.append(hex);
|
||||
}
|
||||
return hexString.toString();
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* A sha256 hashing function that is compatible with literally every other hashing function out there
|
||||
* @param input The bytes to hash
|
||||
* @return The hash
|
||||
*/
|
||||
public static String sha256(byte[] input) {
|
||||
try {
|
||||
MessageDigest md = MessageDigest.getInstance("SHA256");
|
||||
md.update(input);
|
||||
|
||||
byte[] byteData = md.digest();
|
||||
|
||||
// Convert the byte array to a hexadecimal string
|
||||
StringBuilder hexString = new StringBuilder();
|
||||
for (byte aByteData : byteData) {
|
||||
String hex = Integer.toHexString(0xff & aByteData);
|
||||
if (hex.length() == 1) {
|
||||
hexString.append('0');
|
||||
}
|
||||
hexString.append(hex);
|
||||
}
|
||||
return hexString.toString();
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
94
src/main/java/com/zontreck/ariaslib/util/Lists.java
Normal file
94
src/main/java/com/zontreck/ariaslib/util/Lists.java
Normal file
|
@ -0,0 +1,94 @@
|
|||
package com.zontreck.ariaslib.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class Lists
|
||||
{
|
||||
/**
|
||||
* Programatically constructs a list
|
||||
* @param values The list of values
|
||||
* @return The new list
|
||||
* @param <T> An arbitrary type parameter
|
||||
*/
|
||||
public static <T> List<T> of(T... values)
|
||||
{
|
||||
List<T> arr = new ArrayList<>();
|
||||
for(T value : values)
|
||||
{
|
||||
arr.add(value);
|
||||
}
|
||||
|
||||
return arr;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Splits a string into a list
|
||||
* @param input The string to split
|
||||
* @param delimiters The list of delimiters
|
||||
* @return A non-strided list
|
||||
*/
|
||||
public static List<String> split(String input, String... delimiters) {
|
||||
List<String> result = new ArrayList<>();
|
||||
StringBuilder regex = new StringBuilder("(");
|
||||
|
||||
// Constructing the regular expression pattern with provided delimiters
|
||||
for (String delimiter : delimiters) {
|
||||
regex.append(delimiter).append("|");
|
||||
}
|
||||
regex.deleteCharAt(regex.length() - 1); // Remove the extra '|' character
|
||||
regex.append(")");
|
||||
|
||||
String[] tokens = input.split(regex.toString());
|
||||
|
||||
// Add non-empty tokens to the result list
|
||||
for (String token : tokens) {
|
||||
if (!token.isEmpty()) {
|
||||
result.add(token);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Split a string, and keep the delimiters
|
||||
* @param input The string to be parsed and split
|
||||
* @param delimiters A list of delimiters
|
||||
* @return A strided list containing the parsed options, and the delimiters
|
||||
*/
|
||||
public static List<String> splitWithDelim(String input, String... delimiters) {
|
||||
List<String> result = new ArrayList<>();
|
||||
StringBuilder regex = new StringBuilder("(");
|
||||
|
||||
// Constructing the regular expression pattern with provided delimiters
|
||||
for (String delimiter : delimiters) {
|
||||
regex.append(delimiter).append("|");
|
||||
}
|
||||
regex.deleteCharAt(regex.length() - 1); // Remove the extra '|' character
|
||||
regex.append(")");
|
||||
|
||||
// Splitting the input string using the regex pattern
|
||||
String[] tokens = input.split(regex.toString());
|
||||
|
||||
// Adding tokens and delimiters to the result list in a strided manner
|
||||
for (int i = 0; i < tokens.length; i++) {
|
||||
if (!tokens[i].isEmpty()) {
|
||||
result.add(tokens[i]);
|
||||
}
|
||||
// Adding delimiter if it exists and it's not the last token
|
||||
if (i < tokens.length - 1) {
|
||||
result.add(input.substring(input.indexOf(tokens[i]) + tokens[i].length(), input.indexOf(tokens[i + 1])));
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
private Lists(){
|
||||
|
||||
}
|
||||
}
|
49
src/main/java/com/zontreck/ariaslib/util/Maps.java
Normal file
49
src/main/java/com/zontreck/ariaslib/util/Maps.java
Normal file
|
@ -0,0 +1,49 @@
|
|||
package com.zontreck.ariaslib.util;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Utility class to assist in creating a dictionary programmatically in one line of code.
|
||||
*/
|
||||
public class Maps
|
||||
{
|
||||
/**
|
||||
* This takes a list of entries and returns a HashMap
|
||||
* @param entries The entries you want in your hashmap
|
||||
* @return The map itself
|
||||
* @param <A> Any typed parameter
|
||||
* @param <B> Any typed parameter
|
||||
*/
|
||||
public static <A,B> Map<A,B> of(Entry<A,B>... entries) {
|
||||
Map<A,B> map = new HashMap<>();
|
||||
for(Entry<A,B> E : entries)
|
||||
{
|
||||
map.put(E.key, E.value);
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* A virtual entry used only by the Maps#of function.
|
||||
* @see Maps#of(Entry[])
|
||||
* @param <A> Any typed parameter
|
||||
* @param <B> Any typed parameter
|
||||
*/
|
||||
public static class Entry<A,B> {
|
||||
public final A key;
|
||||
public final B value;
|
||||
|
||||
/**
|
||||
* Initializes the readonly entry
|
||||
* @param a The dictionary key
|
||||
* @param b The value
|
||||
*/
|
||||
public Entry(A a, B b)
|
||||
{
|
||||
this.key=a;
|
||||
this.value=b;
|
||||
}
|
||||
}
|
||||
}
|
18
src/main/java/com/zontreck/ariaslib/util/MathUtil.java
Normal file
18
src/main/java/com/zontreck/ariaslib/util/MathUtil.java
Normal file
|
@ -0,0 +1,18 @@
|
|||
package com.zontreck.ariaslib.util;
|
||||
|
||||
/**
|
||||
* This class will be used to house math helper functions
|
||||
*/
|
||||
public class MathUtil
|
||||
{
|
||||
/**
|
||||
* A newer helper function to get the percentage with large number support
|
||||
* @param current Min value
|
||||
* @param max Maximum value for progress
|
||||
* @return Percentage
|
||||
*/
|
||||
public static int getPercent(long current, long max)
|
||||
{
|
||||
return Math.round(current*100/max);
|
||||
}
|
||||
}
|
23
src/main/java/com/zontreck/ariaslib/util/Percent.java
Normal file
23
src/main/java/com/zontreck/ariaslib/util/Percent.java
Normal file
|
@ -0,0 +1,23 @@
|
|||
package com.zontreck.ariaslib.util;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
public class Percent
|
||||
{
|
||||
int current;
|
||||
int maximum;
|
||||
|
||||
public Percent(int cur, int max)
|
||||
{
|
||||
current=cur;
|
||||
maximum=max;
|
||||
}
|
||||
|
||||
|
||||
public int get()
|
||||
{
|
||||
return ((current * 100) / maximum);
|
||||
}
|
||||
|
||||
|
||||
}
|
56
src/main/java/com/zontreck/ariaslib/util/Progress.java
Normal file
56
src/main/java/com/zontreck/ariaslib/util/Progress.java
Normal file
|
@ -0,0 +1,56 @@
|
|||
package com.zontreck.ariaslib.util;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class Progress
|
||||
{
|
||||
private int maximum;
|
||||
private int current;
|
||||
private AtomicInteger tickNum = new AtomicInteger(0);
|
||||
private static final String TICKS="-\\|/";
|
||||
|
||||
public String getSpinnerTick()
|
||||
{
|
||||
if(tickNum.get()>=TICKS.length()) tickNum.set(0);
|
||||
|
||||
return "[" + TICKS.substring(tickNum.getAndIncrement(), tickNum.get()) + "]";
|
||||
}
|
||||
|
||||
public Progress(int maximum)
|
||||
{
|
||||
current=0;
|
||||
this.maximum=maximum;
|
||||
}
|
||||
|
||||
public int getPercent(){
|
||||
return (current*100/maximum);
|
||||
}
|
||||
|
||||
public String getPercentStr()
|
||||
{
|
||||
return (getPercent()+"%");
|
||||
}
|
||||
|
||||
public static int getPercentOf(int current, int max)
|
||||
{
|
||||
return (current*100/max);
|
||||
}
|
||||
|
||||
public void increment(){
|
||||
current++;
|
||||
sanity();
|
||||
}
|
||||
private void sanity(){
|
||||
if(current > maximum) current = maximum;
|
||||
if(current < 0)current = 0;
|
||||
}
|
||||
public void decrement(){
|
||||
current--;
|
||||
sanity();
|
||||
}
|
||||
|
||||
public void setCurrent(int cur)
|
||||
{
|
||||
current=cur;
|
||||
}
|
||||
}
|
66
src/main/java/com/zontreck/ariaslib/util/ProgressBar.java
Normal file
66
src/main/java/com/zontreck/ariaslib/util/ProgressBar.java
Normal file
|
@ -0,0 +1,66 @@
|
|||
package com.zontreck.ariaslib.util;
|
||||
|
||||
import java.io.PrintStream;
|
||||
|
||||
/**
|
||||
* Utility to create an ascii progress bar
|
||||
*/
|
||||
public class ProgressBar
|
||||
{
|
||||
|
||||
private static final int DEFAULT_BAR_WIDTH = 50;
|
||||
|
||||
/**
|
||||
* Reserved spaces for the brackets, and the carrot, and the percent value.
|
||||
*/
|
||||
private static final int PROGRESS_BAR_RESERVED=5;
|
||||
|
||||
/**
|
||||
* Always will return 80
|
||||
* @return 80
|
||||
*/
|
||||
private static int getConsoleWidth() {
|
||||
return 80; // Default console width, can be adjusted for different consoles
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a progress bar
|
||||
* <br><br>
|
||||
* your text here [========= ] 40% your text here
|
||||
* @param percent The percentage
|
||||
* @param beforeText
|
||||
* @param afterText
|
||||
* @return ProgressBar as a String
|
||||
*/
|
||||
public static String printProgressBar(int percent, String beforeText, String afterText) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
int consoleWidth = getConsoleWidth();
|
||||
int barWidth = Math.min(consoleWidth - beforeText.length() - afterText.length() - PROGRESS_BAR_RESERVED, DEFAULT_BAR_WIDTH);
|
||||
|
||||
// Calculate progress
|
||||
int progressBarLength = (int) ((double) percent / 100 * barWidth);
|
||||
|
||||
// Print before text
|
||||
sb.append(beforeText);
|
||||
|
||||
// Print progress bar
|
||||
sb.append("[");
|
||||
for (int i = 0; i < barWidth; i++) {
|
||||
if (i < progressBarLength) {
|
||||
sb.append("=");
|
||||
}else if(i==progressBarLength) sb.append(">");
|
||||
else {
|
||||
sb.append(" ");
|
||||
}
|
||||
}
|
||||
sb.append("]");
|
||||
|
||||
// Print percentage
|
||||
sb.append(" " + percent + "%");
|
||||
|
||||
// Print after text
|
||||
sb.append(afterText);
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
161
src/main/java/com/zontreck/ariaslib/util/TimeNotation.java
Normal file
161
src/main/java/com/zontreck/ariaslib/util/TimeNotation.java
Normal file
|
@ -0,0 +1,161 @@
|
|||
package com.zontreck.ariaslib.util;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Contains useful structures and functions for dealing with, and manipulation of, time.
|
||||
*/
|
||||
public class TimeNotation
|
||||
{
|
||||
public int Years;
|
||||
public int Months;
|
||||
public int Weeks;
|
||||
public int Days;
|
||||
public int Hours;
|
||||
public int Minutes;
|
||||
public int Seconds;
|
||||
|
||||
public TimeNotation(int years, int months, int weeks, int days, int hours, int minutes, int seconds)
|
||||
{
|
||||
Years=years;
|
||||
Months=months;
|
||||
Weeks=weeks;
|
||||
Days=days;
|
||||
Hours=hours;
|
||||
Minutes=minutes;
|
||||
Seconds = seconds;
|
||||
}
|
||||
|
||||
private TimeNotation(){}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String str =
|
||||
someOrNone(Years,Pluralize(Years, "year") + ", ") +
|
||||
someOrNone(Months, Pluralize(Months, "month") + ", ") +
|
||||
someOrNone(Weeks, Pluralize(Weeks, "week") + ", ") +
|
||||
someOrNone(Days, Pluralize(Days, "day") + ", ") +
|
||||
someOrNone(Hours, Pluralize(Hours, "hour") + ", ") +
|
||||
someOrNone(Minutes, Pluralize(Minutes, "minute") + ", ") +
|
||||
someOrNone(Seconds, Pluralize(Seconds, "second"));
|
||||
|
||||
if(str == ""){
|
||||
return "No Seconds";
|
||||
} else return str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a plural version for a number
|
||||
* @param num The number to prefix
|
||||
* @param str The singular form of the string
|
||||
* @return Combined string, num + str in plural form if necessary
|
||||
*/
|
||||
private String Pluralize(int num, String str)
|
||||
{
|
||||
return num + " " + ((num > 1) ? str+"s" : str);
|
||||
}
|
||||
|
||||
/**
|
||||
* A simple function to test a number, return a string, or return nothing at all.
|
||||
* @param num The number to check
|
||||
* @param str The string to return if the number is greater than zero
|
||||
* @return Str if num >1, or empty string
|
||||
*/
|
||||
private String someOrNone(int num, String str)
|
||||
{
|
||||
if(num > 0) return str;
|
||||
else return "";
|
||||
}
|
||||
/**
|
||||
* A simple function to test a number, return a string, or return something else.
|
||||
* @param num The number to check
|
||||
* @param str The string to return if the number is greater than zero
|
||||
* @return Str if num >1, or other string
|
||||
*/
|
||||
private String someOrOther(int num, String str, String other)
|
||||
{
|
||||
if(num > 0) return str;
|
||||
else return other;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes time notation!
|
||||
* @return A program readable string that can be decoded back to a time notation
|
||||
*/
|
||||
public String toNotation()
|
||||
{
|
||||
return Years + "Y" + Months + "M" + Weeks + "W" + Days + "d" + Hours + "h" + Minutes + "m" + Seconds + "s";
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a time notation string
|
||||
* @param notation Serialized time notation
|
||||
* @return The deserialized time notation object
|
||||
*/
|
||||
public static TimeNotation fromNotation(String notation)
|
||||
{
|
||||
TimeNotation notationX = new TimeNotation();
|
||||
String[] delims = new String[]{"Y", "M", "W", "d", "h", "m", "s"};
|
||||
List<String> opts = Lists.split(notation, delims);
|
||||
|
||||
|
||||
int index = 0;
|
||||
for(String dlim : delims)
|
||||
{
|
||||
if(notation.contains(dlim))
|
||||
{
|
||||
switch (dlim)
|
||||
{
|
||||
case "Y":
|
||||
{
|
||||
notationX.Years = Integer.parseInt(opts.get(index));
|
||||
|
||||
break;
|
||||
}
|
||||
case "M":
|
||||
{
|
||||
notationX.Months = Integer.parseInt(opts.get(index));
|
||||
|
||||
break;
|
||||
}
|
||||
case "W":
|
||||
{
|
||||
notationX.Weeks = Integer.parseInt(opts.get(index));
|
||||
|
||||
break;
|
||||
}
|
||||
case "d":
|
||||
{
|
||||
notationX.Days = Integer.parseInt(opts.get(index));
|
||||
|
||||
break;
|
||||
}
|
||||
case "h":
|
||||
{
|
||||
notationX.Hours = Integer.parseInt(opts.get(index));
|
||||
|
||||
break;
|
||||
}
|
||||
case "m":
|
||||
{
|
||||
notationX.Minutes = Integer.parseInt(opts.get(index));
|
||||
|
||||
break;
|
||||
}
|
||||
case "s":
|
||||
{
|
||||
notationX.Seconds = Integer.parseInt(opts.get(index));
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
return notationX;
|
||||
|
||||
}
|
||||
}
|
96
src/main/java/com/zontreck/ariaslib/util/TimeUtil.java
Normal file
96
src/main/java/com/zontreck/ariaslib/util/TimeUtil.java
Normal file
|
@ -0,0 +1,96 @@
|
|||
package com.zontreck.ariaslib.util;
|
||||
|
||||
/**
|
||||
* This class is a helper with some minecraft specific functions
|
||||
*/
|
||||
public class TimeUtil
|
||||
{
|
||||
/**
|
||||
* Converts seconds to ticks. (seconds*ticks)
|
||||
* @param seconds Number of seconds
|
||||
* @param ticks Number of ticks in a single second
|
||||
* @return Number of ticks
|
||||
*/
|
||||
public static int secondsToTicks(int seconds, int ticks)
|
||||
{
|
||||
return seconds*ticks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the number of ticks to seconds
|
||||
* @param ticks The number of ticks to convert
|
||||
* @param ticksInASecond The number of ticks in a single second
|
||||
* @return Number of seconds
|
||||
*/
|
||||
public static int ticksToSeconds(int ticks, int ticksInASecond)
|
||||
{
|
||||
return ticks / ticksInASecond;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encodes a LibAC Time Notation
|
||||
* @param seconds Number of seconds to convert
|
||||
* @return Time Notation
|
||||
*/
|
||||
public static TimeNotation secondsToTimeNotation(int seconds)
|
||||
{
|
||||
int years = seconds / YEAR;
|
||||
if(years > 0) seconds -= YEAR * years;
|
||||
|
||||
int month = seconds / MONTH;
|
||||
if(month > 0) seconds -= MONTH * month;
|
||||
|
||||
int week = seconds / WEEK;
|
||||
if(week > 0) seconds -= WEEK * week;
|
||||
|
||||
int day = seconds / DAY;
|
||||
if(day > 0) seconds -= DAY * day;
|
||||
|
||||
int hour = seconds / HOUR;
|
||||
if(hour > 0) seconds -= HOUR * hour;
|
||||
|
||||
int minute = seconds / MINUTE;
|
||||
if(minute > 0) seconds -= MINUTE * minute;
|
||||
|
||||
return new TimeNotation(years, month, week, day, hour, minute, seconds);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a time notation to seconds
|
||||
* @param notation Notation to convert
|
||||
* @return Total seconds
|
||||
*/
|
||||
public static int notationToSeconds(TimeNotation notation)
|
||||
{
|
||||
int seconds = 0;
|
||||
|
||||
seconds += (notation.Years * YEAR);
|
||||
seconds += (notation.Months * MONTH);
|
||||
seconds += (notation.Weeks * WEEK);
|
||||
seconds += (notation.Days * DAY);
|
||||
seconds += (notation.Hours * HOUR);
|
||||
seconds += (notation.Minutes * MINUTE);
|
||||
seconds += (notation.Seconds);
|
||||
|
||||
return seconds;
|
||||
}
|
||||
|
||||
|
||||
public static final int SECOND;
|
||||
public static final int MINUTE;
|
||||
public static final int HOUR;
|
||||
public static final int DAY;
|
||||
public static final int WEEK;
|
||||
public static final int MONTH;
|
||||
public static final int YEAR;
|
||||
|
||||
static {
|
||||
SECOND = 1;
|
||||
MINUTE = SECOND * 60;
|
||||
HOUR = MINUTE * 60;
|
||||
DAY = HOUR*24;
|
||||
WEEK = DAY*7;
|
||||
MONTH = WEEK*4;
|
||||
YEAR = DAY*365;
|
||||
}
|
||||
}
|
15
src/main/java/com/zontreck/block/DeprecatedBlock.java
Normal file
15
src/main/java/com/zontreck/block/DeprecatedBlock.java
Normal file
|
@ -0,0 +1,15 @@
|
|||
package com.zontreck.block;
|
||||
|
||||
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.state.BlockBehaviour;
|
||||
|
||||
@Deprecated
|
||||
public class DeprecatedBlock extends Block
|
||||
{
|
||||
public DeprecatedBlock(){
|
||||
super(BlockBehaviour.Properties.copy(Blocks.STONE).instabreak());
|
||||
}
|
||||
}
|
||||
|
45
src/main/java/com/zontreck/block/DeprecatedBlockItem.java
Normal file
45
src/main/java/com/zontreck/block/DeprecatedBlockItem.java
Normal file
|
@ -0,0 +1,45 @@
|
|||
package com.zontreck.block;
|
||||
|
||||
|
||||
import com.zontreck.libzontreck.util.ChatHelpers;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.item.BlockItem;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.TooltipFlag;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Deprecated
|
||||
public class DeprecatedBlockItem extends BlockItem
|
||||
{
|
||||
public DeprecatedBlockItem(Block a)
|
||||
{
|
||||
super(a, new Item.Properties().fireResistant());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFoil(ItemStack p_41453_) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is to give a use to an otherwise useless item. The piglins will exchange the item and it gets removed in that way.
|
||||
* @param stack
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean isPiglinCurrency(ItemStack stack) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendHoverText(ItemStack p_41421_, Level p_41422_, List<Component> p_41423_, TooltipFlag p_41424_) {
|
||||
p_41423_.add(ChatHelpers.macro("!Dark_Red!This block is deprecated"));
|
||||
p_41423_.add(ChatHelpers.macro("!Dark_Green!It would appear this block smells faintly of gold. Maybe piglins will accept it?"));
|
||||
p_41423_.add(ChatHelpers.macro("!Dark_Red!This block is scheduled for removal in a future version. You should use it before it is too late."));
|
||||
}
|
||||
}
|
||||
|
87
src/main/java/com/zontreck/block/DeprecatedModBlocks.java
Normal file
87
src/main/java/com/zontreck/block/DeprecatedModBlocks.java
Normal file
|
@ -0,0 +1,87 @@
|
|||
package com.zontreck.block;
|
||||
|
||||
|
||||
import com.zontreck.AriasEssentials;
|
||||
import com.zontreck.items.CreativeModeTabs;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.state.BlockBehaviour;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.material.Material;
|
||||
import net.minecraftforge.eventbus.api.IEventBus;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraftforge.registries.RegistryObject;
|
||||
|
||||
@Deprecated
|
||||
public class DeprecatedModBlocks
|
||||
{
|
||||
|
||||
public static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, AriasEssentials.MOD_ID);
|
||||
public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, AriasEssentials.MOD_ID);
|
||||
|
||||
|
||||
public static void register(IEventBus bus){
|
||||
BLOCKS.register(bus);
|
||||
ITEMS.register(bus);
|
||||
AriasEssentials.LOGGER.info("Registering all deprecated blocks...");
|
||||
}
|
||||
|
||||
private static boolean never(BlockState blockState, BlockGetter blockGetter, BlockPos blockPos) {
|
||||
return false;
|
||||
}
|
||||
private static boolean always(BlockState blockState, BlockGetter blockGetter, BlockPos blockPos) {
|
||||
return true;
|
||||
}
|
||||
|
||||
private static BlockBehaviour.Properties standardBehavior()
|
||||
{
|
||||
return BlockBehaviour.Properties.of(Material.STONE).requiresCorrectToolForDrops().strength(7F).destroyTime(6);
|
||||
}
|
||||
private static BlockBehaviour.Properties stoneLikeBehavior()
|
||||
{
|
||||
return BlockBehaviour.Properties.copy(Blocks.COBBLESTONE);
|
||||
}
|
||||
|
||||
private static BlockBehaviour.Properties explosionResistance()
|
||||
{
|
||||
return standardBehavior().explosionResistance(1200);
|
||||
}
|
||||
|
||||
private static BlockBehaviour.Properties noViewBlocking()
|
||||
{
|
||||
return standardBehavior().noOcclusion().isViewBlocking(DeprecatedModBlocks::never);
|
||||
}
|
||||
|
||||
private static BlockBehaviour.Properties fullBright()
|
||||
{
|
||||
return standardBehavior().lightLevel((X)->{
|
||||
return 15;
|
||||
}).noOcclusion();
|
||||
}
|
||||
|
||||
private static BlockBehaviour.Properties standard = standardBehavior();
|
||||
|
||||
private static BlockBehaviour.Properties explosionResistance = explosionResistance();
|
||||
|
||||
private static BlockBehaviour.Properties noViewBlocking = noViewBlocking();
|
||||
|
||||
private static BlockBehaviour.Properties stone = stoneLikeBehavior();
|
||||
|
||||
private static BlockBehaviour.Properties poolLightClean = BlockBehaviour.Properties.copy(Blocks.GLASS).lightLevel((X) -> 15);
|
||||
private static BlockBehaviour.Properties poolLightDirty = BlockBehaviour.Properties.copy(Blocks.GLASS).lightLevel((X) -> 12);
|
||||
private static BlockBehaviour.Properties poolLightFilthy = BlockBehaviour.Properties.copy(Blocks.GLASS).lightLevel((X) -> 4);
|
||||
|
||||
public static RegistryObject<Block> registerDeprecated(RegistryObject<Block> blk)
|
||||
{
|
||||
CreativeModeTabs.addToAETab(ITEMS.register(blk.getId().getPath(), ()->new DeprecatedBlockItem(blk.get())));
|
||||
|
||||
return blk;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
19
src/main/java/com/zontreck/block/FoiledBlockItem.java
Normal file
19
src/main/java/com/zontreck/block/FoiledBlockItem.java
Normal file
|
@ -0,0 +1,19 @@
|
|||
package com.zontreck.block;
|
||||
|
||||
import net.minecraft.world.item.BlockItem;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
|
||||
public class FoiledBlockItem extends BlockItem {
|
||||
|
||||
public FoiledBlockItem(Block pBlock, Properties pProperties) {
|
||||
super(pBlock, pProperties);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFoil(ItemStack pStack) {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
382
src/main/java/com/zontreck/block/ModBlocks.java
Normal file
382
src/main/java/com/zontreck/block/ModBlocks.java
Normal file
|
@ -0,0 +1,382 @@
|
|||
package com.zontreck.block;
|
||||
|
||||
|
||||
import com.zontreck.AriasEssentials;
|
||||
import com.zontreck.items.CreativeModeTabs;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.item.BlockItem;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.block.*;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.ShulkerBoxBlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockBehaviour;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.material.Material;
|
||||
import net.minecraftforge.eventbus.api.IEventBus;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraftforge.registries.RegistryObject;
|
||||
|
||||
public class ModBlocks {
|
||||
|
||||
private static BlockBehaviour.StatePredicate shulkerState = (p_152653_, p_152654_, p_152655_) -> {
|
||||
BlockEntity blockentity = p_152654_.getBlockEntity(p_152655_);
|
||||
if (!(blockentity instanceof ShulkerBoxBlockEntity)) {
|
||||
return true;
|
||||
} else {
|
||||
ShulkerBoxBlockEntity shulkerboxblockentity = (ShulkerBoxBlockEntity)blockentity;
|
||||
return shulkerboxblockentity.isClosed();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
public static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, AriasEssentials.MOD_ID);
|
||||
public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, AriasEssentials.MOD_ID);
|
||||
|
||||
private static boolean never(BlockState blockState, BlockGetter blockGetter, BlockPos blockPos) {
|
||||
return false;
|
||||
}
|
||||
private static boolean always(BlockState blockState, BlockGetter blockGetter, BlockPos blockPos) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private static boolean neverSpawn(BlockState blockState, BlockGetter blockGetter, BlockPos blockPos, EntityType<?> entityType) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void register(IEventBus bus){
|
||||
BLOCKS.register(bus);
|
||||
ITEMS.register(bus);
|
||||
AriasEssentials.LOGGER.info("Registering all blocks...");
|
||||
}
|
||||
|
||||
private static BlockBehaviour.Properties standardBehavior()
|
||||
{
|
||||
return BlockBehaviour.Properties.of(Material.STONE).requiresCorrectToolForDrops().strength(7F).destroyTime(6).isValidSpawn(ModBlocks::neverSpawn);
|
||||
}
|
||||
private static BlockBehaviour.Properties gratingBlock()
|
||||
{
|
||||
return standardBehavior()
|
||||
.noOcclusion()
|
||||
.strength(0.5f, 2000f)
|
||||
.isViewBlocking(ModBlocks::never);
|
||||
}
|
||||
|
||||
private static BlockBehaviour.Properties stoneLikeBehavior()
|
||||
{
|
||||
return BlockBehaviour.Properties.copy(Blocks.COBBLESTONE).isValidSpawn(ModBlocks::neverSpawn);
|
||||
}
|
||||
|
||||
private static BlockBehaviour.Properties explosionResistance()
|
||||
{
|
||||
return standardBehavior().explosionResistance(1200);
|
||||
}
|
||||
|
||||
private static BlockBehaviour.Properties noViewBlocking()
|
||||
{
|
||||
return standardBehavior().noOcclusion().isViewBlocking(ModBlocks::never);
|
||||
}
|
||||
|
||||
private static BlockBehaviour.Properties fullBright()
|
||||
{
|
||||
return standardBehavior().lightLevel((X)->{
|
||||
return 15;
|
||||
}).noOcclusion();
|
||||
}
|
||||
|
||||
private static BlockBehaviour.Properties standard = standardBehavior();
|
||||
|
||||
private static BlockBehaviour.Properties explosionResistance = explosionResistance();
|
||||
|
||||
private static BlockBehaviour.Properties noViewBlocking = noViewBlocking();
|
||||
|
||||
private static BlockBehaviour.Properties stone = stoneLikeBehavior();
|
||||
|
||||
private static BlockBehaviour.Properties gratingBlock = gratingBlock();
|
||||
|
||||
private static BlockBehaviour.Properties poolLightClean = BlockBehaviour.Properties.copy(Blocks.GLASS).lightLevel((X) -> 15);
|
||||
private static BlockBehaviour.Properties poolLightDirty = BlockBehaviour.Properties.copy(Blocks.GLASS).lightLevel((X) -> 12);
|
||||
private static BlockBehaviour.Properties poolLightFilthy = BlockBehaviour.Properties.copy(Blocks.GLASS).lightLevel((X) -> 4);
|
||||
|
||||
|
||||
public static RegistryObject<Block> registerWithItem(RegistryObject<Block> blk, Item.Properties props)
|
||||
{
|
||||
CreativeModeTabs.addToAETab(ITEMS.register(blk.getId().getPath(), ()->new BlockItem(blk.get(), props.tab(CreativeModeTabs.AETAB))));
|
||||
|
||||
return blk;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static final RegistryObject<Block> DARK_RED_WOOL = registerWithItem(BLOCKS.register("dark_red_wool", ()->new Block(BlockBehaviour.Properties.copy(Blocks.RED_WOOL))), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> DARK_RED_CARPET = registerWithItem(BLOCKS.register("dark_red_carpet", ()->new CarpetBlock(BlockBehaviour.Properties.copy(Blocks.RED_CARPET))), new Item.Properties());
|
||||
|
||||
|
||||
public static final RegistryObject<Block> ETERNIUM_ORE_BLOCK = registerWithItem(BLOCKS.register("eternium_ore_block", ()->new DropExperienceBlock(explosionResistance)), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> ETERNIUM_BLOCK = registerWithItem(BLOCKS.register("eternium_block", ()->new Block(explosionResistance)), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> DEEPSLATE_ETERNIUM_ORE_BLOCK = registerWithItem(BLOCKS.register("deepslate_eternium_ore_block", ()->new DropExperienceBlock(explosionResistance)), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> VOID = registerWithItem(BLOCKS.register("void", ()->new Block(fullBright().noCollission())), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> WHITEOUT = registerWithItem(BLOCKS.register("whiteout", ()->new Block(fullBright().noCollission())), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> BLOOD_RED = registerWithItem(BLOCKS.register("blood_red", ()->new Block(fullBright())), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> RED_TILE = registerWithItem(BLOCKS.register("red_tile", ()-> new Block(fullBright())), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> RED_STAIRS = registerWithItem(BLOCKS.register("red_stairs", ()-> new StairBlock(BLOOD_RED.get()::defaultBlockState, fullBright())), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> RED_TILE_BR = registerWithItem(BLOCKS.register("red_tile_br", ()->new RotatableBlock(fullBright())), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> RED_TILE_TO_WALL = registerWithItem(BLOCKS.register("red_tile_to_wall", ()->new Block(fullBright())), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> RED_WALL_V1 = registerWithItem(BLOCKS.register("red_wall_variant_1", ()->new Block(fullBright())), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> RED_WALL_V2 = registerWithItem(BLOCKS.register("red_wall_variant_2", ()->new Block(fullBright())), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> CYAN = registerWithItem(BLOCKS.register("cyan", ()->new Block(fullBright())), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> CYAN_TILE = registerWithItem(BLOCKS.register("cyan_tile", ()->new Block(fullBright())), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> CYAN_STAIRS = registerWithItem(BLOCKS.register("cyan_stairs", ()->new StairBlock(CYAN.get()::defaultBlockState, fullBright())), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> CYAN_TILE_BR = registerWithItem(BLOCKS.register("cyan_tile_br", ()->new RotatableBlock(fullBright())), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> CYAN_TILE_TO_WALL = registerWithItem(BLOCKS.register("cyan_tile_to_wall", ()->new Block(fullBright())), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> CYAN_WALL_V1 = registerWithItem(BLOCKS.register("cyan_wall_variant_1", ()->new Block(fullBright())), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> CYAN_WALL_V2 = registerWithItem(BLOCKS.register("cyan_wall_variant_2", ()->new Block(fullBright())), new Item.Properties());
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public static final RegistryObject<Block> POOL_TILE = registerWithItem(BLOCKS.register("pool_tile", ()->new Block(stone)), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> POOL_TILE_STAIRS = registerWithItem(BLOCKS.register("pool_tile_stairs", ()->new StairBlock(POOL_TILE.get()::defaultBlockState, stone)), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> POOL_TILE_SLAB = registerWithItem(BLOCKS.register("pool_tile_slab", ()->new SlabBlock(stone)), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> POOL_TILE_WALL = registerWithItem(BLOCKS.register("pool_tile_wall", ()->new WallBlock(stone)), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> POOL_LIGHT = registerWithItem(BLOCKS.register("pool_light", ()->new Block(poolLightClean)), new Item.Properties());
|
||||
|
||||
|
||||
|
||||
public static final RegistryObject<Block> DIRTY_POOL_TILE = registerWithItem(BLOCKS.register("dirty_pool_tile", ()->new Block(stone)), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> DIRTY_POOL_TILE_STAIRS = registerWithItem(BLOCKS.register("dirty_pool_tile_stairs", ()->new StairBlock(DIRTY_POOL_TILE.get()::defaultBlockState, stone)), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> DIRTY_POOL_TILE_SLAB = registerWithItem(BLOCKS.register("dirty_pool_tile_slab", ()-> new SlabBlock(stone)), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> DIRTY_POOL_TILE_WALL = registerWithItem(BLOCKS.register("dirty_pool_tile_wall", ()->new WallBlock(stone)), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> DIRTY_POOL_LIGHT = registerWithItem(BLOCKS.register("dirty_pool_light", ()->new Block(poolLightDirty)), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> FILTHY_POOL_LIGHT = registerWithItem(BLOCKS.register("filthy_pool_light", ()->new Block(poolLightFilthy)), new Item.Properties());
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public static final RegistryObject<Block> DARK_POOL_TILE = registerWithItem(BLOCKS.register("dark_pool_tile", ()->new Block(stone)), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> DARK_POOL_LIGHT = registerWithItem(BLOCKS.register("dark_pool_light", ()->new Block(poolLightClean)), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> DARK_POOL_TILE_STAIRS = registerWithItem(BLOCKS.register("dark_pool_tile_stairs", ()->new StairBlock(DARK_POOL_TILE.get()::defaultBlockState, stone)), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> DARK_POOL_TILE_SLAB = registerWithItem(BLOCKS.register("dark_pool_tile_slab",()-> new SlabBlock(stone)), new Item.Properties());
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public static final RegistryObject<Block> BLUE_POOL_TILE = registerWithItem(BLOCKS.register("blue_pool_tile",()-> new Block(stone)), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> BLUE_POOL_TILE_STAIRS = registerWithItem(BLOCKS.register("blue_pool_tile_stairs", ()->new StairBlock(BLUE_POOL_TILE.get()::defaultBlockState, stone)), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> BLUE_POOL_TILE_SLAB = registerWithItem(BLOCKS.register("blue_pool_tile_slab",()-> new SlabBlock(stone)), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> BLUE_POOL_TILE_WALL = registerWithItem(BLOCKS.register("blue_pool_tile_wall", ()->new WallBlock(stone)), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> BLUE_POOL_LIGHT = registerWithItem(BLOCKS.register("blue_pool_light", ()->new Block(poolLightClean)), new Item.Properties());
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public static final RegistryObject<Block> DIRTY_BLUE_POOL_TILE = registerWithItem(BLOCKS.register("dirty_blue_pool_tile", ()->new Block(stone)), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> DIRTY_BLUE_POOL_TILE_STAIRS = registerWithItem(BLOCKS.register("dirty_blue_pool_tile_stairs", ()->new StairBlock(DIRTY_BLUE_POOL_TILE.get()::defaultBlockState, stone)), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> DIRTY_BLUE_POOL_TILE_SLAB = registerWithItem(BLOCKS.register("dirty_blue_pool_tile_slab", ()->new SlabBlock(stone)), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> DIRTY_BLUE_POOL_TILE_WALL = registerWithItem(BLOCKS.register("dirty_blue_pool_tile_wall", ()->new WallBlock(stone)), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> DIRTY_BLUE_POOL_LIGHT = registerWithItem(BLOCKS.register("dirty_blue_pool_light", ()->new Block(poolLightDirty)), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> FILTHY_BLUE_POOL_LIGHT = registerWithItem(BLOCKS.register("filthy_blue_pool_light", ()->new Block(poolLightFilthy)), new Item.Properties());
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public static final RegistryObject<Block> RED_POOL_TILE = registerWithItem(BLOCKS.register("red_pool_tile", ()->new Block(stone)), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> RED_POOL_TILE_STAIRS = registerWithItem(BLOCKS.register("red_pool_tile_stairs", ()->new StairBlock(RED_POOL_TILE.get()::defaultBlockState, stone)), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> RED_POOL_TILE_SLAB = registerWithItem(BLOCKS.register("red_pool_tile_slab", ()->new SlabBlock(stone)), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> RED_POOL_TILE_WALL = registerWithItem(BLOCKS.register("red_pool_tile_wall", ()->new WallBlock(stone)), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> RED_POOL_LIGHT = registerWithItem(BLOCKS.register("red_pool_light", ()->new Block(poolLightClean)), new Item.Properties());
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public static final RegistryObject<Block> DIRTY_RED_POOL_TILE = registerWithItem(BLOCKS.register("dirty_red_pool_tile", ()->new Block(stone)), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> DIRTY_RED_POOL_LIGHT = registerWithItem(BLOCKS.register("dirty_red_pool_light", ()->new Block(poolLightDirty)), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> FILTHY_RED_POOL_LIGHT = registerWithItem(BLOCKS.register("filthy_red_pool_light", ()->new Block(poolLightFilthy)), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> DIRTY_RED_POOL_TILE_STAIRS = registerWithItem(BLOCKS.register("dirty_red_pool_tile_stairs", ()->new StairBlock(DIRTY_RED_POOL_TILE.get()::defaultBlockState, stone)), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> DIRTY_RED_POOL_TILE_SLAB = registerWithItem(BLOCKS.register("dirty_red_pool_tile_slab", ()->new SlabBlock(stone)), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> DIRTY_RED_POOL_TILE_WALL = registerWithItem(BLOCKS.register("dirty_red_pool_tile_wall", ()->new WallBlock(stone)), new Item.Properties());
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public static final RegistryObject<Block> GREEN_POOL_TILE = registerWithItem(BLOCKS.register("green_pool_tile", ()->new Block(stone)), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> GREEN_POOL_TILE_STAIRS = registerWithItem(BLOCKS.register("green_pool_tile_stairs", ()->new StairBlock(GREEN_POOL_TILE.get()::defaultBlockState, stone)), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> GREEN_POOL_TILE_SLAB = registerWithItem(BLOCKS.register("green_pool_tile_slab", ()->new SlabBlock(stone)), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> GREEN_POOL_TILE_WALL = registerWithItem(BLOCKS.register("green_pool_tile_wall", ()->new WallBlock(stone)), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> GREEN_POOL_LIGHT = registerWithItem(BLOCKS.register("green_pool_light", ()->new Block(poolLightClean)), new Item.Properties());
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public static final RegistryObject<Block> DIRTY_GREEN_POOL_TILE = registerWithItem(BLOCKS.register("dirty_green_pool_tile", ()->new Block(stone)), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> DIRTY_GREEN_POOL_LIGHT = registerWithItem(BLOCKS.register("dirty_green_pool_light", ()->new Block(poolLightDirty)), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> FILTHY_GREEN_POOL_LIGHT = registerWithItem(BLOCKS.register("filthy_green_pool_light", ()->new Block(poolLightFilthy)), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> DIRTY_GREEN_POOL_TILE_STAIRS = registerWithItem(BLOCKS.register("dirty_green_pool_tile_stairs", ()->new StairBlock(DIRTY_GREEN_POOL_TILE.get()::defaultBlockState, stone)), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> DIRTY_GREEN_POOL_TILE_SLAB = registerWithItem(BLOCKS.register("dirty_green_pool_tile_slab", ()->new SlabBlock(stone)), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> DIRTY_GREEN_POOL_TILE_WALL = registerWithItem(BLOCKS.register("dirty_green_pool_tile_wall", ()->new WallBlock(stone)), new Item.Properties());
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
|
||||
ENGINEERS DECOR BLOCKS
|
||||
|
||||
*/
|
||||
|
||||
public static final RegistryObject<Block> CLINKER_BRICK_BLOCK = registerWithItem(BLOCKS.register("clinker_brick_block", ()->new Block(standardBehavior().strength(0.5f, 7f).sound(SoundType.STONE)
|
||||
)), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> CLINKER_BRICK_SLAB = registerWithItem(BLOCKS.register("clinker_brick_slab", ()->new SlabBlock(BlockBehaviour.Properties.copy(Blocks.STONE_SLAB))), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> CLINKER_BRICK_STAIRS = registerWithItem(BLOCKS.register("clinker_brick_stairs", ()->new StairBlock(CLINKER_BRICK_BLOCK.get()::defaultBlockState, BlockBehaviour.Properties.copy(Blocks.STONE_STAIRS))), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> CLINKER_BRICK_WALL = registerWithItem(BLOCKS.register("clinker_brick_wall", ()->new WallBlock(BlockBehaviour.Properties.copy(Blocks.STONE_BRICK_WALL))), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> CLINKER_BRICK_STAINED_BLOCK = registerWithItem(BLOCKS.register("clinker_brick_stained_block", ()->new Block(BlockBehaviour.Properties.copy(Blocks.STONE))), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> CLINKER_BRICK_STAINED_SLAB = registerWithItem(BLOCKS.register("clinker_brick_stained_slab", ()-> new SlabBlock(BlockBehaviour.Properties.copy(Blocks.STONE))), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> CLINKER_BRICK_STAINED_STAIRS = registerWithItem(BLOCKS.register("clinker_brick_stained_stairs", ()-> new StairBlock(CLINKER_BRICK_STAINED_BLOCK.get()::defaultBlockState, BlockBehaviour.Properties.copy(Blocks.STONE))), new Item.Properties());
|
||||
|
||||
/*public static final RegistryObject<Block> CLINKER_BRICK_VERTICAL_SLAB_STRUCTURED = registerWithItem(BLOCKS.register("clinker_brick_vertical_slab_structured", () -> new StandardBlocks.HorizontalWaterLoggable(
|
||||
StandardBlocks.CFG_CUTOUT | StandardBlocks.CFG_HORIZIONTAL | StandardBlocks.CFG_LOOK_PLACEMENT,
|
||||
BlockBehaviour.Properties.of().strength(0.5f, 7f).sound(SoundType.STONE),
|
||||
new AABB[]{
|
||||
Auxiliaries.getPixeledAABB(0, 0, 0, 16, 16, 8),
|
||||
}
|
||||
)), new Item.Properties());*/
|
||||
|
||||
public static final RegistryObject<Block> SLAG_BRICK_BLOCK = registerWithItem(BLOCKS.register("slag_brick_block", ()-> new Block(BlockBehaviour.Properties.copy(Blocks.STONE))), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> SLAG_BRICK_SLAB = registerWithItem(BLOCKS.register("slag_brick_slab", ()-> new SlabBlock(BlockBehaviour.Properties.copy(Blocks.STONE))), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> SLAG_BRICK_STAIRS = registerWithItem(BLOCKS.register("slag_brick_stairs", ()-> new StairBlock(SLAG_BRICK_BLOCK.get()::defaultBlockState, BlockBehaviour.Properties.copy(Blocks.STONE))), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> SLAG_BRICK_WALL = registerWithItem(BLOCKS.register("slag_brick_wall", ()-> new WallBlock(BlockBehaviour.Properties.copy(Blocks.STONE_BRICK_WALL))), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> REBAR_CONCRETE_BLOCK = registerWithItem(BLOCKS.register("rebar_concrete", ()-> new Block(BlockBehaviour.Properties.copy(Blocks.STONE).isValidSpawn(ModBlocks::neverSpawn).strength(1f, 2000f))), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> REBAR_CONCRETE_SLAB = registerWithItem(BLOCKS.register("rebar_concrete_slab", ()-> new SlabBlock(BlockBehaviour.Properties.copy(Blocks.STONE).strength(1f, 2000f).isValidSpawn(ModBlocks::neverSpawn))), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> REBAR_CONCRETE_STAIRS = registerWithItem(BLOCKS.register("rebar_concrete_stairs", ()-> new StairBlock(ModBlocks.REBAR_CONCRETE_BLOCK.get()::defaultBlockState, BlockBehaviour.Properties.copy(Blocks.STONE).strength(1f, 2000f).isValidSpawn(ModBlocks::neverSpawn))), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> REBAR_CONCRETE_WALL = registerWithItem(BLOCKS.register("rebar_concrete_wall", ()-> new WallBlock(BlockBehaviour.Properties.copy(Blocks.STONE).strength(1f, 2000f).isValidSpawn(ModBlocks::neverSpawn))), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> REBAR_CONCRETE_TILE_BLOCK = registerWithItem(BLOCKS.register("rebar_concrete_tile", ()-> new Block(BlockBehaviour.Properties.copy(Blocks.STONE).isValidSpawn(ModBlocks::neverSpawn).strength(1f, 2000f))), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> REBAR_CONCRETE_TILE_SLAB = registerWithItem(BLOCKS.register("rebar_concrete_tile_slab", ()-> new SlabBlock(BlockBehaviour.Properties.copy(Blocks.STONE).strength(1f, 2000f).isValidSpawn(ModBlocks::neverSpawn))), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> REBAR_CONCRETE_TILE_STAIRS = registerWithItem(BLOCKS.register("rebar_concrete_tile_stairs", ()-> new StairBlock(ModBlocks.REBAR_CONCRETE_BLOCK.get()::defaultBlockState, BlockBehaviour.Properties.copy(Blocks.STONE).strength(1f, 2000f).isValidSpawn(ModBlocks::neverSpawn))), new Item.Properties());
|
||||
|
||||
/*public static final RegistryObject<Block> REBAR_CONCRETE_HALFSLAB = registerWithItem(BLOCKS.register("halfslab_rebar_concrete", () -> new SlabSliceBlock(
|
||||
StandardBlocks.CFG_CUTOUT,
|
||||
BlockBehaviour.Properties.of().strength(1.0f, 2000f).sound(SoundType.STONE).isValidSpawn(ModBlocks::neverSpawn)
|
||||
)), new Item.Properties());*/
|
||||
|
||||
public static final RegistryObject<Block> PANZER_GLASS_BLOCK = registerWithItem(BLOCKS.register("panzerglass_block", ()-> new Block(noViewBlocking().noOcclusion().strength(0.5f, 2000f).isValidSpawn(ModBlocks::neverSpawn).sound(SoundType.METAL))), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> PANZER_GLASS_SLAB = registerWithItem(BLOCKS.register("panzerglass_slab", ()-> new SlabBlock(noViewBlocking().noOcclusion().strength(0.5f, 2000f).isValidSpawn(ModBlocks::neverSpawn).sound(SoundType.METAL))), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> OLD_INDUSTRIAL_WOOD_PLANKS = registerWithItem(BLOCKS.register("old_industrial_wood_planks", ()-> new Block(BlockBehaviour.Properties.copy(Blocks.OAK_PLANKS).strength(0.5f, 6f).sound(SoundType.WOOD))), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> OLD_INDUSTRIAL_WOOD_SLAB = registerWithItem(BLOCKS.register("old_industrial_wood_slab", ()-> new SlabBlock(BlockBehaviour.Properties.copy(Blocks.OAK_PLANKS).strength(0.5f, 6f).sound(SoundType.WOOD))), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> OLD_INDUSTRIAL_WOOD_STAIRS = registerWithItem(BLOCKS.register("old_industrial_wood_stairs", ()-> new StairBlock(ModBlocks.OLD_INDUSTRIAL_WOOD_PLANKS.get()::defaultBlockState, BlockBehaviour.Properties.copy(Blocks.OAK_PLANKS).strength(0.5f, 6f).sound(SoundType.WOOD))), new Item.Properties());
|
||||
|
||||
public static final RegistryObject<Block> OLD_INDUSTRIAL_WOOD_DOOR = registerWithItem(BLOCKS.register("old_industrial_wood_door", ()-> new DoorBlock(BlockBehaviour.Properties.copy(Blocks.OAK_PLANKS).strength(0.5f, 6f).noOcclusion().sound(SoundType.WOOD))), new Item.Properties());
|
||||
|
||||
}
|
||||
|
19
src/main/java/com/zontreck/block/RegistryObj.java
Normal file
19
src/main/java/com/zontreck/block/RegistryObj.java
Normal file
|
@ -0,0 +1,19 @@
|
|||
package com.zontreck.block;
|
||||
|
||||
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraftforge.registries.RegistryObject;
|
||||
|
||||
public class RegistryObj
|
||||
{
|
||||
public RegistryObject<Block> block;
|
||||
public RegistryObject<? extends Item> item;
|
||||
|
||||
public RegistryObj(RegistryObject<Block> blk, RegistryObject<? extends Item> item)
|
||||
{
|
||||
this.block=blk;
|
||||
this.item=item;
|
||||
}
|
||||
}
|
||||
|
27
src/main/java/com/zontreck/block/RotatableBlock.java
Normal file
27
src/main/java/com/zontreck/block/RotatableBlock.java
Normal file
|
@ -0,0 +1,27 @@
|
|||
package com.zontreck.block;
|
||||
|
||||
|
||||
import net.minecraft.world.item.context.BlockPlaceContext;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.HorizontalDirectionalBlock;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.StateDefinition;
|
||||
|
||||
public class RotatableBlock extends HorizontalDirectionalBlock
|
||||
{
|
||||
protected RotatableBlock(Properties pProperties) {
|
||||
super(pProperties);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> pBuilder) {
|
||||
super.createBlockStateDefinition(pBuilder);
|
||||
pBuilder.add(FACING);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public BlockState getStateForPlacement(BlockPlaceContext pContext) {
|
||||
return defaultBlockState().setValue(FACING, pContext.getHorizontalDirection());
|
||||
}
|
||||
}
|
13
src/main/java/com/zontreck/block/VoidBlock.java
Normal file
13
src/main/java/com/zontreck/block/VoidBlock.java
Normal file
|
@ -0,0 +1,13 @@
|
|||
package com.zontreck.block;
|
||||
|
||||
|
||||
import net.minecraft.world.level.block.Block;
|
||||
|
||||
public class VoidBlock extends Block
|
||||
{
|
||||
public VoidBlock(Properties pProperties) {
|
||||
super(pProperties);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
package com.zontreck.block.types;
|
||||
|
||||
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.level.block.IronBarsBlock;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.properties.BooleanProperty;
|
||||
|
||||
import java.util.EnumMap;
|
||||
|
||||
/** Pane block with sensible culling */
|
||||
public class AlternatePaneBlock extends IronBarsBlock {
|
||||
public static final EnumMap<Direction, BooleanProperty> DIRECTIONS;
|
||||
static {
|
||||
DIRECTIONS = new EnumMap<>(Direction.class);
|
||||
DIRECTIONS.put(Direction.NORTH, NORTH);
|
||||
DIRECTIONS.put(Direction.EAST, EAST);
|
||||
DIRECTIONS.put(Direction.SOUTH, SOUTH);
|
||||
DIRECTIONS.put(Direction.WEST, WEST);
|
||||
}
|
||||
|
||||
public AlternatePaneBlock(Properties builder) {
|
||||
super(builder);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean skipRendering(BlockState state, BlockState adjacentBlockState, Direction side) {
|
||||
// cull top and bottom if all props that we have are contained in the above or below
|
||||
if (adjacentBlockState.getBlock() == this && side.getAxis().isVertical()) {
|
||||
for (Direction dir : Direction.Plane.HORIZONTAL) {
|
||||
BooleanProperty prop = DIRECTIONS.get(dir);
|
||||
if (state.getValue(prop) && !adjacentBlockState.getValue(prop)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return super.skipRendering(state, adjacentBlockState, side);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
package com.zontreck.client;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.math.Quaternion;
|
||||
import com.mojang.math.Vector3f;
|
||||
import com.zontreck.entities.TimeBoostEntity;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.Font;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.entity.EntityRenderer;
|
||||
import net.minecraft.client.renderer.entity.EntityRendererProvider;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
public class TimeBoostEntityRenderer extends EntityRenderer<TimeBoostEntity> {
|
||||
|
||||
public TimeBoostEntityRenderer(EntityRendererProvider.Context erp) {
|
||||
super(erp);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void render(TimeBoostEntity entity, float entityYaw, float partialTicks, PoseStack matrixStack, MultiBufferSource bufferIn, int packedLightIn) {
|
||||
String timeRate = "x" + 2 * entity.getTimeRate();
|
||||
float paddingLeftRight = 2 * entity.getTimeRate() < 10 ? 0.11F : 0.19F;
|
||||
drawText(matrixStack, timeRate, new Vector3f(-paddingLeftRight, 0.064F, 0.51F), Vector3f.YP.rotationDegrees(0), ChatFormatting.WHITE.getColor()); // Front
|
||||
drawText(matrixStack, timeRate, new Vector3f(paddingLeftRight, 0.064F, -0.51F), Vector3f.YP.rotationDegrees(180F), ChatFormatting.WHITE.getColor()); // Back
|
||||
drawText(matrixStack, timeRate, new Vector3f(0.51F, 0.064F, paddingLeftRight), Vector3f.YP.rotationDegrees(90F), ChatFormatting.WHITE.getColor()); // Right
|
||||
drawText(matrixStack, timeRate, new Vector3f(-0.51F, 0.064F, -paddingLeftRight), Vector3f.YP.rotationDegrees(-90F), ChatFormatting.WHITE.getColor()); // Left
|
||||
drawText(matrixStack, timeRate, new Vector3f(-paddingLeftRight, 0.51F, -0.064F), Vector3f.XP.rotationDegrees(90F), ChatFormatting.WHITE.getColor()); // Top
|
||||
drawText(matrixStack, timeRate, new Vector3f(-paddingLeftRight, -0.51F, 0.064F), Vector3f.XP.rotationDegrees(-90F), ChatFormatting.WHITE.getColor()); // Bottom
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation getTextureLocation(TimeBoostEntity entity) {
|
||||
return null;
|
||||
}
|
||||
|
||||
private void drawText(PoseStack matrixStack, String text, Vector3f translateVector, Quaternion rotate, int color) {
|
||||
matrixStack.pushPose();
|
||||
matrixStack.translate(translateVector.x(), translateVector.y(), translateVector.z());
|
||||
matrixStack.scale(0.02F, -0.02F, 0.02F);
|
||||
matrixStack.mulPose(rotate);
|
||||
Font fontRenderer = Minecraft.getInstance().gui.getFont();
|
||||
fontRenderer.draw(matrixStack, text, 0, 0, color);
|
||||
matrixStack.popPose();
|
||||
}
|
||||
}
|
31
src/main/java/com/zontreck/commands/CommandRegistry.java
Normal file
31
src/main/java/com/zontreck/commands/CommandRegistry.java
Normal file
|
@ -0,0 +1,31 @@
|
|||
package com.zontreck.commands;
|
||||
|
||||
import com.zontreck.commands.homes.DelHomeCommand;
|
||||
import com.zontreck.commands.homes.HomeCommand;
|
||||
import com.zontreck.commands.homes.HomesCommand;
|
||||
import com.zontreck.commands.homes.SetHomeCommand;
|
||||
import com.zontreck.commands.items.ShareItemInChatCommand;
|
||||
import com.zontreck.commands.items.TIABDebug;
|
||||
import com.zontreck.commands.teleport.*;
|
||||
import net.minecraftforge.event.RegisterCommandsEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
|
||||
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.FORGE)
|
||||
public class CommandRegistry
|
||||
{
|
||||
@SubscribeEvent
|
||||
public static void onCommandRegister(RegisterCommandsEvent ev) {
|
||||
TPACommand.register(ev.getDispatcher());
|
||||
TPAcceptCommand.register(ev.getDispatcher());
|
||||
TPDenyCommand.register(ev.getDispatcher());
|
||||
TPCancelCommand.register(ev.getDispatcher());
|
||||
TPAHereCommand.register(ev.getDispatcher());
|
||||
HomesCommand.register(ev.getDispatcher());
|
||||
SetHomeCommand.register(ev.getDispatcher());
|
||||
DelHomeCommand.register(ev.getDispatcher());
|
||||
HomeCommand.register(ev.getDispatcher());
|
||||
ShareItemInChatCommand.register(ev.getDispatcher());
|
||||
//TIABDebug.register(ev.getDispatcher());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
package com.zontreck.commands.homes;
|
||||
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.zontreck.Messages;
|
||||
import com.zontreck.events.CommandExecutionEvent;
|
||||
import com.zontreck.libzontreck.profiles.Profile;
|
||||
import com.zontreck.libzontreck.util.ChatHelpers;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
||||
public class DelHomeCommand {
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
|
||||
{
|
||||
dispatcher.register(
|
||||
Commands.literal("rmhome")
|
||||
.executes(c->rmHome(c.getSource(), "default"))
|
||||
.then(Commands.argument("nickname", StringArgumentType.string())
|
||||
.executes(c->rmHome(c.getSource(), StringArgumentType.getString(c, "nickname")))
|
||||
|
||||
)
|
||||
);
|
||||
|
||||
//dispatcher.register(Commands.literal("sethome").then(Commands.argument("nickname", StringArgumentType.string())).executes(command -> {
|
||||
//String arg = StringArgumentType.getString(command, "nickname");
|
||||
//return setHome(command.getSource(), arg);
|
||||
//}));
|
||||
}
|
||||
|
||||
private static int rmHome(CommandSourceStack ctx, String homeName)
|
||||
{
|
||||
|
||||
var exec = new CommandExecutionEvent(ctx.getPlayer(), "rmhome");
|
||||
if(MinecraftForge.EVENT_BUS.post(exec))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
// Request homes
|
||||
// String homeName = "";
|
||||
// CommandSourceStack ctx = ctx2.getSource();
|
||||
// homeName = StringArgumentType.getString(ctx2, "nickname");
|
||||
// if(homeName==null)return 0;
|
||||
try{
|
||||
ServerPlayer p = ctx.getPlayerOrException();
|
||||
|
||||
Profile prof = Profile.factory(p);
|
||||
prof.homes.delete(homeName);
|
||||
|
||||
prof.commit();
|
||||
|
||||
|
||||
ChatHelpers.broadcastTo(p, ChatHelpers.macro(Messages.HOME_DELETE_SUCCESS), ctx.getServer());
|
||||
}catch(Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
|
||||
ChatHelpers.broadcastTo(ctx.getEntity().getUUID(), ChatHelpers.macro(Messages.HOME_DELETE_FAIL), ctx.getServer());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
81
src/main/java/com/zontreck/commands/homes/HomeCommand.java
Normal file
81
src/main/java/com/zontreck/commands/homes/HomeCommand.java
Normal file
|
@ -0,0 +1,81 @@
|
|||
package com.zontreck.commands.homes;
|
||||
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.zontreck.Messages;
|
||||
import com.zontreck.events.CommandExecutionEvent;
|
||||
import com.zontreck.exceptions.NoSuchHomeException;
|
||||
import com.zontreck.homes.Home;
|
||||
import com.zontreck.libzontreck.profiles.Profile;
|
||||
import com.zontreck.libzontreck.util.ChatHelpers;
|
||||
import com.zontreck.util.TeleportActioner;
|
||||
import com.zontreck.util.TeleportContainer;
|
||||
import com.zontreck.util.TeleportDestination;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
||||
public class HomeCommand {
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
|
||||
{
|
||||
dispatcher.register(Commands.literal("home").executes(c-> home(c.getSource(), "default")).then(Commands.argument("name", StringArgumentType.string()).executes(c->home(c.getSource(), StringArgumentType.getString(c, "name")))));
|
||||
|
||||
//dispatcher.register(Commands.literal("sethome").then(Commands.argument("nickname", StringArgumentType.string())).executes(command -> {
|
||||
//String arg = StringArgumentType.getString(command, "nickname");
|
||||
//return setHome(command.getSource(), arg);
|
||||
//}));
|
||||
}
|
||||
|
||||
private static int home(CommandSourceStack ctx, String homeName)
|
||||
{
|
||||
var exec = new CommandExecutionEvent(ctx.getPlayer(), "home");
|
||||
if(MinecraftForge.EVENT_BUS.post(exec))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
// Request homes
|
||||
// String homeName = "";
|
||||
// CommandSourceStack ctx = ctx2.getSource();
|
||||
// homeName = StringArgumentType.getString(ctx2, "nickname");
|
||||
// if(homeName==null)return 0;
|
||||
try{
|
||||
ServerPlayer p = ctx.getPlayerOrException();
|
||||
Profile prof = Profile.factory(p);
|
||||
Home home = prof.homes.get(homeName);
|
||||
|
||||
//Transaction tx = new Transaction(Bank.getAccount(p.getUUID()), Bank.SYSTEM, AEServerConfig.COST_TO_TP_HOME.get(), Instant.now().getEpochSecond());
|
||||
|
||||
//ChatHelpers.broadcastTo(p.getUUID(), ChatHelpers.macro(Messages.PAYMENT_ATTEMPTING,
|
||||
// "$" + String.valueOf(AEServerConfig.COST_TO_TP_HOME.get()), "SYSTEM"), p.server);
|
||||
/*if(true)
|
||||
{
|
||||
ChatHelpers.broadcastTo(p.getUUID(), ChatHelpers.macro(Messages.PAYMENT_SUCCESS), p.server);
|
||||
}else {
|
||||
ChatHelpers.broadcastTo(p.getUUID(), ChatHelpers.macro(Messages.PAYMENT_FAILED), p.server);
|
||||
return 0;
|
||||
}*/
|
||||
|
||||
TeleportDestination dest = home.destination;
|
||||
TeleportActioner.ApplyTeleportEffect(p);
|
||||
TeleportContainer cont = new TeleportContainer(p, dest.Position.asMinecraftVector(), dest.Rotation.asMinecraftVector(), dest.getActualDimension());
|
||||
TeleportActioner.PerformTeleport(cont,false);
|
||||
|
||||
ChatHelpers.broadcastTo(p.getUUID(), ChatHelpers.macro(Messages.TELEPORTING_HOME), ctx.getServer());
|
||||
}catch(CommandSyntaxException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
return 1;
|
||||
}catch(NoSuchHomeException e)
|
||||
{
|
||||
|
||||
ChatHelpers.broadcastTo(ctx.getEntity().getUUID(), ChatHelpers.macro(Messages.TELEPORT_HOME_FAIL), ctx.getServer());
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
106
src/main/java/com/zontreck/commands/homes/HomesCommand.java
Normal file
106
src/main/java/com/zontreck/commands/homes/HomesCommand.java
Normal file
|
@ -0,0 +1,106 @@
|
|||
package com.zontreck.commands.homes;
|
||||
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.zontreck.Messages;
|
||||
import com.zontreck.events.CommandExecutionEvent;
|
||||
import com.zontreck.exceptions.NoSuchHomeException;
|
||||
import com.zontreck.homes.Home;
|
||||
import com.zontreck.homes.Homes;
|
||||
import com.zontreck.libzontreck.chat.ChatColor;
|
||||
import com.zontreck.libzontreck.chat.Clickable;
|
||||
import com.zontreck.libzontreck.chat.HoverTip;
|
||||
import com.zontreck.libzontreck.chestgui.ChestGUI;
|
||||
import com.zontreck.libzontreck.chestgui.ChestGUIButton;
|
||||
import com.zontreck.libzontreck.chestgui.ChestGUIIdentifier;
|
||||
import com.zontreck.libzontreck.lore.LoreEntry;
|
||||
import com.zontreck.libzontreck.profiles.Profile;
|
||||
import com.zontreck.libzontreck.profiles.UserProfileNotYetExistsException;
|
||||
import com.zontreck.libzontreck.util.ChatHelpers;
|
||||
import com.zontreck.libzontreck.vectors.Vector2i;
|
||||
import com.zontreck.util.TeleportActioner;
|
||||
import com.zontreck.util.TeleportContainer;
|
||||
import com.zontreck.util.TeleportDestination;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.Style;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
||||
public class HomesCommand {
|
||||
private static final ChestGUIIdentifier HOMES_GUI_ID = new ChestGUIIdentifier("homes-gui");
|
||||
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
|
||||
{
|
||||
dispatcher.register(Commands.literal("homes").executes(HomesCommand::getHomes));
|
||||
}
|
||||
|
||||
private static int getHomes(CommandContext<CommandSourceStack> ctx)
|
||||
{
|
||||
// Request homes
|
||||
try{
|
||||
ServerPlayer player = ctx.getSource().getPlayerOrException();
|
||||
|
||||
Profile prof = Profile.factory(player);
|
||||
Homes homes = prof.homes;
|
||||
|
||||
ChatHelpers.broadcastTo(player.getUUID(), ChatHelpers.macro(Messages.HOME_COUNT, String.valueOf(homes.count())), player.server);
|
||||
|
||||
ChestGUI gui = ChestGUI.builder().withGUIId(HOMES_GUI_ID).withTitle("Homes").withPlayer(player.getUUID());
|
||||
|
||||
int iconX = 0;
|
||||
int iconY = 0;
|
||||
|
||||
for (Home string : homes.getList()) {
|
||||
Style st = Style.EMPTY.withFont(Style.DEFAULT_FONT).withHoverEvent(HoverTip.get(ChatHelpers.macroize(Messages.HOME_HOVER_TEXT))).withClickEvent(Clickable.command("/home "+string.homeName));
|
||||
|
||||
ItemStack stack = string.homeIcon.copy();
|
||||
if(stack.is(Items.AIR))
|
||||
{
|
||||
stack = new ItemStack(Items.GRASS_BLOCK, 1);
|
||||
}
|
||||
stack.setHoverName(Component.literal(string.homeName));
|
||||
|
||||
ChestGUIButton button = new ChestGUIButton(stack, (stackx, container, lore)-> {
|
||||
|
||||
TeleportDestination dest = string.destination;
|
||||
TeleportActioner.ApplyTeleportEffect(player);
|
||||
TeleportContainer cont = new TeleportContainer(player, dest.Position.asMinecraftVector(), dest.Rotation.asMinecraftVector(), dest.getActualDimension());
|
||||
TeleportActioner.PerformTeleport(cont, false);
|
||||
gui.close();
|
||||
}, new Vector2i(iconX, iconY))
|
||||
.withInfo(new LoreEntry.Builder().text(ChatColor.doColors("!Dark_Green!Click here to go to this home")).build())
|
||||
.withInfo(new LoreEntry.Builder().text(ChatHelpers.macro("!Dark_Purple!This home is in the dimension [0]", string.destination.Dimension).getString()).bold(true).build());
|
||||
|
||||
iconY++;
|
||||
if(iconY>=9)
|
||||
{
|
||||
iconY=0;
|
||||
iconX++;
|
||||
}
|
||||
if(homes.count() > (2*9))
|
||||
ChatHelpers.broadcastTo(player.getUUID(), ChatHelpers.macro(Messages.HOME_FORMAT, string.homeName).setStyle(st), ctx.getSource().getServer());
|
||||
else
|
||||
gui.withButton(button); // Put this in the else case, to prevent a error when exceeding inventory slots
|
||||
|
||||
}
|
||||
|
||||
if(homes.count()<=27)
|
||||
gui.open();
|
||||
}catch(CommandSyntaxException ex)
|
||||
{
|
||||
ex.printStackTrace();
|
||||
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,95 @@
|
|||
package com.zontreck.commands.homes;
|
||||
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import com.zontreck.Messages;
|
||||
import com.zontreck.configs.server.AEServerConfig;
|
||||
import com.zontreck.events.CommandExecutionEvent;
|
||||
import com.zontreck.homes.Home;
|
||||
import com.zontreck.libzontreck.profiles.Profile;
|
||||
import com.zontreck.libzontreck.profiles.UserProfileNotYetExistsException;
|
||||
import com.zontreck.libzontreck.util.ChatHelpers;
|
||||
import com.zontreck.libzontreck.vectors.Vector2f;
|
||||
import com.zontreck.libzontreck.vectors.Vector3d;
|
||||
import com.zontreck.util.TeleportActioner;
|
||||
import com.zontreck.util.TeleportDestination;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.phys.Vec2;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
||||
public class SetHomeCommand {
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
|
||||
{
|
||||
dispatcher.register(
|
||||
Commands.literal("sethome")
|
||||
.executes(c->setHome(c.getSource(), "default"))
|
||||
.then(Commands.argument("nickname", StringArgumentType.string())
|
||||
.executes(c -> setHome(c.getSource(), StringArgumentType.getString(c, "nickname")))
|
||||
)
|
||||
|
||||
);
|
||||
|
||||
//dispatcher.register(Commands.literal("sethome").then(Commands.argument("nickname", StringArgumentType.string())).executes(command -> {
|
||||
//String arg = StringArgumentType.getString(command, "nickname");
|
||||
//return setHome(command.getSource(), arg);
|
||||
//}));
|
||||
}
|
||||
|
||||
private static int setHome(CommandSourceStack ctx, String homeName)
|
||||
{
|
||||
|
||||
var exec = new CommandExecutionEvent(ctx.getPlayer(), "sethome");
|
||||
if(MinecraftForge.EVENT_BUS.post(exec))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
// Request homes
|
||||
// String homeName = "";
|
||||
// CommandSourceStack ctx = ctx2.getSource();
|
||||
// homeName = StringArgumentType.getString(ctx2, "nickname");
|
||||
// if(homeName==null)return 0;
|
||||
|
||||
ServerPlayer p;
|
||||
try {
|
||||
p = ctx.getPlayerOrException();
|
||||
|
||||
|
||||
if(TeleportActioner.isBlacklistedDimension(p.getLevel()))
|
||||
{
|
||||
ChatHelpers.broadcastTo(p, ChatHelpers.macro(Messages.ESSENTIALS_PREFIX + AEServerConfig.getInstance().messages.BlacklistedDimensionError), p.server);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Vec3 position = p.position();
|
||||
Vec2 rot = p.getRotationVector();
|
||||
|
||||
TeleportDestination dest = new TeleportDestination(new Vector3d(position), new Vector2f(rot), p.getLevel());
|
||||
BlockState bs = p.getLevel().getBlockState(dest.Position.moveDown().asBlockPos());
|
||||
|
||||
Home newhome = new Home(p, homeName, dest, new ItemStack(p.getBlockStateOn().getBlock().asItem()));
|
||||
|
||||
Profile prof = Profile.factory(p);
|
||||
prof.homes.add(newhome);
|
||||
prof.commit();
|
||||
|
||||
|
||||
ChatHelpers.broadcastTo(p.getUUID(), ChatHelpers.macro(Messages.HOME_CREATE_SUCCESS), ctx.getServer());
|
||||
} catch (CommandSyntaxException e) {
|
||||
|
||||
ChatHelpers.broadcastTo(ctx.getEntity().getUUID(), ChatHelpers.macro(Messages.HOME_CREATE_FAIL), ctx.getServer());
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
package com.zontreck.commands.items;
|
||||
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.zontreck.Messages;
|
||||
import com.zontreck.libzontreck.chat.HoverTip;
|
||||
import com.zontreck.libzontreck.profiles.Profile;
|
||||
import com.zontreck.libzontreck.profiles.UserProfileNotYetExistsException;
|
||||
import com.zontreck.libzontreck.util.ChatHelpers;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.network.chat.MutableComponent;
|
||||
import net.minecraft.network.chat.Style;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.AirItem;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.server.ServerLifecycleHooks;
|
||||
|
||||
public class ShareItemInChatCommand {
|
||||
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
|
||||
{
|
||||
dispatcher.register(Commands.literal("shareitem").executes(c->share_item(c.getSource())));
|
||||
|
||||
//dispatcher.register(Commands.literal("sethome").then(Commands.argument("nickname", StringArgumentType.string())).executes(command -> {
|
||||
//String arg = StringArgumentType.getString(command, "nickname");
|
||||
//return setHome(command.getSource(), arg);
|
||||
//}));
|
||||
}
|
||||
|
||||
private static int share_item(CommandSourceStack source) {
|
||||
|
||||
if(source.getEntity() instanceof Player)
|
||||
{
|
||||
ServerPlayer play = (ServerPlayer)source.getEntity();
|
||||
ItemStack is = play.getItemInHand(InteractionHand.MAIN_HAND);
|
||||
if(is.getItem() instanceof AirItem)
|
||||
{
|
||||
play.displayClientMessage(ChatHelpers.macro(Messages.ESSENTIALS_PREFIX +" !Dark_Red!You cannot share air in the chat."), false);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Profile prof = Profile.factory(play);
|
||||
|
||||
|
||||
MutableComponent component = ChatHelpers.macro(Messages.ESSENTIALS_PREFIX).append(is.getDisplayName()).append(ChatHelpers.macro(" !White!-!Dark_Purple! Hover here to see the item that "+prof.name_color+prof.nickname+"!Dark_Purple! shared"));
|
||||
Style style = Style.EMPTY.withFont(Style.DEFAULT_FONT);
|
||||
component = component.withStyle(style.withHoverEvent(HoverTip.getItem(is)));
|
||||
|
||||
ChatHelpers.broadcast(component, ServerLifecycleHooks.getCurrentServer());
|
||||
|
||||
}else {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
54
src/main/java/com/zontreck/commands/items/TIABDebug.java
Normal file
54
src/main/java/com/zontreck/commands/items/TIABDebug.java
Normal file
|
@ -0,0 +1,54 @@
|
|||
package com.zontreck.commands.items;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.zontreck.configs.server.AEServerConfig;
|
||||
import com.zontreck.items.abstracts.AbstractTIAB;
|
||||
import com.zontreck.items.impl.TimeBottle;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
public class TIABDebug {
|
||||
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
|
||||
{
|
||||
dispatcher.register(Commands.literal("tiab_set_expire").executes(c->setBottleExpired(c.getSource())));
|
||||
|
||||
dispatcher.register(Commands.literal("tiab_shift_uses").executes(c->shiftBottleUses(c.getSource())));
|
||||
|
||||
dispatcher.register(Commands.literal("tiab_reset").executes(c->resetBottle(c.getSource())));
|
||||
|
||||
//dispatcher.register(Commands.literal("sethome").then(Commands.argument("nickname", StringArgumentType.string())).executes(command -> {
|
||||
//String arg = StringArgumentType.getString(command, "nickname");
|
||||
//return setHome(command.getSource(), arg);
|
||||
//}));
|
||||
}
|
||||
private static int setBottleExpired(CommandSourceStack stack) {
|
||||
ItemStack item = stack.getPlayer().getMainHandItem();
|
||||
TimeBottle TIAB = (TimeBottle) item.getItem();
|
||||
|
||||
TIAB.setTotalAccumulatedTime(item, Integer.MAX_VALUE);
|
||||
TIAB.setExpired(item);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static int shiftBottleUses(CommandSourceStack stack) {
|
||||
|
||||
ItemStack item = stack.getPlayer().getMainHandItem();
|
||||
TimeBottle TIAB = (TimeBottle) item.getItem();
|
||||
|
||||
TIAB.setStoredEnergy(item, 20 * AEServerConfig.getInstance().bottles.eachUseDuration * 20);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static int resetBottle(CommandSourceStack stack) {
|
||||
|
||||
ItemStack item = stack.getPlayer().getMainHandItem();
|
||||
item.setTag(new CompoundTag());
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
127
src/main/java/com/zontreck/commands/teleport/TPACommand.java
Normal file
127
src/main/java/com/zontreck/commands/teleport/TPACommand.java
Normal file
|
@ -0,0 +1,127 @@
|
|||
package com.zontreck.commands.teleport;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.zontreck.Messages;
|
||||
import com.zontreck.events.CommandExecutionEvent;
|
||||
import com.zontreck.libzontreck.chat.ChatColor;
|
||||
import com.zontreck.libzontreck.chat.Clickable;
|
||||
import com.zontreck.libzontreck.chat.HoverTip;
|
||||
import com.zontreck.libzontreck.profiles.Profile;
|
||||
import com.zontreck.libzontreck.profiles.UserProfileNotYetExistsException;
|
||||
import com.zontreck.libzontreck.util.ChatHelpers;
|
||||
import com.zontreck.util.TeleportContainer;
|
||||
import com.zontreck.util.TeleportRegistry;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.commands.arguments.EntityArgument;
|
||||
import net.minecraft.network.chat.ClickEvent;
|
||||
import net.minecraft.network.chat.HoverEvent;
|
||||
import net.minecraft.network.chat.Style;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
||||
public class TPACommand
|
||||
{
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
|
||||
{
|
||||
dispatcher.register(Commands.literal("tpa").executes(c->usage(c.getSource())).then(Commands.argument("player", EntityArgument.player()).executes(c -> tpa(c.getSource(), EntityArgument.getPlayer(c, "player")))));
|
||||
|
||||
//dispatcher.register(Commands.literal("sethome").then(Commands.argument("nickname", StringArgumentType.string())).executes(command -> {
|
||||
//String arg = StringArgumentType.getString(command, "nickname");
|
||||
//return setHome(command.getSource(), arg);
|
||||
//}));
|
||||
}
|
||||
|
||||
private static int tpa(CommandSourceStack source, ServerPlayer serverPlayer) {
|
||||
|
||||
var exec = new CommandExecutionEvent(source.getPlayer(), "tpa");
|
||||
if(MinecraftForge.EVENT_BUS.post(exec))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
// Send the request to player
|
||||
if(serverPlayer == null){
|
||||
source.sendFailure(ChatHelpers.macro(Messages.PLAYER_NOT_FOUND));
|
||||
return 1;
|
||||
}
|
||||
|
||||
ServerPlayer play = (ServerPlayer)source.getEntity();
|
||||
|
||||
|
||||
if(play.getUUID() == serverPlayer.getUUID()){
|
||||
source.sendFailure(ChatHelpers.macro(Messages.NO_TP_TO_SELF));
|
||||
return 1;
|
||||
}
|
||||
|
||||
final TeleportContainer cont = new TeleportContainer(play.getUUID(), serverPlayer.getUUID());
|
||||
|
||||
for(TeleportContainer cont2 : TeleportRegistry.get()){
|
||||
if(cont2.compareTo(cont)==0){
|
||||
ChatHelpers.broadcastTo(cont.FromPlayer, ChatHelpers.macro(Messages.NO_MORE_THAN_ONE_TPA), source.getServer());
|
||||
return 0;
|
||||
}else {
|
||||
if(cont2.FromPlayer == cont.FromPlayer){
|
||||
ChatHelpers.broadcastTo(cont.FromPlayer, ChatHelpers.macro(Messages.NO_MORE_THAN_ONE_TPA), source.getServer());
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ClickEvent ce = Clickable.command("/tpcancel "+cont.TeleportID.toString());
|
||||
HoverEvent he = HoverTip.get(ChatColor.DARK_GREEN+"Cancel this teleport request");
|
||||
|
||||
Style s = Style.EMPTY.withFont(Style.DEFAULT_FONT).withHoverEvent(he).withClickEvent(ce);
|
||||
|
||||
// Send the alerts
|
||||
ChatHelpers.broadcastTo(cont.FromPlayer, ChatHelpers.macro(ChatColor.BOLD + ChatColor.DARK_GREEN +"TPA Request Sent! ").append(ChatHelpers.macro(ChatColor.BOLD+ChatColor.DARK_GRAY+"["+ChatColor.DARK_RED+"X"+ChatColor.DARK_GRAY+"]").setStyle(s)), serverPlayer.server);
|
||||
|
||||
|
||||
ce = Clickable.command("/tpaccept "+cont.TeleportID.toString());
|
||||
he = HoverTip.get(ChatColor.DARK_GREEN + "Accept tp request");
|
||||
ClickEvent ce2 = Clickable.command("/tpdeny "+ cont.TeleportID);
|
||||
HoverEvent he2 = HoverTip.get(ChatColor.DARK_RED+"Deny this request");
|
||||
s = Style.EMPTY.withFont(Style.DEFAULT_FONT).withClickEvent(ce).withHoverEvent(he);
|
||||
|
||||
Style s2 = Style.EMPTY.withFont(Style.DEFAULT_FONT).withClickEvent(ce2).withHoverEvent(he2);
|
||||
|
||||
|
||||
|
||||
Profile p;
|
||||
try {
|
||||
p = Profile.get_profile_of(cont.FromPlayer.toString());
|
||||
} catch (UserProfileNotYetExistsException e) {
|
||||
return 1;
|
||||
}
|
||||
serverPlayer.playSound(Messages.TPA_SOUND, 1, serverPlayer.getRandom().nextFloat());
|
||||
ChatHelpers.broadcastTo(cont.ToPlayer, ChatHelpers.macro(Messages.TPA, p.name_color+p.nickname).
|
||||
append(ChatHelpers.macro(Messages.TELEPORT_ACCEPT+" ").setStyle(s)).
|
||||
append(ChatHelpers.macro(Messages.TELEPORT_DENY).setStyle(s2)), serverPlayer.server);
|
||||
|
||||
TeleportRegistry.get().add(cont);
|
||||
Thread tx = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
try {
|
||||
Thread.sleep(30 * 1000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if(!(TeleportRegistry.get().contains(cont)))return;
|
||||
TeleportRegistry.get().remove(cont);
|
||||
|
||||
ChatHelpers.broadcastTo(cont.ToPlayer, ChatHelpers.macro("!Dark_Red!Teleport request has expired"), cont.Dimension.getServer());
|
||||
ChatHelpers.broadcastTo(cont.FromPlayer, ChatHelpers.macro("!Dark_Red!Teleport request has expired"), cont.Dimension.getServer());
|
||||
}
|
||||
});
|
||||
tx.start();
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static int usage(CommandSourceStack source) {
|
||||
|
||||
source.sendSystemMessage(ChatHelpers.macro("/tpa USAGE\n\n "+ ChatColor.BOLD + ChatColor.DARK_GRAY+"/tpa "+ChatColor.DARK_RED+"target_player\n"));
|
||||
return 0;
|
||||
}
|
||||
}
|
127
src/main/java/com/zontreck/commands/teleport/TPAHereCommand.java
Normal file
127
src/main/java/com/zontreck/commands/teleport/TPAHereCommand.java
Normal file
|
@ -0,0 +1,127 @@
|
|||
package com.zontreck.commands.teleport;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.zontreck.Messages;
|
||||
import com.zontreck.events.CommandExecutionEvent;
|
||||
import com.zontreck.libzontreck.chat.ChatColor;
|
||||
import com.zontreck.libzontreck.chat.Clickable;
|
||||
import com.zontreck.libzontreck.chat.HoverTip;
|
||||
import com.zontreck.libzontreck.profiles.Profile;
|
||||
import com.zontreck.libzontreck.profiles.UserProfileNotYetExistsException;
|
||||
import com.zontreck.libzontreck.util.ChatHelpers;
|
||||
import com.zontreck.util.TeleportContainer;
|
||||
import com.zontreck.util.TeleportRegistry;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.commands.arguments.EntityArgument;
|
||||
import net.minecraft.network.chat.ClickEvent;
|
||||
import net.minecraft.network.chat.HoverEvent;
|
||||
import net.minecraft.network.chat.MutableComponent;
|
||||
import net.minecraft.network.chat.Style;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
||||
public class TPAHereCommand
|
||||
{
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
|
||||
{
|
||||
dispatcher.register(Commands.literal("tpahere").executes(c->usage(c.getSource())).then(Commands.argument("player", EntityArgument.player()).executes(c -> tpa(c.getSource(), EntityArgument.getPlayer(c, "player")))));
|
||||
|
||||
//dispatcher.register(Commands.literal("sethome").then(Commands.argument("nickname", StringArgumentType.string())).executes(command -> {
|
||||
//String arg = StringArgumentType.getString(command, "nickname");
|
||||
//return setHome(command.getSource(), arg);
|
||||
//}));
|
||||
}
|
||||
|
||||
private static int tpa(CommandSourceStack source, ServerPlayer serverPlayer) {
|
||||
|
||||
var exec = new CommandExecutionEvent(source.getPlayer(), "tpahere");
|
||||
if(MinecraftForge.EVENT_BUS.post(exec))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
// Send the request to player
|
||||
|
||||
ServerPlayer play = (ServerPlayer)source.getEntity();
|
||||
if(serverPlayer == null){
|
||||
source.sendFailure(ChatHelpers.macro(Messages.PLAYER_NOT_FOUND));
|
||||
return 1;
|
||||
}
|
||||
if(play.getUUID() == serverPlayer.getUUID()){
|
||||
source.sendFailure(ChatHelpers.macro(Messages.NO_TP_TO_SELF));
|
||||
return 1;
|
||||
}
|
||||
|
||||
final TeleportContainer cont = new TeleportContainer(serverPlayer.getUUID(), play.getUUID());
|
||||
|
||||
for(TeleportContainer cont2 : TeleportRegistry.get()){
|
||||
if(cont2.compareTo(cont)==0){
|
||||
ChatHelpers.broadcastTo(cont.ToPlayer, ChatHelpers.macro(Messages.NO_MORE_THAN_ONE_TPA), source.getServer());
|
||||
return 0;
|
||||
}else {
|
||||
if(cont2.ToPlayer.equals(cont.ToPlayer)){
|
||||
ChatHelpers.broadcastTo(cont.ToPlayer, ChatHelpers.macro(Messages.NO_MORE_THAN_ONE_TPA), source.getServer());
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ClickEvent ce = Clickable.command("/tpcancel "+cont.TeleportID.toString());
|
||||
HoverEvent he = HoverTip.get(ChatColor.DARK_GREEN+"Cancel this teleport request");
|
||||
|
||||
// Send the alerts
|
||||
MutableComponent component = ChatHelpers.macro("!Bold!!Dark_Green!TPA Request Sent! ");
|
||||
MutableComponent cancelation = ChatHelpers.macro("!Bold!!Dark_Gray![!Dark_Red!X!Dark_Gray!]");
|
||||
cancelation.setStyle(cancelation.getStyle().withClickEvent(ce).withHoverEvent(he));
|
||||
|
||||
component.append(cancelation);
|
||||
ChatHelpers.broadcastTo(cont.ToPlayer, component, serverPlayer.server);
|
||||
|
||||
Style s;
|
||||
|
||||
ce = Clickable.command("/tpaccept "+cont.TeleportID.toString());
|
||||
he = HoverTip.get(ChatColor.DARK_GREEN + "Accept tp request");
|
||||
ClickEvent ce2 = Clickable.command("/tpdeny "+ cont.TeleportID);
|
||||
HoverEvent he2 = HoverTip.get(ChatColor.DARK_RED+"Deny this request");
|
||||
s = Style.EMPTY.withFont(Style.DEFAULT_FONT).withClickEvent(ce).withHoverEvent(he);
|
||||
|
||||
Style s2 = Style.EMPTY.withFont(Style.DEFAULT_FONT).withClickEvent(ce2).withHoverEvent(he2);
|
||||
|
||||
Profile p;
|
||||
try {
|
||||
p = Profile.get_profile_of(cont.ToPlayer.toString());
|
||||
} catch (UserProfileNotYetExistsException e) {
|
||||
return 1;
|
||||
}
|
||||
serverPlayer.playSound(Messages.TPA_SOUND, 1, serverPlayer.getRandom().nextFloat());
|
||||
ChatHelpers.broadcastTo(cont.FromPlayer, ChatHelpers.macro(Messages.TPA_HERE, p.name_color+p.nickname).
|
||||
append(ChatHelpers.macro(Messages.TELEPORT_ACCEPT+" ").setStyle(s)).
|
||||
append(ChatHelpers.macro(Messages.TELEPORT_DENY).setStyle(s2)), serverPlayer.server);
|
||||
|
||||
TeleportRegistry.get().add(cont);
|
||||
|
||||
Thread tx = new Thread(new Runnable(){
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
try {
|
||||
Thread.sleep(30 * 1000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if(!(TeleportRegistry.get().contains(cont)))return;
|
||||
TeleportRegistry.get().remove(cont);
|
||||
|
||||
ChatHelpers.broadcastTo(cont.ToPlayer, ChatHelpers.macro("!Dark_Red!Teleport request has expired"), cont.Dimension.getServer());
|
||||
ChatHelpers.broadcastTo(cont.FromPlayer, ChatHelpers.macro("!Dark_Red!Teleport request has expired"), cont.Dimension.getServer());
|
||||
}
|
||||
});
|
||||
return 0;
|
||||
}
|
||||
|
||||
private static int usage(CommandSourceStack source) {
|
||||
source.sendSystemMessage(ChatHelpers.macro("/tpahere USAGE\n\n !Bold!!Dark_Gray!/tpahere !Dark_Red!target_player\n"));
|
||||
return 0;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
package com.zontreck.commands.teleport;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.zontreck.Messages;
|
||||
import com.zontreck.events.CommandExecutionEvent;
|
||||
import com.zontreck.libzontreck.util.ChatHelpers;
|
||||
import com.zontreck.util.TeleportActioner;
|
||||
import com.zontreck.util.TeleportContainer;
|
||||
import com.zontreck.util.TeleportRegistry;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.UUID;
|
||||
|
||||
public class TPAcceptCommand {
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
|
||||
{
|
||||
dispatcher.register(Commands.literal("tpaccept").then(Commands.argument("TeleportUUID", StringArgumentType.string()).executes(c->doAccept(c.getSource(), StringArgumentType.getString(c, "TeleportUUID")))));
|
||||
}
|
||||
|
||||
private static int doAccept(CommandSourceStack source, String TPID) {
|
||||
|
||||
var exec = new CommandExecutionEvent(source.getPlayer(), "tpaccept");
|
||||
if(MinecraftForge.EVENT_BUS.post(exec))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
UUID teleporter = UUID.fromString(TPID);
|
||||
|
||||
ServerPlayer play = (ServerPlayer)source.getEntity();
|
||||
Iterator<TeleportContainer> it = TeleportRegistry.get().iterator();
|
||||
while(it.hasNext())
|
||||
{
|
||||
TeleportContainer cont = it.next();
|
||||
if(cont.TeleportID.equals(teleporter)){
|
||||
// Accepting!
|
||||
|
||||
ServerPlayer from = source.getServer().getPlayerList().getPlayer(cont.FromPlayer);
|
||||
ServerPlayer to = source.getServer().getPlayerList().getPlayer(cont.ToPlayer);
|
||||
|
||||
Component comp = ChatHelpers.macro(Messages.TELEPORT_REQUEST_ACCEPTED);
|
||||
|
||||
ChatHelpers.broadcastTo(cont.FromPlayer, comp, source.getServer());
|
||||
ChatHelpers.broadcastTo(cont.ToPlayer, comp, source.getServer());
|
||||
|
||||
it.remove();
|
||||
|
||||
|
||||
cont.PlayerInst = from;
|
||||
cont.Position = to.position();
|
||||
cont.Rotation = to.getRotationVector();
|
||||
cont.Dimension = to.getLevel();
|
||||
|
||||
TeleportActioner.ApplyTeleportEffect(from);
|
||||
TeleportActioner.PerformTeleport(cont, false);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
Component comp = ChatHelpers.macro(Messages.TELEPORT_REQUEST_NOT_FOUND);
|
||||
|
||||
ChatHelpers.broadcastTo(play.getUUID(), comp, source.getServer());
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
package com.zontreck.commands.teleport;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.zontreck.Messages;
|
||||
import com.zontreck.libzontreck.util.ChatHelpers;
|
||||
import com.zontreck.util.TeleportContainer;
|
||||
import com.zontreck.util.TeleportRegistry;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.UUID;
|
||||
|
||||
public class TPCancelCommand
|
||||
{
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
|
||||
{
|
||||
dispatcher.register(Commands.literal("tpcancel").then(Commands.argument("TeleportUUID", StringArgumentType.string()).executes(c->doCancel(c.getSource(), StringArgumentType.getString(c, "TeleportUUID")))));
|
||||
|
||||
//executes(c -> doCancel(c.getSource())));
|
||||
|
||||
//dispatcher.register(Commands.literal("sethome").then(Commands.argument("nickname", StringArgumentType.string())).executes(command -> {
|
||||
//String arg = StringArgumentType.getString(command, "nickname");
|
||||
//return setHome(command.getSource(), arg);
|
||||
//}));
|
||||
}
|
||||
|
||||
private static int doCancel(CommandSourceStack source, String TPID) {
|
||||
UUID teleporter = UUID.fromString(TPID);
|
||||
ServerPlayer play = (ServerPlayer)source.getEntity();
|
||||
|
||||
Iterator<TeleportContainer> it = TeleportRegistry.get().iterator();
|
||||
while(it.hasNext())
|
||||
{
|
||||
TeleportContainer cont = it.next();
|
||||
if(cont.TeleportID.equals(teleporter)){
|
||||
// Canceling!
|
||||
Component comp = ChatHelpers.macro(Messages.TELEPORT_REQUEST_CANCELLED);
|
||||
|
||||
ChatHelpers.broadcastTo(cont.FromPlayer, comp, source.getServer());
|
||||
ChatHelpers.broadcastTo(cont.ToPlayer, comp, source.getServer());
|
||||
|
||||
it.remove();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
Component comp = ChatHelpers.macro(Messages.TELEPORT_REQUEST_NOT_FOUND);
|
||||
|
||||
ChatHelpers.broadcastTo(play.getUUID(), comp, source.getServer());
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
package com.zontreck.commands.teleport;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.zontreck.Messages;
|
||||
import com.zontreck.libzontreck.util.ChatHelpers;
|
||||
import com.zontreck.util.TeleportContainer;
|
||||
import com.zontreck.util.TeleportRegistry;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.UUID;
|
||||
|
||||
public class TPDenyCommand
|
||||
{
|
||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher)
|
||||
{
|
||||
dispatcher.register(Commands.literal("tpdeny").then(Commands.argument("TeleportUUID", StringArgumentType.string()).executes(c->doCancel(c.getSource(), StringArgumentType.getString(c, "TeleportUUID")))));
|
||||
|
||||
//executes(c -> doCancel(c.getSource())));
|
||||
|
||||
//dispatcher.register(Commands.literal("sethome").then(Commands.argument("nickname", StringArgumentType.string())).executes(command -> {
|
||||
//String arg = StringArgumentType.getString(command, "nickname");
|
||||
//return setHome(command.getSource(), arg);
|
||||
//}));
|
||||
}
|
||||
|
||||
private static int doCancel(CommandSourceStack source, String TPID) {
|
||||
UUID teleporter = UUID.fromString(TPID);
|
||||
ServerPlayer play = (ServerPlayer)source.getEntity();
|
||||
Iterator<TeleportContainer> it = TeleportRegistry.get().iterator();
|
||||
while(it.hasNext())
|
||||
{
|
||||
TeleportContainer cont = it.next();
|
||||
if(cont.TeleportID.equals(teleporter)){
|
||||
// Canceling!
|
||||
Component comp = ChatHelpers.macro(Messages.TELEPORT_REQUEST_DENIED);
|
||||
|
||||
ChatHelpers.broadcastTo(cont.FromPlayer, comp, source.getServer());
|
||||
ChatHelpers.broadcastTo(cont.ToPlayer, comp, source.getServer());
|
||||
|
||||
it.remove();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
Component comp = ChatHelpers.macro(Messages.TELEPORT_REQUEST_NOT_FOUND);
|
||||
|
||||
ChatHelpers.broadcastTo(play.getUUID(), comp, source.getServer());
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,76 @@
|
|||
package com.zontreck.configs.client;
|
||||
|
||||
import com.zontreck.libzontreck.util.SNbtIo;
|
||||
import com.zontreck.util.EssentialsDatastore;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class AEClientConfig
|
||||
{
|
||||
public static final String TAG_HEARTS = "enable_hearts";
|
||||
|
||||
private static AEClientConfig inst;
|
||||
public boolean EnableHearts = true;
|
||||
|
||||
|
||||
|
||||
public static AEClientConfig deserialize(CompoundTag tag)
|
||||
{
|
||||
AEClientConfig config = new AEClientConfig();
|
||||
config.EnableHearts = tag.getBoolean(TAG_HEARTS);
|
||||
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
public static void loadFromFile()
|
||||
{
|
||||
Path serverConfig = EssentialsDatastore.of("client.snbt", false);
|
||||
if(serverConfig.toFile().exists())
|
||||
{
|
||||
|
||||
inst = deserialize(SNbtIo.loadSnbt(serverConfig));
|
||||
}else {
|
||||
initNewConfig();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private static void initNewConfig()
|
||||
{
|
||||
inst = new AEClientConfig();
|
||||
inst.reset();
|
||||
}
|
||||
|
||||
private void reset()
|
||||
{
|
||||
EnableHearts = true;
|
||||
|
||||
save();
|
||||
}
|
||||
|
||||
public static void save()
|
||||
{
|
||||
Path serverConfig = EssentialsDatastore.of("client.snbt", false);
|
||||
|
||||
CompoundTag tag = inst.serialize();
|
||||
SNbtIo.writeSnbt(serverConfig, tag);
|
||||
}
|
||||
|
||||
public CompoundTag serialize()
|
||||
{
|
||||
CompoundTag tag = new CompoundTag();
|
||||
tag.putBoolean(TAG_HEARTS, EnableHearts);
|
||||
|
||||
|
||||
|
||||
return tag;
|
||||
}
|
||||
|
||||
public static AEClientConfig getInstance()
|
||||
{
|
||||
return inst;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
package com.zontreck.configs.client.sections;
|
||||
|
||||
public class Messages
|
||||
{
|
||||
|
||||
}
|
148
src/main/java/com/zontreck/configs/server/AEServerConfig.java
Normal file
148
src/main/java/com/zontreck/configs/server/AEServerConfig.java
Normal file
|
@ -0,0 +1,148 @@
|
|||
package com.zontreck.configs.server;
|
||||
|
||||
import com.zontreck.AriasEssentials;
|
||||
import com.zontreck.ariaslib.util.Lists;
|
||||
import com.zontreck.configs.server.sections.Bottles;
|
||||
import com.zontreck.configs.server.sections.Drops;
|
||||
import com.zontreck.configs.server.sections.Messages;
|
||||
import com.zontreck.configs.server.sections.Teleportation;
|
||||
import com.zontreck.libzontreck.util.SNbtIo;
|
||||
import com.zontreck.util.EssentialsDatastore;
|
||||
import net.minecraft.nbt.*;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class AEServerConfig
|
||||
{
|
||||
private static AEServerConfig inst;
|
||||
public Bottles bottles;
|
||||
public Teleportation teleport;
|
||||
public Messages messages;
|
||||
public Drops drops;
|
||||
public boolean enable_debug = false;
|
||||
|
||||
|
||||
|
||||
public static AEServerConfig deserialize(CompoundTag tag)
|
||||
{
|
||||
AEServerConfig config = new AEServerConfig();
|
||||
try {
|
||||
AriasEssentials.LOGGER.info("Loading Aria's Essentials configuration for - Server");
|
||||
if(tag.contains(Bottles.TAG_NAME))
|
||||
{
|
||||
config.bottles = Bottles.deserialize(tag.getCompound(Bottles.TAG_NAME));
|
||||
} else config.resetBottles();
|
||||
|
||||
|
||||
if(tag.contains(Teleportation.TAG_NAME))
|
||||
config.teleport = Teleportation.deserialize(tag.getCompound(Teleportation.TAG_NAME));
|
||||
else {
|
||||
config.resetTeleport();
|
||||
}
|
||||
|
||||
if(tag.contains(Messages.TAG_NAME))
|
||||
config.messages = Messages.deserialize(tag.getCompound(Messages.TAG_NAME));
|
||||
else config.messages = new Messages();
|
||||
|
||||
if(tag.contains("use_debug"))
|
||||
config.enable_debug = tag.getBoolean("use_debug");
|
||||
else config.enable_debug=false;
|
||||
|
||||
if(tag.contains(Drops.TAG_NAME))
|
||||
config.drops = Drops.load(tag.getCompound(Drops.TAG_NAME));
|
||||
else {
|
||||
config.resetDrops();
|
||||
}
|
||||
|
||||
AriasEssentials.LOGGER.info("Aria's Essentials Server Configuration Loaded");
|
||||
} catch(Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
public static void loadFromFile()
|
||||
{
|
||||
Path serverConfig = EssentialsDatastore.of("server.snbt",false);
|
||||
if(serverConfig.toFile().exists())
|
||||
{
|
||||
inst = deserialize(SNbtIo.loadSnbt(serverConfig));
|
||||
|
||||
save(); // incase of updates
|
||||
}else {
|
||||
initNewConfig();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private static void initNewConfig()
|
||||
{
|
||||
inst = new AEServerConfig();
|
||||
inst.resetBottles(); // also saves
|
||||
inst.resetTeleport();
|
||||
inst.resetDrops();
|
||||
inst.messages = new Messages();
|
||||
inst.enable_debug=false;
|
||||
|
||||
save();
|
||||
}
|
||||
|
||||
private void resetBottles()
|
||||
{
|
||||
bottles = new Bottles();
|
||||
}
|
||||
|
||||
private void resetTeleport() {
|
||||
|
||||
teleport = new Teleportation();
|
||||
teleport.Effects = Lists.of(
|
||||
"minecraft:darkness",
|
||||
"minecraft:levitation",
|
||||
"minecraft:slow_falling",
|
||||
"minecraft:hunger"
|
||||
);
|
||||
teleport.Blacklist = Lists.of(
|
||||
"dimdoors:dungeon_pockets",
|
||||
"dimdoors:limbo",
|
||||
"dimdoors:personal_pockets",
|
||||
"dimdoors:public_pockets",
|
||||
"witherstormmod:bowels"
|
||||
);
|
||||
}
|
||||
|
||||
private void resetDrops() {
|
||||
drops = new Drops();
|
||||
}
|
||||
|
||||
public static void save()
|
||||
{
|
||||
Path serverConfig = EssentialsDatastore.of("server.snbt", false);
|
||||
|
||||
CompoundTag tag = inst.serialize();
|
||||
SNbtIo.writeSnbt(serverConfig, tag);
|
||||
}
|
||||
|
||||
public CompoundTag serialize()
|
||||
{
|
||||
CompoundTag tag = new CompoundTag();
|
||||
tag.put(Bottles.TAG_NAME, bottles.serialize());
|
||||
tag.put(Teleportation.TAG_NAME, teleport.serialize());
|
||||
tag.put(Messages.TAG_NAME, messages.serialize());
|
||||
tag.putBoolean("use_debug", enable_debug);
|
||||
tag.put(Drops.TAG_NAME, drops.save());
|
||||
|
||||
|
||||
|
||||
return tag;
|
||||
}
|
||||
|
||||
public static AEServerConfig getInstance()
|
||||
{
|
||||
return inst;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,88 @@
|
|||
package com.zontreck.configs.server.sections;
|
||||
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
|
||||
public class Bottles {
|
||||
public static final String TAG_NAME = "bottles";
|
||||
public static final String TAG_DURATION = "durationEachUse";
|
||||
public static final String TAG_TICKS = "ticks";
|
||||
public static final String TAG_RANDOM_TICKS = "avgRandomTicks";
|
||||
public static final String TAG_MAX_TIME_RATE = "maxTimeRate";
|
||||
public static final String TAG_STORED_TIME = "maxTime";
|
||||
|
||||
public static final String TAG_MESSAGE_EXPIRED_BOTTLE = "expireMsg";
|
||||
|
||||
public static final String TAG_MESSAGE_STORED_TIME = "msg_storedTime";
|
||||
public static final String TAG_MESSAGE_ACCUMULATED_TIME = "msg_accumulatedTime";
|
||||
public static final String TAG_TOTAL_USES = "msg_totalUses";
|
||||
|
||||
|
||||
|
||||
|
||||
public int eachUseDuration = 30;
|
||||
public int ticks = 20;
|
||||
public int avgRandomTicks = 512;
|
||||
public int maxTimeRate = 8;
|
||||
public int maxTime = (60 * 60 * 24 * 30); // 30 days is the default
|
||||
public String storedTimeStr = "!Dark_Green!Stored Time: [0]";
|
||||
public String accumulatedTimeStr = "!Gray!Total Accumulated Time: [0]";
|
||||
public String totalUses = "!Dark_Red!Total available uses: [0]";
|
||||
public String expiredBottle = "!Dark_Green!This bottle is [0][1]";
|
||||
|
||||
|
||||
public CompoundTag serialize()
|
||||
{
|
||||
CompoundTag tag = new CompoundTag();
|
||||
tag.putInt(TAG_DURATION, eachUseDuration);
|
||||
tag.putInt(TAG_TICKS, ticks);
|
||||
tag.putInt(TAG_RANDOM_TICKS, avgRandomTicks);
|
||||
tag.putInt(TAG_MAX_TIME_RATE, maxTimeRate);
|
||||
tag.putString(TAG_MESSAGE_STORED_TIME, storedTimeStr);
|
||||
tag.putString(TAG_MESSAGE_ACCUMULATED_TIME, accumulatedTimeStr);
|
||||
tag.putString(TAG_TOTAL_USES, totalUses);
|
||||
tag.putInt(TAG_STORED_TIME, maxTime);
|
||||
tag.putString(TAG_MESSAGE_EXPIRED_BOTTLE, expiredBottle);
|
||||
|
||||
|
||||
return tag;
|
||||
}
|
||||
|
||||
public static Bottles deserialize(CompoundTag tag)
|
||||
{
|
||||
Bottles bottles = new Bottles();
|
||||
if(tag.contains(TAG_DURATION))
|
||||
{
|
||||
bottles.eachUseDuration = tag.getInt(TAG_DURATION);
|
||||
}
|
||||
|
||||
if(tag.contains(TAG_TICKS))
|
||||
bottles.ticks = tag.getInt(TAG_TICKS);
|
||||
|
||||
if(tag.contains(TAG_RANDOM_TICKS))
|
||||
bottles.avgRandomTicks = tag.getInt(TAG_RANDOM_TICKS);
|
||||
|
||||
if(tag.contains(TAG_MAX_TIME_RATE))
|
||||
bottles.maxTimeRate = tag.getInt(TAG_MAX_TIME_RATE);
|
||||
|
||||
if(tag.contains(TAG_MESSAGE_STORED_TIME))
|
||||
bottles.storedTimeStr = tag.getString(TAG_MESSAGE_STORED_TIME);
|
||||
|
||||
if(tag.contains(TAG_MESSAGE_ACCUMULATED_TIME))
|
||||
bottles.accumulatedTimeStr = tag.getString(TAG_MESSAGE_ACCUMULATED_TIME);
|
||||
|
||||
if(tag.contains(TAG_STORED_TIME))
|
||||
bottles.maxTime = tag.getInt(TAG_STORED_TIME);
|
||||
|
||||
if(tag.contains(TAG_TOTAL_USES))
|
||||
bottles.totalUses = tag.getString(TAG_TOTAL_USES);
|
||||
|
||||
if(tag.contains(TAG_MESSAGE_EXPIRED_BOTTLE))
|
||||
bottles.expiredBottle = tag.getString(TAG_MESSAGE_EXPIRED_BOTTLE);
|
||||
|
||||
|
||||
|
||||
|
||||
return bottles;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
package com.zontreck.configs.server.sections;
|
||||
|
||||
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
|
||||
public class Drops
|
||||
{
|
||||
public static final String TAG_NAME = "drops";
|
||||
public static final String TAG_PLAYER_HEAD_DROPS = "enablePlayerHeadDrops";
|
||||
public static final String TAG_SPAWN_EGG_CHANCE = "mobEggingChance";
|
||||
public static final String TAG_PLAYER_HEAD_CHANCE = "playerHeadChance";
|
||||
|
||||
public boolean enablePlayerHeadChance = true;
|
||||
public int mobEggingChance = 5;
|
||||
public int playerHeadChance=10;
|
||||
|
||||
|
||||
public CompoundTag save()
|
||||
{
|
||||
CompoundTag tag = new CompoundTag();
|
||||
tag.putBoolean(TAG_PLAYER_HEAD_DROPS, enablePlayerHeadChance);
|
||||
tag.putFloat(TAG_SPAWN_EGG_CHANCE, mobEggingChance);
|
||||
tag.putFloat(TAG_PLAYER_HEAD_CHANCE, playerHeadChance);
|
||||
|
||||
return tag;
|
||||
}
|
||||
|
||||
public static Drops load(CompoundTag tag)
|
||||
{
|
||||
Drops drops = new Drops();
|
||||
|
||||
if(tag.contains(TAG_PLAYER_HEAD_DROPS))
|
||||
drops.enablePlayerHeadChance = tag.getBoolean(TAG_PLAYER_HEAD_DROPS);
|
||||
|
||||
if(tag.contains(TAG_SPAWN_EGG_CHANCE))
|
||||
drops.mobEggingChance = tag.getInt(TAG_SPAWN_EGG_CHANCE);
|
||||
|
||||
if(tag.contains(TAG_PLAYER_HEAD_CHANCE))
|
||||
drops.playerHeadChance = tag.getInt(TAG_PLAYER_HEAD_CHANCE);
|
||||
|
||||
return drops;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
package com.zontreck.configs.server.sections;
|
||||
|
||||
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
|
||||
public class Messages
|
||||
{
|
||||
public static final String TAG_NAME = "messages";
|
||||
public static final String TAG_BL_DIM_ERROR = "blacklisted_dimension_error";
|
||||
|
||||
|
||||
public String BlacklistedDimensionError = "!Dark_Red!You appear to be in a place where we cannot find you.";
|
||||
|
||||
public static Messages deserialize(CompoundTag tag)
|
||||
{
|
||||
Messages msgs = new Messages();
|
||||
msgs.BlacklistedDimensionError = tag.getString(TAG_BL_DIM_ERROR);
|
||||
|
||||
return msgs;
|
||||
}
|
||||
|
||||
public CompoundTag serialize()
|
||||
{
|
||||
CompoundTag tag = new CompoundTag();
|
||||
tag.putString(TAG_BL_DIM_ERROR, BlacklistedDimensionError);
|
||||
|
||||
return tag;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,77 @@
|
|||
package com.zontreck.configs.server.sections;
|
||||
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.nbt.StringTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Teleportation {
|
||||
public static final String TAG_NAME = "teleport";
|
||||
public static final String TAG_EFFECTS = "effects";
|
||||
public static final String TAG_BLACKLIST = "blacklist";
|
||||
|
||||
public List<String> Effects;
|
||||
public List<String> Blacklist;
|
||||
|
||||
public static Teleportation deserialize(CompoundTag tag)
|
||||
{
|
||||
Teleportation teleport = new Teleportation();
|
||||
teleport.Effects = new ArrayList<>();
|
||||
teleport.Blacklist = new ArrayList<>();
|
||||
ListTag effects = tag.getList(TAG_EFFECTS, Tag.TAG_STRING);
|
||||
for(Tag str : effects)
|
||||
{
|
||||
teleport.Effects.add(str.getAsString());
|
||||
}
|
||||
|
||||
ListTag dims = tag.getList(TAG_BLACKLIST, Tag.TAG_STRING);
|
||||
for(Tag dim : dims)
|
||||
{
|
||||
teleport.Blacklist.add(dim.getAsString());
|
||||
}
|
||||
|
||||
return teleport;
|
||||
}
|
||||
|
||||
public CompoundTag serialize()
|
||||
{
|
||||
CompoundTag tag = new CompoundTag();
|
||||
ListTag eff = new ListTag();
|
||||
for(String str : Effects)
|
||||
{
|
||||
eff.add(StringTag.valueOf(str));
|
||||
}
|
||||
|
||||
tag.put(TAG_EFFECTS, eff);
|
||||
|
||||
ListTag dims = new ListTag();
|
||||
for(String str : Blacklist)
|
||||
{
|
||||
dims.add(StringTag.valueOf(str));
|
||||
}
|
||||
|
||||
tag.put(TAG_BLACKLIST, dims);
|
||||
|
||||
return tag;
|
||||
}
|
||||
|
||||
|
||||
static class TeleportEffect
|
||||
{
|
||||
String Effect;
|
||||
int Duration;
|
||||
int Amplifier;
|
||||
boolean Ambient;
|
||||
|
||||
public TeleportEffect(String name, int Duration, int Amplifier, boolean Ambient)
|
||||
{
|
||||
this.Effect = name;
|
||||
this.Duration = Duration;
|
||||
this.Amplifier = Amplifier;
|
||||
this.Ambient = Ambient;
|
||||
}
|
||||
}
|
||||
}
|
84
src/main/java/com/zontreck/effects/FlightEffect.java
Normal file
84
src/main/java/com/zontreck/effects/FlightEffect.java
Normal file
|
@ -0,0 +1,84 @@
|
|||
package com.zontreck.effects;
|
||||
|
||||
|
||||
import com.zontreck.Messages;
|
||||
import com.zontreck.libzontreck.util.ChatHelpers;
|
||||
import com.zontreck.libzontreck.util.ServerUtilities;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.effect.MobEffect;
|
||||
import net.minecraft.world.effect.MobEffectCategory;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.ai.attributes.AttributeMap;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
|
||||
public class FlightEffect extends MobEffect {
|
||||
int lastDuration = -1;
|
||||
ServerPlayer myPlayer;
|
||||
protected FlightEffect(MobEffectCategory pCategory, int pColor) {
|
||||
super(pCategory, pColor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDurationEffectTick(int pDuration, int pAmplifier) {
|
||||
lastDuration=pDuration;
|
||||
|
||||
if(myPlayer!=null) {
|
||||
if(myPlayer.getAbilities().mayfly == false) {
|
||||
myPlayer.getAbilities().mayfly=true;
|
||||
myPlayer.onUpdateAbilities();
|
||||
}
|
||||
}
|
||||
|
||||
//OTEMod.LOGGER.info("Effect duration: " + lastDuration);
|
||||
return pDuration > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBeneficial() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addAttributeModifiers(LivingEntity entity, AttributeMap map, int i) {
|
||||
super.addAttributeModifiers(entity, map, i);
|
||||
|
||||
if(entity instanceof ServerPlayer player)
|
||||
{
|
||||
if(player.getAbilities().mayfly==false)
|
||||
{
|
||||
myPlayer=player;
|
||||
player.getAbilities().mayfly=true;
|
||||
player.onUpdateAbilities();
|
||||
|
||||
ChatHelpers.broadcastTo(player, ChatHelpers.macro(Messages.FLIGHT_GIVEN), player.server);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void removeFlightModifier(LivingEntity entity)
|
||||
{
|
||||
if(lastDuration == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if ( entity instanceof Player player )
|
||||
{
|
||||
if(ServerUtilities.isServer() && lastDuration < (5*20))
|
||||
{
|
||||
ServerPlayer serverPlayer = (ServerPlayer) player;
|
||||
serverPlayer.getAbilities().mayfly = false;
|
||||
serverPlayer.getAbilities().flying = false;
|
||||
|
||||
serverPlayer.onUpdateAbilities();
|
||||
|
||||
ChatHelpers.broadcastTo(serverPlayer, ChatHelpers.macro(Messages.FLIGHT_REMOVED), serverPlayer.server);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeAttributeModifiers(LivingEntity entity, AttributeMap p_19470_, int p_19471_) {
|
||||
super.removeAttributeModifiers(entity, p_19470_, p_19471_);
|
||||
removeFlightModifier(entity);
|
||||
}
|
||||
}
|
25
src/main/java/com/zontreck/effects/ModEffects.java
Normal file
25
src/main/java/com/zontreck/effects/ModEffects.java
Normal file
|
@ -0,0 +1,25 @@
|
|||
package com.zontreck.effects;
|
||||
|
||||
|
||||
import com.zontreck.AriasEssentials;
|
||||
import net.minecraft.world.effect.MobEffect;
|
||||
import net.minecraft.world.effect.MobEffectCategory;
|
||||
import net.minecraftforge.eventbus.api.IEventBus;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraftforge.registries.RegistryObject;
|
||||
|
||||
public class ModEffects
|
||||
{
|
||||
public static final DeferredRegister<MobEffect> REGISTRY = DeferredRegister.create(ForgeRegistries.MOB_EFFECTS, AriasEssentials.MOD_ID);
|
||||
|
||||
public static final RegistryObject<MobEffect> FLIGHT = REGISTRY.register("flight", ()->new FlightEffect(MobEffectCategory.BENEFICIAL, 0xFF0000FF));
|
||||
|
||||
|
||||
|
||||
public static void register(IEventBus bus)
|
||||
{
|
||||
REGISTRY.register(bus);
|
||||
}
|
||||
}
|
||||
|
28
src/main/java/com/zontreck/effects/ModPotions.java
Normal file
28
src/main/java/com/zontreck/effects/ModPotions.java
Normal file
|
@ -0,0 +1,28 @@
|
|||
package com.zontreck.effects;
|
||||
|
||||
|
||||
import com.zontreck.AriasEssentials;
|
||||
import net.minecraft.world.effect.MobEffectInstance;
|
||||
import net.minecraft.world.item.alchemy.Potion;
|
||||
import net.minecraftforge.eventbus.api.IEventBus;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraftforge.registries.RegistryObject;
|
||||
|
||||
public class ModPotions {
|
||||
public static final DeferredRegister<Potion> REGISTRY = DeferredRegister.create(ForgeRegistries.POTIONS, AriasEssentials.MOD_ID);
|
||||
|
||||
|
||||
public static final RegistryObject<Potion> AWKWARD_FLIGHT = REGISTRY.register("flight_awkward", ()->new Potion(new MobEffectInstance(ModEffects.FLIGHT.get(), 30*20, 1)));
|
||||
|
||||
public static final RegistryObject<Potion> MUNDANE_FLIGHT = REGISTRY.register("flight_basic", ()->new Potion(new MobEffectInstance(ModEffects.FLIGHT.get(), 60*20, 1)));
|
||||
|
||||
public static final RegistryObject<Potion> FLIGHT = REGISTRY.register("flight", ()->new Potion(new MobEffectInstance(ModEffects.FLIGHT.get(), 360*20, 1)));
|
||||
|
||||
|
||||
public static void register(IEventBus bus)
|
||||
{
|
||||
REGISTRY.register(bus);
|
||||
}
|
||||
}
|
||||
|
160
src/main/java/com/zontreck/enchantments/ConsumptionMending.java
Normal file
160
src/main/java/com/zontreck/enchantments/ConsumptionMending.java
Normal file
|
@ -0,0 +1,160 @@
|
|||
package com.zontreck.enchantments;
|
||||
|
||||
|
||||
import com.zontreck.libzontreck.util.ItemUtils;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.enchantment.Enchantment;
|
||||
import net.minecraft.world.item.enchantment.EnchantmentCategory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class ConsumptionMending extends Enchantment
|
||||
{
|
||||
protected ConsumptionMending(EquipmentSlot... slots) {
|
||||
super(Rarity.RARE, EnchantmentCategory.BREAKABLE, slots);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxLevel() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTradeable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTreasureOnly() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCurse() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinCost(int pLevel) {
|
||||
return 25 + (pLevel-1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxCost(int pLevel) {
|
||||
return pLevel * 23;
|
||||
}
|
||||
|
||||
private static List<ItemStack> append(ServerPlayer player, List<ItemStack> items)
|
||||
{
|
||||
List<ItemStack> enchanted = new ArrayList<>();
|
||||
|
||||
for(ItemStack stack : player.getInventory().items)
|
||||
{
|
||||
if(ItemUtils.getEnchantmentLevel(ModEnchantments.CONSUMPTION_MENDING.get(), stack) > 0)
|
||||
{
|
||||
enchanted.add(stack);
|
||||
}
|
||||
}
|
||||
|
||||
return enchanted;
|
||||
}
|
||||
|
||||
public static void onEntityTick(ServerPlayer player)
|
||||
{
|
||||
// Check what items have this enchantment
|
||||
// If any, check for like-items that lack the enchant.
|
||||
|
||||
List<ItemStack> enchanted = ItemUtils.getPlayerInventory(player);
|
||||
List<ItemStack> procList = new ArrayList<>(enchanted);
|
||||
|
||||
for(ItemStack stack : enchanted)
|
||||
{
|
||||
int dmgValue = stack.getDamageValue();
|
||||
if(ItemUtils.getEnchantmentLevel(ModEnchantments.CONSUMPTION_MENDING.get(), stack) == 0 || dmgValue == 0) continue; // Skip, because this is a ineligible item
|
||||
|
||||
for(ItemStack item : procList)
|
||||
{
|
||||
// Is this a like item, and does it have the enchant?
|
||||
boolean eligible = false;
|
||||
if(!(ItemUtils.getEnchantmentLevel(ModEnchantments.CONSUMPTION_MENDING.get(), item)>0))
|
||||
{
|
||||
eligible=true;
|
||||
if(!item.isDamageableItem())
|
||||
{
|
||||
eligible=false;
|
||||
}
|
||||
}
|
||||
|
||||
if(stack.getDamageValue()==0)
|
||||
{
|
||||
eligible=false;
|
||||
}
|
||||
|
||||
if(stack.sameItem(item)) {
|
||||
eligible = false;
|
||||
}
|
||||
|
||||
if(eligible)
|
||||
{
|
||||
// Let's eat
|
||||
int iDamage = stack.getDamageValue();
|
||||
int iMax = stack.getMaxDamage();
|
||||
|
||||
int iNeeds = iDamage * 2;
|
||||
|
||||
// The stack we are inspecting:
|
||||
int nDamage = item.getDamageValue();
|
||||
int nMax = item.getMaxDamage();
|
||||
|
||||
int iRemain = nMax - nDamage;
|
||||
|
||||
if(iRemain == iNeeds)
|
||||
{
|
||||
nDamage = nMax;
|
||||
iDamage=0;
|
||||
} else {
|
||||
if(iRemain > iNeeds)
|
||||
{
|
||||
iDamage -= iNeeds;
|
||||
nDamage += iNeeds;
|
||||
} else {
|
||||
iDamage -= iRemain;
|
||||
nDamage = nMax;
|
||||
}
|
||||
}
|
||||
|
||||
if(nDamage == nMax){
|
||||
// Check for curses on the item
|
||||
if(item.isEnchanted())
|
||||
{
|
||||
Map<Enchantment, Integer> enchantments = ItemUtils.getEnchantments(item);
|
||||
for(Map.Entry<Enchantment,Integer> entry : enchantments.entrySet())
|
||||
{
|
||||
Enchantment id = entry.getKey();
|
||||
int dice = player.getRandom().nextInt(0,20);
|
||||
|
||||
if(id.isCurse() && ((dice >= 13) && (dice <= 18)))
|
||||
{
|
||||
stack.enchant(id, entry.getValue());
|
||||
player.getLevel().playSound(null, player.getOnPos(), SoundEvents.ANVIL_USE, SoundSource.NEUTRAL,1, player.getRandom().nextFloat());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
item.shrink(1);
|
||||
player.getLevel().playSound(null, player.getOnPos(), SoundEvents.PLAYER_BURP, SoundSource.NEUTRAL,1, player.getRandom().nextFloat());
|
||||
}
|
||||
else item.setDamageValue(nDamage);
|
||||
|
||||
stack.setDamageValue(iDamage);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
package com.zontreck.enchantments;
|
||||
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.entity.MobType;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.enchantment.Enchantment;
|
||||
import net.minecraft.world.item.enchantment.EnchantmentCategory;
|
||||
import net.minecraft.world.item.enchantment.Enchantments;
|
||||
|
||||
public class DamageIncreaseEnchantment extends Enchantment
|
||||
{
|
||||
protected DamageIncreaseEnchantment(Rarity arg, EnchantmentCategory arg2, EquipmentSlot[] args) {
|
||||
super(arg, arg2, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCurse() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAllowedOnBooks() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTradeable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxLevel() {
|
||||
return 6;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinLevel() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDiscoverable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTreasureOnly() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getDamageBonus(int level, MobType mobType, ItemStack enchantedItem) {
|
||||
return (float) Math.pow(0.5, level);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
package com.zontreck.enchantments;
|
||||
|
||||
|
||||
import com.zontreck.AriasEssentials;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraftforge.event.TickEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Mod.EventBusSubscriber
|
||||
public class EnchantmentEvents
|
||||
{
|
||||
static Map<String, Integer> ticks = new HashMap<>();
|
||||
|
||||
@SubscribeEvent
|
||||
public static void handleEnchantmentTicks(TickEvent.PlayerTickEvent event)
|
||||
{
|
||||
if(event.side == LogicalSide.CLIENT) return;
|
||||
|
||||
if(event.phase == TickEvent.Phase.END)
|
||||
{
|
||||
if(event.player instanceof ServerPlayer sp)
|
||||
{
|
||||
boolean cont = false;
|
||||
|
||||
if(ticks.containsKey(sp.getStringUUID())){
|
||||
if(ticks.get(sp.getStringUUID()) > 150) {
|
||||
ticks.put(sp.getStringUUID(), 0);
|
||||
cont=true;
|
||||
} else cont=false;
|
||||
} else {
|
||||
// Insert
|
||||
ticks.put(sp.getStringUUID(),0);
|
||||
cont=false;
|
||||
}
|
||||
|
||||
if(!cont) {
|
||||
ticks.put(sp.getStringUUID(), ticks.get(sp.getStringUUID())+1);
|
||||
return;
|
||||
}
|
||||
|
||||
//AriasEssentials.LOGGER.info("ENCHANT TICK - Server Player");
|
||||
|
||||
FlightEnchantment.runEntityTick(sp);
|
||||
ConsumptionMending.onEntityTick(sp);
|
||||
VampiricMending.onTick(sp);
|
||||
NightVisionEnchantment.runEntityTick(sp);
|
||||
WaterBreathingEnchantment.runEntityTick(sp);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,96 @@
|
|||
package com.zontreck.enchantments;
|
||||
|
||||
|
||||
import com.zontreck.AriasEssentials;
|
||||
import com.zontreck.configs.server.AEServerConfig;
|
||||
import com.zontreck.effects.ModEffects;
|
||||
import com.zontreck.libzontreck.util.ItemUtils;
|
||||
import com.zontreck.libzontreck.util.ServerUtilities;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.effect.MobEffectInstance;
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.enchantment.Enchantment;
|
||||
import net.minecraft.world.item.enchantment.EnchantmentCategory;
|
||||
|
||||
public class FlightEnchantment extends Enchantment
|
||||
{
|
||||
|
||||
public FlightEnchantment(EquipmentSlot... slots)
|
||||
{
|
||||
super(Rarity.VERY_RARE, EnchantmentCategory.ARMOR_FEET, slots);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxLevel()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinCost(int level)
|
||||
{
|
||||
return 28 + (level - 1) * 15;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxCost(int level)
|
||||
{
|
||||
return this.getMinCost(level) + 15;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTreasureOnly(){
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean isTradeable()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// Not a bug. Flight is meant to be a permanent upgrade to a item. It is considered a curse due to unstable behavior. Flight will eat up durability and forge energy
|
||||
// Flight should NOT be able to be removed via the grindstone
|
||||
@Override
|
||||
public boolean isCurse()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public static void runEntityTick(ServerPlayer sp)
|
||||
{
|
||||
if(ServerUtilities.isClient()) return;
|
||||
|
||||
|
||||
if(AEServerConfig.getInstance().enable_debug)
|
||||
{
|
||||
AriasEssentials.LOGGER.info("> Flight Enchantment Tick <");
|
||||
}
|
||||
|
||||
ItemStack feet = sp.getItemBySlot(EquipmentSlot.FEET);
|
||||
|
||||
boolean hasFlight = false;
|
||||
|
||||
if(ItemUtils.getEnchantmentLevel(ModEnchantments.FLIGHT_ENCHANTMENT.get(), feet)>0)hasFlight=true;
|
||||
|
||||
if(hasFlight)
|
||||
{
|
||||
MobEffectInstance inst = new MobEffectInstance(ModEffects.FLIGHT.get(), 60*20, 0, false, false, true);
|
||||
MobEffectInstance existing = sp.getEffect(ModEffects.FLIGHT.get());
|
||||
|
||||
if(existing != null)
|
||||
{
|
||||
if(existing.getDuration() <= (30 * 20))
|
||||
{
|
||||
sp.addEffect(inst);
|
||||
return;
|
||||
}else return;
|
||||
}
|
||||
|
||||
sp.addEffect(inst);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,88 @@
|
|||
package com.zontreck.enchantments;
|
||||
|
||||
|
||||
import com.zontreck.AriasEssentials;
|
||||
import com.zontreck.configs.server.AEServerConfig;
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.enchantment.Enchantment;
|
||||
import net.minecraft.world.item.enchantment.EnchantmentCategory;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class MobEggEnchantment extends Enchantment
|
||||
{
|
||||
public static final String TAG_BIAS = "mob_egging_bias";
|
||||
|
||||
public MobEggEnchantment()
|
||||
{
|
||||
super(Rarity.VERY_RARE, EnchantmentCategory.WEAPON, new EquipmentSlot[] {EquipmentSlot.MAINHAND});
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxLevel()
|
||||
{
|
||||
return 6;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinCost(int level)
|
||||
{
|
||||
return 28 + (level - 1) * 15;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxCost(int level)
|
||||
{
|
||||
return this.getMinCost(level) + 15;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean canApplyAtEnchantingTable(ItemStack stack)
|
||||
{
|
||||
return super.canApplyAtEnchantingTable(stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTreasureOnly(){
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean isTradeable()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDiscoverable()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean givesEgg(int level, int bias)
|
||||
{
|
||||
int CHANCE = AEServerConfig.getInstance().drops.mobEggingChance;
|
||||
|
||||
CHANCE += level;
|
||||
CHANCE += bias;
|
||||
|
||||
if(AEServerConfig.getInstance().enable_debug)
|
||||
{
|
||||
AriasEssentials.LOGGER.info("Spawn Egg Chance (" + CHANCE + ")");
|
||||
}
|
||||
return rollChance(CHANCE);
|
||||
}
|
||||
|
||||
public static boolean rollChance(int percent)
|
||||
{
|
||||
Random rng = new Random();
|
||||
int test = rng.nextInt(100) + 1 + (100 - percent);
|
||||
if(AEServerConfig.getInstance().enable_debug)
|
||||
{
|
||||
AriasEssentials.LOGGER.info("Spawn Egg Dice Roll (" + test + " / " + percent + ")");
|
||||
}
|
||||
|
||||
return test <= percent;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package com.zontreck.enchantments;
|
||||
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
|
||||
public class ModDamageSources
|
||||
{
|
||||
public static final DamageSource VAMPIRIC_MENDING = new DamageSource("vampiric_mend");
|
||||
}
|
38
src/main/java/com/zontreck/enchantments/ModEnchantments.java
Normal file
38
src/main/java/com/zontreck/enchantments/ModEnchantments.java
Normal file
|
@ -0,0 +1,38 @@
|
|||
package com.zontreck.enchantments;
|
||||
|
||||
import com.zontreck.AriasEssentials;
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.item.enchantment.Enchantment;
|
||||
import net.minecraft.world.item.enchantment.EnchantmentCategory;
|
||||
import net.minecraftforge.eventbus.api.IEventBus;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraftforge.registries.RegistryObject;
|
||||
|
||||
public class ModEnchantments {
|
||||
|
||||
protected static final EquipmentSlot[] ARMOR_SLOTS = new EquipmentSlot[]{EquipmentSlot.HEAD, EquipmentSlot.CHEST, EquipmentSlot.LEGS, EquipmentSlot.FEET};
|
||||
public static final DeferredRegister<Enchantment> REGISTERS = DeferredRegister.create(ForgeRegistries.ENCHANTMENTS, AriasEssentials.MOD_ID);
|
||||
|
||||
public static final RegistryObject<Enchantment> MOB_EGGING_ENCHANTMENT = REGISTERS.register("mob_egging", ()->new MobEggEnchantment());
|
||||
|
||||
public static final RegistryObject<Enchantment> FLIGHT_ENCHANTMENT = REGISTERS.register("player_flight", ()->new FlightEnchantment(EquipmentSlot.FEET));
|
||||
|
||||
|
||||
public static final RegistryObject<Enchantment> CONSUMPTION_MENDING = REGISTERS.register("consumption_mending", ()->new ConsumptionMending(EquipmentSlot.HEAD, EquipmentSlot.CHEST, EquipmentSlot.FEET, EquipmentSlot.LEGS, EquipmentSlot.MAINHAND, EquipmentSlot.OFFHAND));
|
||||
|
||||
|
||||
public static final RegistryObject<Enchantment> NIGHT_VISION_ENCHANT = REGISTERS.register("night_vision", ()->new NightVisionEnchantment(EquipmentSlot.HEAD));
|
||||
|
||||
public static final RegistryObject<Enchantment> WATER_BREATHING_ENCHANT = REGISTERS.register("water_breathing", ()->new WaterBreathingEnchantment(EquipmentSlot.HEAD));
|
||||
|
||||
public static final RegistryObject<Enchantment> WIP_LEVEL_FIELD = REGISTERS.register("extra_strength", ()->new DamageIncreaseEnchantment(Enchantment.Rarity.UNCOMMON, EnchantmentCategory.WEAPON, new EquipmentSlot[] {EquipmentSlot.MAINHAND}));
|
||||
|
||||
public static final RegistryObject<Enchantment> VAMPIRIC_MENDING = REGISTERS.register("vampiric_mend", ()-> new VampiricMending(EquipmentSlot.HEAD, EquipmentSlot.CHEST, EquipmentSlot.FEET, EquipmentSlot.LEGS, EquipmentSlot.MAINHAND, EquipmentSlot.OFFHAND));
|
||||
|
||||
|
||||
|
||||
public static void register(IEventBus bus){
|
||||
REGISTERS.register(bus);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,86 @@
|
|||
package com.zontreck.enchantments;
|
||||
|
||||
|
||||
import com.zontreck.AriasEssentials;
|
||||
import com.zontreck.configs.server.AEServerConfig;
|
||||
import com.zontreck.libzontreck.util.ItemUtils;
|
||||
import com.zontreck.libzontreck.util.ServerUtilities;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.effect.MobEffectInstance;
|
||||
import net.minecraft.world.effect.MobEffects;
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.enchantment.Enchantment;
|
||||
import net.minecraft.world.item.enchantment.EnchantmentCategory;
|
||||
|
||||
public class NightVisionEnchantment extends Enchantment
|
||||
{
|
||||
|
||||
public NightVisionEnchantment(EquipmentSlot... slots)
|
||||
{
|
||||
super(Rarity.VERY_RARE, EnchantmentCategory.ARMOR_HEAD, slots);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxLevel()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTreasureOnly(){
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean isTradeable()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// Not a bug. Flight is meant to be a permanent upgrade to a item. It is considered a curse due to unstable behavior. Flight will eat up durability and forge energy
|
||||
// Flight should NOT be able to be removed via the grindstone
|
||||
@Override
|
||||
public boolean isCurse()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void runEntityTick(ServerPlayer sp)
|
||||
{
|
||||
if(ServerUtilities.isClient()) return;
|
||||
|
||||
|
||||
if(AEServerConfig.getInstance().enable_debug)
|
||||
{
|
||||
AriasEssentials.LOGGER.info("> NVision Enchantment Tick <");
|
||||
}
|
||||
|
||||
|
||||
ItemStack feet = sp.getItemBySlot(EquipmentSlot.HEAD);
|
||||
|
||||
boolean hasNV = false;
|
||||
|
||||
if(ItemUtils.getEnchantmentLevel(ModEnchantments.NIGHT_VISION_ENCHANT.get(), feet)>0)hasNV=true;
|
||||
|
||||
if(hasNV)
|
||||
{
|
||||
MobEffectInstance inst = new MobEffectInstance(MobEffects.NIGHT_VISION, 60*20, 4, false, false, true);
|
||||
|
||||
MobEffectInstance existing = sp.getEffect(MobEffects.NIGHT_VISION);
|
||||
if(existing != null)
|
||||
{
|
||||
if(existing.getDuration() <= (30*20))
|
||||
{
|
||||
sp.addEffect(inst);
|
||||
return;
|
||||
}else return;
|
||||
}
|
||||
|
||||
sp.addEffect(inst);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
107
src/main/java/com/zontreck/enchantments/VampiricMending.java
Normal file
107
src/main/java/com/zontreck/enchantments/VampiricMending.java
Normal file
|
@ -0,0 +1,107 @@
|
|||
package com.zontreck.enchantments;
|
||||
|
||||
import com.zontreck.Messages;
|
||||
import com.zontreck.libzontreck.chat.HoverTip;
|
||||
import com.zontreck.libzontreck.util.ChatHelpers;
|
||||
import com.zontreck.libzontreck.util.ItemUtils;
|
||||
import net.minecraft.network.chat.Style;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.enchantment.Enchantment;
|
||||
import net.minecraft.world.item.enchantment.EnchantmentCategory;
|
||||
import net.minecraftforge.server.ServerLifecycleHooks;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class VampiricMending extends Enchantment
|
||||
{
|
||||
protected VampiricMending(EquipmentSlot... args) {
|
||||
super(Rarity.VERY_RARE, EnchantmentCategory.BREAKABLE, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxLevel() {
|
||||
return 6;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTreasureOnly() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTradeable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDiscoverable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCurse() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAllowedOnBooks() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void onTick(ServerPlayer player) {
|
||||
List<ItemStack> lst1 = ItemUtils.getPlayerInventory(player);
|
||||
|
||||
for(ItemStack stack : lst1) {
|
||||
if(!stack.isDamageableItem()) {
|
||||
continue; // Not damageable, no way it would have the enchant
|
||||
}
|
||||
|
||||
if(stack.getDamageValue() == 0) continue;
|
||||
|
||||
if(ItemUtils.getEnchantmentLevel(ModEnchantments.VAMPIRIC_MENDING.get(), stack) == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// We can proceed
|
||||
int lvl = ItemUtils.getEnchantmentLevel(ModEnchantments.VAMPIRIC_MENDING.get(), stack);
|
||||
|
||||
// Get the multiplier for number of hearts to drink up
|
||||
float base = 1.0f; // player has 20 hearts / 2 = 10 full hearts
|
||||
float numOfHeartsToTake = base*lvl;
|
||||
float playerHealth = player.getHealth();
|
||||
|
||||
int cLvl = 1;
|
||||
// Calculate the amount needed up to max per enchant level
|
||||
while(cLvl <= lvl) {
|
||||
numOfHeartsToTake = base*cLvl;
|
||||
|
||||
if(lvl == cLvl) break;
|
||||
if(stack.getDamageValue() <= (50 * cLvl)) break;
|
||||
|
||||
cLvl++;
|
||||
}
|
||||
|
||||
// Get corrected number of hearts
|
||||
float numToTake = numOfHeartsToTake;
|
||||
if(playerHealth > numToTake) {
|
||||
// we can take that many hearts
|
||||
player.hurt(ModDamageSources.VAMPIRIC_MENDING, numToTake);
|
||||
} else {
|
||||
numToTake = player.getHealth();
|
||||
player.hurt(ModDamageSources.VAMPIRIC_MENDING, numToTake);
|
||||
|
||||
|
||||
ChatHelpers.broadcast(ChatHelpers.macro(Messages.ESSENTIALS_PREFIX + " !Dark_Red!Vampiric Item [Hover Here]").setStyle(Style.EMPTY.withFont(Style.DEFAULT_FONT).withHoverEvent(HoverTip.getItem(stack))), ServerLifecycleHooks.getCurrentServer());
|
||||
}
|
||||
|
||||
int newDmg = stack.getDamageValue() - (50 * lvl);
|
||||
if(newDmg <= 0) newDmg = 0;
|
||||
stack.setDamageValue(newDmg);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,85 @@
|
|||
package com.zontreck.enchantments;
|
||||
|
||||
|
||||
import com.zontreck.AriasEssentials;
|
||||
import com.zontreck.configs.server.AEServerConfig;
|
||||
import com.zontreck.libzontreck.util.ItemUtils;
|
||||
import com.zontreck.libzontreck.util.ServerUtilities;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.effect.MobEffectInstance;
|
||||
import net.minecraft.world.effect.MobEffects;
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.enchantment.Enchantment;
|
||||
import net.minecraft.world.item.enchantment.EnchantmentCategory;
|
||||
|
||||
public class WaterBreathingEnchantment extends Enchantment
|
||||
{
|
||||
|
||||
public WaterBreathingEnchantment(EquipmentSlot... slots)
|
||||
{
|
||||
super(Rarity.VERY_RARE, EnchantmentCategory.ARMOR_HEAD, slots);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxLevel()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTreasureOnly(){
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean isTradeable()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// Not a bug. Flight is meant to be a permanent upgrade to a item. It is considered a curse due to unstable behavior. Flight will eat up durability and forge energy
|
||||
// Flight should NOT be able to be removed via the grindstone
|
||||
@Override
|
||||
public boolean isCurse()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void runEntityTick(ServerPlayer sp)
|
||||
{
|
||||
if(ServerUtilities.isClient()) return;
|
||||
|
||||
|
||||
if(AEServerConfig.getInstance().enable_debug)
|
||||
{
|
||||
AriasEssentials.LOGGER.info("> WBreath Enchantment Tick <");
|
||||
}
|
||||
|
||||
|
||||
ItemStack feet = sp.getItemBySlot(EquipmentSlot.HEAD);
|
||||
|
||||
boolean hasEnchantment = false;
|
||||
|
||||
if(ItemUtils.getEnchantmentLevel(ModEnchantments.WATER_BREATHING_ENCHANT.get(), feet)>0)hasEnchantment=true;
|
||||
|
||||
if(hasEnchantment)
|
||||
{
|
||||
MobEffectInstance inst = new MobEffectInstance(MobEffects.WATER_BREATHING, 60*20, 4, false, false, true);
|
||||
|
||||
MobEffectInstance existing = sp.getEffect(MobEffects.WATER_BREATHING);
|
||||
if(existing != null)
|
||||
{
|
||||
if(existing.getDuration() <= (30*20))
|
||||
{
|
||||
sp.addEffect(inst);
|
||||
return;
|
||||
}else return;
|
||||
}
|
||||
|
||||
sp.addEffect(inst);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
25
src/main/java/com/zontreck/entities/ModEntities.java
Normal file
25
src/main/java/com/zontreck/entities/ModEntities.java
Normal file
|
@ -0,0 +1,25 @@
|
|||
package com.zontreck.entities;
|
||||
|
||||
import com.zontreck.AriasEssentials;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.MobCategory;
|
||||
import net.minecraftforge.eventbus.api.IEventBus;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraftforge.registries.RegistryObject;
|
||||
|
||||
public class ModEntities {
|
||||
|
||||
public static final DeferredRegister<EntityType<?>> REGISTER = DeferredRegister.create(ForgeRegistries.ENTITY_TYPES, AriasEssentials.MOD_ID);
|
||||
|
||||
public static RegistryObject<EntityType<TimeBoostEntity>> TIAB_ENTITY = REGISTER.register("tiab_entity_type", ()->EntityType.Builder.<TimeBoostEntity>of(TimeBoostEntity::new, MobCategory.MISC)
|
||||
.sized(0.1f, 0.1f)
|
||||
.build(new ResourceLocation(AriasEssentials.MOD_ID, "tiab_entity_type").toString())
|
||||
);
|
||||
|
||||
|
||||
public static void register(IEventBus bus) {
|
||||
REGISTER.register(bus);
|
||||
}
|
||||
}
|
126
src/main/java/com/zontreck/entities/TimeBoostEntity.java
Normal file
126
src/main/java/com/zontreck/entities/TimeBoostEntity.java
Normal file
|
@ -0,0 +1,126 @@
|
|||
package com.zontreck.entities;
|
||||
|
||||
import com.zontreck.configs.server.AEServerConfig;
|
||||
import com.zontreck.items.NBTKeys;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.NbtUtils;
|
||||
import net.minecraft.network.protocol.Packet;
|
||||
import net.minecraft.network.syncher.EntityDataAccessor;
|
||||
import net.minecraft.network.syncher.EntityDataSerializers;
|
||||
import net.minecraft.network.syncher.SynchedEntityData;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityTicker;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraftforge.network.NetworkHooks;
|
||||
|
||||
public class TimeBoostEntity extends Entity {
|
||||
private static final EntityDataAccessor<Integer> timeRate = SynchedEntityData.defineId(TimeBoostEntity.class, EntityDataSerializers.INT);
|
||||
|
||||
private int remainingTime;
|
||||
private BlockPos position;
|
||||
|
||||
|
||||
public TimeBoostEntity(EntityType entityType, Level worldIn) {
|
||||
super(entityType, worldIn);
|
||||
entityData.set(timeRate, 1);
|
||||
}
|
||||
|
||||
|
||||
public TimeBoostEntity(Level worldIn, BlockPos pos, double posX, double posY, double posZ) {
|
||||
this(ModEntities.TIAB_ENTITY.get(), worldIn);
|
||||
this.position = pos;
|
||||
this.setPos(posX, posY, posZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void defineSynchedData() {
|
||||
entityData.define(timeRate, 1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected void readAdditionalSaveData(CompoundTag compound) {
|
||||
entityData.set(timeRate, compound.getInt(NBTKeys.ENTITY_TIME_RATE));
|
||||
setRemainingTime(compound.getInt(NBTKeys.ENTITY_REMAINING_TIME));
|
||||
this.position = NbtUtils.readBlockPos(compound.getCompound(NBTKeys.ENTITY_POS));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addAdditionalSaveData(CompoundTag compound) {
|
||||
compound.putInt(NBTKeys.ENTITY_TIME_RATE, getTimeRate());
|
||||
compound.putInt(NBTKeys.ENTITY_REMAINING_TIME, getRemainingTime());
|
||||
compound.put(NBTKeys.ENTITY_POS, NbtUtils.writeBlockPos(this.position));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Packet<?> getAddEntityPacket() {
|
||||
return NetworkHooks.getEntitySpawningPacket(this);
|
||||
}
|
||||
|
||||
public int getTimeRate() {
|
||||
return entityData.get(timeRate);
|
||||
}
|
||||
|
||||
public void setTimeRate(int rate) {
|
||||
entityData.set(timeRate, rate);
|
||||
}
|
||||
|
||||
public int getRemainingTime() {
|
||||
return this.remainingTime;
|
||||
}
|
||||
|
||||
public void setRemainingTime(int remainingTime) {
|
||||
this.remainingTime = remainingTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
Level level = getLevel();
|
||||
|
||||
if(position == null)
|
||||
{
|
||||
if(!level.isClientSide)
|
||||
{
|
||||
remove(RemovalReason.KILLED);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
BlockState state = level.getBlockState(position);
|
||||
ServerLevel serverWorld = level.getServer().getLevel(level.dimension());
|
||||
BlockEntity targetTE = level.getBlockEntity(position);
|
||||
|
||||
|
||||
for (int i = 0; i < getTimeRate(); i++) {
|
||||
if (targetTE != null) {
|
||||
// if is TileEntity (furnace, brewing stand, ...)
|
||||
BlockEntityTicker<BlockEntity> ticker = targetTE.getBlockState().getTicker(level, (BlockEntityType<BlockEntity>) targetTE.getType());
|
||||
if (ticker != null) {
|
||||
ticker.tick(level, position, targetTE.getBlockState(), targetTE);
|
||||
}
|
||||
} else if (serverWorld != null && state.isRandomlyTicking()) {
|
||||
// if is random ticket block (grass block, sugar cane, wheat or sapling, ...)
|
||||
if (level.random.nextInt(AEServerConfig.getInstance().bottles.avgRandomTicks) == 0) {
|
||||
state.randomTick(serverWorld, position, level.random);
|
||||
}
|
||||
} else {
|
||||
// block entity broken
|
||||
this.remove(RemovalReason.KILLED);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
this.remainingTime -= 1;
|
||||
if (this.remainingTime <= 0 && !level.isClientSide) {
|
||||
this.remove(RemovalReason.KILLED);
|
||||
}
|
||||
}
|
||||
}
|
21
src/main/java/com/zontreck/events/CommandExecutionEvent.java
Normal file
21
src/main/java/com/zontreck/events/CommandExecutionEvent.java
Normal file
|
@ -0,0 +1,21 @@
|
|||
package com.zontreck.events;
|
||||
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
|
||||
@Cancelable
|
||||
public class CommandExecutionEvent extends Event {
|
||||
|
||||
public UUID playerID;
|
||||
public String command;
|
||||
|
||||
public CommandExecutionEvent(Player player, String cmd)
|
||||
{
|
||||
playerID=player.getUUID();
|
||||
command=cmd;
|
||||
}
|
||||
}
|
20
src/main/java/com/zontreck/events/HomeCreatedEvent.java
Normal file
20
src/main/java/com/zontreck/events/HomeCreatedEvent.java
Normal file
|
@ -0,0 +1,20 @@
|
|||
package com.zontreck.events;
|
||||
|
||||
|
||||
import com.zontreck.homes.Home;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
|
||||
/**
|
||||
* This event may be cancelled if the home is in a invalid location, like in the middle of a claim they have no rights to
|
||||
*/
|
||||
@Cancelable
|
||||
public class HomeCreatedEvent extends Event
|
||||
{
|
||||
public Home home;
|
||||
public HomeCreatedEvent(Home home)
|
||||
{
|
||||
this.home=home;
|
||||
}
|
||||
}
|
||||
|
20
src/main/java/com/zontreck/events/HomeDeletedEvent.java
Normal file
20
src/main/java/com/zontreck/events/HomeDeletedEvent.java
Normal file
|
@ -0,0 +1,20 @@
|
|||
package com.zontreck.events;
|
||||
|
||||
|
||||
import com.zontreck.homes.Home;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
|
||||
/**
|
||||
* This event cannot be cancelled.
|
||||
*/
|
||||
public class HomeDeletedEvent extends Event
|
||||
{
|
||||
|
||||
public Home home;
|
||||
public HomeDeletedEvent(Home home)
|
||||
{
|
||||
this.home=home;
|
||||
}
|
||||
|
||||
}
|
||||
|
20
src/main/java/com/zontreck/events/TeleportEvent.java
Normal file
20
src/main/java/com/zontreck/events/TeleportEvent.java
Normal file
|
@ -0,0 +1,20 @@
|
|||
package com.zontreck.events;
|
||||
|
||||
import com.zontreck.util.TeleportContainer;
|
||||
import net.minecraftforge.eventbus.api.Cancelable;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
|
||||
@Cancelable
|
||||
public class TeleportEvent extends Event
|
||||
{
|
||||
|
||||
private final TeleportContainer container;
|
||||
public TeleportEvent(TeleportContainer container)
|
||||
{
|
||||
this.container=container;
|
||||
}
|
||||
|
||||
public TeleportContainer getContainer() {
|
||||
return container;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
package com.zontreck.exceptions;
|
||||
|
||||
public class NoSuchHomeException extends Exception
|
||||
{
|
||||
}
|
53
src/main/java/com/zontreck/homes/Home.java
Normal file
53
src/main/java/com/zontreck/homes/Home.java
Normal file
|
@ -0,0 +1,53 @@
|
|||
package com.zontreck.homes;
|
||||
|
||||
import com.zontreck.libzontreck.exceptions.InvalidDeserialization;
|
||||
import com.zontreck.util.TeleportDestination;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class Home {
|
||||
|
||||
public UUID owner;
|
||||
public String homeName;
|
||||
public TeleportDestination destination;
|
||||
public ItemStack homeIcon;
|
||||
|
||||
|
||||
public Home(ServerPlayer player, String name, TeleportDestination dest, ItemStack homeIcon)
|
||||
{
|
||||
owner=player.getUUID();
|
||||
homeName=name;
|
||||
destination=dest;
|
||||
this.homeIcon = homeIcon;
|
||||
}
|
||||
|
||||
public Home(CompoundTag tag)
|
||||
{
|
||||
owner = tag.getUUID("owner");
|
||||
homeName = tag.getString("name");
|
||||
try {
|
||||
destination = new TeleportDestination(tag.getCompound("dest"));
|
||||
} catch (InvalidDeserialization e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if(tag.contains("icon"))
|
||||
{
|
||||
homeIcon = ItemStack.of(tag.getCompound("icon"));
|
||||
} else homeIcon = new ItemStack(Items.BLUE_BED);
|
||||
}
|
||||
|
||||
public CompoundTag serialize()
|
||||
{
|
||||
CompoundTag tag = new CompoundTag();
|
||||
tag.putUUID("owner", owner);
|
||||
tag.putString("name", homeName);
|
||||
tag.put("dest", destination.serialize());
|
||||
tag.put("icon", homeIcon.serializeNBT());
|
||||
|
||||
return tag;
|
||||
}
|
||||
}
|
82
src/main/java/com/zontreck/homes/Homes.java
Normal file
82
src/main/java/com/zontreck/homes/Homes.java
Normal file
|
@ -0,0 +1,82 @@
|
|||
package com.zontreck.homes;
|
||||
|
||||
import com.zontreck.events.HomeCreatedEvent;
|
||||
import com.zontreck.events.HomeDeletedEvent;
|
||||
import com.zontreck.exceptions.NoSuchHomeException;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class Homes
|
||||
{
|
||||
private final Map<String, Home> homes = new HashMap<>();
|
||||
|
||||
public String playerID;
|
||||
public Homes(String playerID)
|
||||
{
|
||||
this.playerID=playerID;
|
||||
}
|
||||
|
||||
public int count()
|
||||
{
|
||||
return homes.size();
|
||||
}
|
||||
|
||||
public List<Home> getList()
|
||||
{
|
||||
return new ArrayList<>(homes.values());
|
||||
}
|
||||
|
||||
public Home get(String name) throws NoSuchHomeException
|
||||
{
|
||||
if(homes.containsKey(name))
|
||||
return homes.get(name);
|
||||
else throw new NoSuchHomeException();
|
||||
}
|
||||
|
||||
public void delete(String name) throws NoSuchHomeException
|
||||
{
|
||||
Home home = homes.get(name);
|
||||
HomeDeletedEvent e = new HomeDeletedEvent(home);
|
||||
homes.remove(name);
|
||||
|
||||
MinecraftForge.EVENT_BUS.post(e);
|
||||
}
|
||||
|
||||
public void add(Home toAdd)
|
||||
{
|
||||
HomeCreatedEvent hce = new HomeCreatedEvent(toAdd);
|
||||
|
||||
if(!MinecraftForge.EVENT_BUS.post(hce))
|
||||
homes.put(toAdd.homeName, toAdd);
|
||||
}
|
||||
|
||||
public static Homes deserialize(CompoundTag tag)
|
||||
{
|
||||
Homes ret = new Homes(null);
|
||||
ListTag theHomes = tag.getList("homes", Tag.TAG_COMPOUND);
|
||||
for (Tag tag2 : theHomes) {
|
||||
Home h = new Home((CompoundTag)tag2);
|
||||
ret.homes.put(h.homeName, h);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
public CompoundTag serialize()
|
||||
{
|
||||
CompoundTag tag = new CompoundTag();
|
||||
ListTag lst = new ListTag();
|
||||
for (Map.Entry<String,Home> entry : homes.entrySet()) {
|
||||
lst.add(entry.getValue().serialize());
|
||||
}
|
||||
tag.put("homes", lst);
|
||||
return tag;
|
||||
}
|
||||
}
|
28
src/main/java/com/zontreck/items/CreativeModeTabs.java
Normal file
28
src/main/java/com/zontreck/items/CreativeModeTabs.java
Normal file
|
@ -0,0 +1,28 @@
|
|||
package com.zontreck.items;
|
||||
|
||||
|
||||
import com.zontreck.AriasEssentials;
|
||||
import com.zontreck.block.ModBlocks;
|
||||
import net.minecraft.world.item.CreativeModeTab;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.registries.RegistryObject;
|
||||
|
||||
@Mod.EventBusSubscriber(modid = AriasEssentials.MOD_ID, value = Dist.CLIENT)
|
||||
public class CreativeModeTabs {
|
||||
public static CreativeModeTab AETAB = new CreativeModeTab("ariasessentials") {
|
||||
@Override
|
||||
public ItemStack makeIcon() {
|
||||
return new ItemStack(ModBlocks.BLUE_POOL_TILE.get().asItem());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
public static <T extends Item> RegistryObject<T> addToAETab(RegistryObject<T> item)
|
||||
{
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
42
src/main/java/com/zontreck/items/DeprecatedItem.java
Normal file
42
src/main/java/com/zontreck/items/DeprecatedItem.java
Normal file
|
@ -0,0 +1,42 @@
|
|||
package com.zontreck.items;
|
||||
|
||||
|
||||
import com.zontreck.libzontreck.util.ChatHelpers;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.TooltipFlag;
|
||||
import net.minecraft.world.level.Level;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class DeprecatedItem extends Item
|
||||
{
|
||||
public DeprecatedItem()
|
||||
{
|
||||
super(new Properties().fireResistant().tab(CreativeModeTabs.AETAB));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFoil(ItemStack p_41453_) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is to give a use to an otherwise useless item. The piglins will exchange the item and it gets removed in that way.
|
||||
* @param stack
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean isPiglinCurrency(ItemStack stack) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendHoverText(ItemStack p_41421_, Level p_41422_, List<Component> p_41423_, TooltipFlag p_41424_) {
|
||||
p_41423_.add(ChatHelpers.macro("!Dark_Red!This item is deprecated"));
|
||||
p_41423_.add(ChatHelpers.macro("!Dark_Green!It would appear this item smells faintly of gold. Maybe piglins will accept it?"));
|
||||
p_41423_.add(ChatHelpers.macro("!Dark_Red!This item is scheduled for removal in a future version. You should use it before it is too late."));
|
||||
}
|
||||
}
|
||||
|
19
src/main/java/com/zontreck/items/DeprecatedModItems.java
Normal file
19
src/main/java/com/zontreck/items/DeprecatedModItems.java
Normal file
|
@ -0,0 +1,19 @@
|
|||
package com.zontreck.items;
|
||||
|
||||
|
||||
import com.zontreck.AriasEssentials;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraftforge.eventbus.api.IEventBus;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraftforge.registries.RegistryObject;
|
||||
|
||||
public class DeprecatedModItems
|
||||
{
|
||||
public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, AriasEssentials.MOD_ID);
|
||||
|
||||
public static void register(IEventBus bus){
|
||||
ITEMS.register(bus);
|
||||
}
|
||||
}
|
||||
|
104
src/main/java/com/zontreck/items/IhanCrystal.java
Normal file
104
src/main/java/com/zontreck/items/IhanCrystal.java
Normal file
|
@ -0,0 +1,104 @@
|
|||
package com.zontreck.items;
|
||||
|
||||
|
||||
import com.zontreck.libzontreck.util.ChatHelpers;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.stats.Stats;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResultHolder;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.TooltipFlag;
|
||||
import net.minecraft.world.level.Level;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class IhanCrystal extends Item {
|
||||
|
||||
public static final String TAG_XP = "xp";
|
||||
|
||||
public IhanCrystal() {
|
||||
super(new Properties().stacksTo(1).tab(CreativeModeTabs.AETAB));
|
||||
}
|
||||
|
||||
private void assertTag(ItemStack stack)
|
||||
{
|
||||
if(!stack.hasTag() || stack.getTag()==null)
|
||||
{
|
||||
stack.setTag(new CompoundTag());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFoil(ItemStack stack) {
|
||||
assertTag(stack);
|
||||
|
||||
if(stack.getTag().contains(TAG_XP))
|
||||
{
|
||||
if(stack.getTag().getInt(TAG_XP) > 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendHoverText(ItemStack stack, Level p_41422_, List<Component> tooltip, TooltipFlag p_41424_) {
|
||||
assertTag(stack);
|
||||
|
||||
tooltip.add(ChatHelpers.macro("!Dark_Green!Stored XP: !Dark_Red!" + stack.getTag().getInt(TAG_XP) + "!Dark_Green! " + Pluralize(stack.getTag().getInt(TAG_XP), "level")));
|
||||
}
|
||||
|
||||
|
||||
private String Pluralize(int num, String str) {
|
||||
return (num > 1 ? str + "s" : str);
|
||||
}
|
||||
|
||||
@Override
|
||||
public InteractionResultHolder<ItemStack> use(Level serverWorld, Player player, InteractionHand hand) {
|
||||
ItemStack stack = player.getItemInHand(hand);
|
||||
|
||||
assertTag(stack);
|
||||
|
||||
serverWorld.playSound(player, player.getOnPos(), SoundEvents.EXPERIENCE_ORB_PICKUP, SoundSource.NEUTRAL, 1F, 1F);
|
||||
|
||||
if(!serverWorld.isClientSide)
|
||||
{
|
||||
|
||||
ServerPlayer serverPlayer = (ServerPlayer) player;
|
||||
if(player.isCrouching())
|
||||
{
|
||||
int lvls=0;
|
||||
// Unpack the experience levels - 10 at a time!!
|
||||
int xp = stack.getTag().getInt(TAG_XP);
|
||||
if(xp>10){
|
||||
lvls = 10;
|
||||
}else lvls= xp;
|
||||
xp-=lvls;
|
||||
|
||||
serverPlayer.setExperienceLevels(serverPlayer.experienceLevel + lvls);
|
||||
|
||||
stack.getTag().putInt(TAG_XP, xp);
|
||||
} else {
|
||||
// Store the xp
|
||||
int xp = stack.getTag().getInt(TAG_XP);
|
||||
xp += player.experienceLevel;
|
||||
|
||||
serverPlayer.setExperienceLevels(0);
|
||||
|
||||
stack.getTag().putInt(TAG_XP, xp);
|
||||
}
|
||||
}
|
||||
|
||||
player.awardStat(Stats.ITEM_USED.get(this));
|
||||
return InteractionResultHolder.sidedSuccess(stack, serverWorld.isClientSide);
|
||||
|
||||
}
|
||||
|
||||
}
|
69
src/main/java/com/zontreck/items/MagmaPowder.java
Normal file
69
src/main/java/com/zontreck/items/MagmaPowder.java
Normal file
|
@ -0,0 +1,69 @@
|
|||
package com.zontreck.items;
|
||||
|
||||
import com.zontreck.AriasEssentials;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.context.UseOnContext;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class MagmaPowder extends Item
|
||||
{
|
||||
MagmaPowder(Item.Properties props) {
|
||||
super(props);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public InteractionResult useOn(UseOnContext context) {
|
||||
BlockPos usedOn = context.getClickedPos();
|
||||
Player player = context.getPlayer();
|
||||
Level level = context.getLevel();
|
||||
|
||||
// Get the block state at the position where the item was used
|
||||
BlockState blockState = level.getBlockState(usedOn);
|
||||
Block block = blockState.getBlock();
|
||||
|
||||
// Check if the block is fractured bedrock, seeping bedrock, or regular bedrock
|
||||
try{
|
||||
if (block == ForgeRegistries.BLOCKS.getValue(new ResourceLocation("tetra:fractured_bedrock")) ||
|
||||
block == ForgeRegistries.BLOCKS.getValue(new ResourceLocation("tetra:seeping_bedrock"))) {
|
||||
|
||||
// Do something if the block is one of the specified types
|
||||
if (player != null && !level.isClientSide()) {
|
||||
// Replace with new Tetra Seeping Bedrock
|
||||
Block seepingBedrock = ForgeRegistries.BLOCKS.getValue(new ResourceLocation("tetra:seeping_bedrock"));
|
||||
if(seepingBedrock == null || seepingBedrock == Blocks.AIR)
|
||||
{
|
||||
return InteractionResult.FAIL;
|
||||
}
|
||||
level.setBlock(usedOn, seepingBedrock.defaultBlockState(), 0);
|
||||
}
|
||||
|
||||
if(!player.isCreative()) {
|
||||
context.getItemInHand().shrink(1);
|
||||
}
|
||||
|
||||
// Return success to indicate the interaction was successful
|
||||
return InteractionResult.SUCCESS;
|
||||
}
|
||||
}catch(Exception E) {
|
||||
// We likely do not have Tetra
|
||||
AriasEssentials.LOGGER.info("Tetra is not installed?");
|
||||
|
||||
return InteractionResult.FAIL;
|
||||
|
||||
}
|
||||
// If the block is not one of the specified types, do nothing special
|
||||
return InteractionResult.PASS;
|
||||
}
|
||||
|
||||
}
|
58
src/main/java/com/zontreck/items/MobCaptureBallItem.java
Normal file
58
src/main/java/com/zontreck/items/MobCaptureBallItem.java
Normal file
|
@ -0,0 +1,58 @@
|
|||
package com.zontreck.items;
|
||||
|
||||
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.stats.Stats;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResultHolder;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
|
||||
public class MobCaptureBallItem extends Item
|
||||
{
|
||||
public MobCaptureBallItem() {
|
||||
super(new Properties().tab(CreativeModeTabs.AETAB));
|
||||
}
|
||||
@Override
|
||||
public boolean isFoil(ItemStack pStack) {
|
||||
if(!pStack.hasTag() || pStack.getTag()==null)
|
||||
{
|
||||
pStack.setTag(new CompoundTag());
|
||||
}
|
||||
if(pStack.getTag().contains("entity"))
|
||||
{
|
||||
return true;
|
||||
} else return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InteractionResultHolder<ItemStack> use(Level pLevel, Player pPlayer, InteractionHand pUsedHand) {
|
||||
ItemStack stack = pPlayer.getItemInHand(pUsedHand);
|
||||
pLevel.playSound((Player) null, pPlayer.getX(), pPlayer.getY(), pPlayer.getZ(), SoundEvents.EGG_THROW, SoundSource.PLAYERS, 0.5F, 0.4F / (pLevel.random.nextFloat() * 0.4f + 0.8f));
|
||||
if(!pLevel.isClientSide)
|
||||
{
|
||||
ItemStack single = stack.copy();
|
||||
single.setCount(1);
|
||||
|
||||
if(!pPlayer.getAbilities().instabuild)
|
||||
{
|
||||
stack.shrink(1);
|
||||
}else {
|
||||
|
||||
}
|
||||
|
||||
ThrownMobCaptureBall TPB = new ThrownMobCaptureBall(pLevel, pPlayer, single);
|
||||
|
||||
|
||||
TPB.shootFromRotation(pPlayer, pPlayer.getXRot(), pPlayer.getYRot(), 0.0F, 1.5F, 1.0F);
|
||||
pLevel.addFreshEntity(TPB);
|
||||
}
|
||||
|
||||
pPlayer.awardStat(Stats.ITEM_USED.get(this));
|
||||
return super.use(pLevel, pPlayer, pUsedHand);
|
||||
}
|
||||
}
|
56
src/main/java/com/zontreck/items/ModItems.java
Normal file
56
src/main/java/com/zontreck/items/ModItems.java
Normal file
|
@ -0,0 +1,56 @@
|
|||
package com.zontreck.items;
|
||||
|
||||
import com.zontreck.items.impl.TimeBottle;
|
||||
import net.minecraft.world.item.SimpleFoiledItem;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraft.world.item.Item;
|
||||
import com.zontreck.AriasEssentials;
|
||||
import net.minecraftforge.registries.RegistryObject;
|
||||
|
||||
public class ModItems {
|
||||
public static DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, AriasEssentials.MOD_ID);
|
||||
|
||||
public static RegistryObject<Item> TIAB = ITEMS.register("tiab", ()->new TimeBottle());
|
||||
|
||||
|
||||
|
||||
public static final RegistryObject<Item> IHAN_CRYSTAL = CreativeModeTabs.addToAETab(ITEMS.register("ihan_crystal", () -> new IhanCrystal()));
|
||||
|
||||
public static final RegistryObject<Item> ETERNIUM_RAW_ORE = CreativeModeTabs.addToAETab(ITEMS.register("eternium_ore", () -> new Item(new Item.Properties().tab(CreativeModeTabs.AETAB))));
|
||||
|
||||
public static final RegistryObject<Item> ETERNIUM_INGOT = CreativeModeTabs.addToAETab(ITEMS.register("eternium_ingot", ()-> new SimpleFoiledItem(new Item.Properties().tab(CreativeModeTabs.AETAB))));
|
||||
|
||||
public static final RegistryObject<Item> ETERNIUM_ROD = CreativeModeTabs.addToAETab(ITEMS.register("eternium_rod", () -> new SimpleFoiledItem(new Item.Properties().stacksTo(64).tab(CreativeModeTabs.AETAB))));
|
||||
|
||||
|
||||
public static final RegistryObject<Item> MIAB = CreativeModeTabs.addToAETab(ITEMS.register("mob_capture_ball", ()->new MobCaptureBallItem()));
|
||||
|
||||
|
||||
public static final RegistryObject<Item> EMPTY_SPAWN_EGG = CreativeModeTabs.addToAETab(ITEMS.register("empty_spawn_egg", () -> new Item(new Item.Properties().tab(CreativeModeTabs.AETAB))));
|
||||
|
||||
public static final RegistryObject<Item> GENERIC_DEPRECATED_ITEM = CreativeModeTabs.addToAETab(ITEMS.register("deprecated", ()->new DeprecatedItem()));
|
||||
|
||||
public static final RegistryObject<Item> WHITE_BRICK = CreativeModeTabs.addToAETab(ITEMS.register("white_brick", ()->new Item(new Item.Properties().tab(CreativeModeTabs.AETAB))));
|
||||
|
||||
public static final RegistryObject<Item> BLUE_BRICK = CreativeModeTabs.addToAETab(ITEMS.register("blue_brick", ()->new Item(new Item.Properties().tab(CreativeModeTabs.AETAB))));
|
||||
|
||||
public static final RegistryObject<Item> LIGHT_BLUE_BRICK = CreativeModeTabs.addToAETab(ITEMS.register("light_blue_brick", ()->new Item(new Item.Properties().tab(CreativeModeTabs.AETAB))));
|
||||
|
||||
public static final RegistryObject<Item> CYAN_BRICK = CreativeModeTabs.addToAETab(ITEMS.register("cyan_brick", ()->new Item(new Item.Properties().tab(CreativeModeTabs.AETAB))));
|
||||
|
||||
public static final RegistryObject<Item> DARK_RED_DYE = CreativeModeTabs.addToAETab(ITEMS.register("dark_red_dye", ()->new Item(new Item.Properties().tab(CreativeModeTabs.AETAB))));
|
||||
|
||||
public static final RegistryObject<Item> RED_BRICK = CreativeModeTabs.addToAETab(ITEMS.register("red_brick", ()->new Item(new Item.Properties().tab(CreativeModeTabs.AETAB))));
|
||||
|
||||
public static final RegistryObject<Item> DARK_RED_BRICK = CreativeModeTabs.addToAETab(ITEMS.register("dark_red_brick", ()->new Item(new Item.Properties().tab(CreativeModeTabs.AETAB))));
|
||||
|
||||
public static final RegistryObject<Item> GREEN_BRICK = CreativeModeTabs.addToAETab(ITEMS.register("green_brick", ()->new Item(new Item.Properties().tab(CreativeModeTabs.AETAB))));
|
||||
|
||||
public static final RegistryObject<Item> LIME_BRICK = CreativeModeTabs.addToAETab(ITEMS.register("lime_brick", ()->new Item(new Item.Properties().tab(CreativeModeTabs.AETAB))));
|
||||
|
||||
public static final RegistryObject<Item> PARTIAL_ITEM = CreativeModeTabs.addToAETab(ITEMS.register("partial_item", PartialItem::new));
|
||||
|
||||
public static final RegistryObject<Item> MAGMA_POWDER = CreativeModeTabs.addToAETab(ITEMS.register("magma_powder", ()-> new MagmaPowder(new Item.Properties().tab(CreativeModeTabs.AETAB))));
|
||||
|
||||
}
|
12
src/main/java/com/zontreck/items/NBTKeys.java
Normal file
12
src/main/java/com/zontreck/items/NBTKeys.java
Normal file
|
@ -0,0 +1,12 @@
|
|||
package com.zontreck.items;
|
||||
|
||||
public class NBTKeys {
|
||||
// for time in a bottle item
|
||||
public static final String STORED_TIME = "storedTime";
|
||||
public static final String TOTAL_ACCUMULATED_TIME = "totalAccumulatedTime";
|
||||
|
||||
// for time accelerator entity
|
||||
public static final String ENTITY_TIME_RATE = "timeRate";
|
||||
public static final String ENTITY_REMAINING_TIME = "remainingTime";
|
||||
public static final String ENTITY_POS = "position";
|
||||
}
|
116
src/main/java/com/zontreck/items/PartialItem.java
Normal file
116
src/main/java/com/zontreck/items/PartialItem.java
Normal file
|
@ -0,0 +1,116 @@
|
|||
package com.zontreck.items;
|
||||
|
||||
|
||||
import com.zontreck.libzontreck.util.ChatHelpers;
|
||||
import net.minecraft.core.UUIDUtil;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.nbt.StringTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.TooltipFlag;
|
||||
import net.minecraft.world.item.enchantment.Enchantment;
|
||||
import net.minecraft.world.item.enchantment.EnchantmentHelper;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PartialItem extends Item
|
||||
{
|
||||
private static final String TAG_UNCRAFT_REMAIN = "remaining";
|
||||
private static final String TAG_UNCRAFT_LIST = "Items";
|
||||
|
||||
@Override
|
||||
public boolean isEnchantable(ItemStack p_41456_) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canApplyAtEnchantingTable(ItemStack stack, Enchantment enchantment) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBookEnchantable(ItemStack stack, ItemStack book) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public PartialItem() {
|
||||
super (new Properties().fireResistant().tab(CreativeModeTabs.AETAB));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendHoverText(ItemStack stack, @Nullable Level p_41422_, List<Component> tooltip, TooltipFlag p_41424_) {
|
||||
tooltip.add(ChatHelpers.macro("!Yellow!This is a partially deconstructed item."));
|
||||
|
||||
if(stack.getTag()!= null)
|
||||
{
|
||||
if(stack.getTag().contains(TAG_UNCRAFT_REMAIN))
|
||||
{
|
||||
tooltip.add(ChatHelpers.macro("!Dark_Red!Number of uncraft steps remaining: [0]", "!Yellow!" + stack.getTag().getInt(TAG_UNCRAFT_REMAIN)));
|
||||
}
|
||||
if(stack.getTag().contains(ItemStack.TAG_ENCH))
|
||||
{
|
||||
tooltip.add(ChatHelpers.macro("!Dark_Red!Number of Enchantments remaining: [0]", "!Yellow!" + stack.getTag().getList(ItemStack.TAG_ENCH, Tag.TAG_COMPOUND).size()));
|
||||
}
|
||||
} else {
|
||||
tooltip.add(ChatHelpers.macro("!Dark_Red!This partial item appears to be invalid, and contains no fragments."));
|
||||
}
|
||||
}
|
||||
|
||||
public static List<Item> getRemainingIngredients(ItemStack stack)
|
||||
{
|
||||
List<Item> itx = new ArrayList<>();
|
||||
if(stack.getTag()!=null)
|
||||
{
|
||||
if(stack.getTag().contains(TAG_UNCRAFT_LIST))
|
||||
{
|
||||
ListTag lst = stack.getTag().getList(TAG_UNCRAFT_LIST, ListTag.TAG_STRING);
|
||||
|
||||
for (Tag tag :
|
||||
lst) {
|
||||
StringTag st = (StringTag)tag;
|
||||
itx.add(deserializeItemType(st.getAsString()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return itx;
|
||||
}
|
||||
|
||||
private static Item deserializeItemType(String item)
|
||||
{
|
||||
return ForgeRegistries.ITEMS.getValue(new ResourceLocation(item));
|
||||
}
|
||||
|
||||
public static ItemStack makePartialItem(ItemStack original, boolean enchantMode, boolean uncraftMode)
|
||||
{
|
||||
if(enchantMode)
|
||||
{
|
||||
ItemStack partial = new ItemStack(ModItems.PARTIAL_ITEM.get(), 1);
|
||||
CompoundTag tag = new CompoundTag();
|
||||
Map<Enchantment, Integer> enchants = EnchantmentHelper.getEnchantments(original);
|
||||
partial.setTag(tag);
|
||||
for(Map.Entry<Enchantment, Integer> entry : enchants.entrySet())
|
||||
{
|
||||
//UUID id = UUIDUtil.createOfflinePlayerUUID()
|
||||
//UUID.nameUUIDFromBytes()
|
||||
partial.enchant(entry.getKey(), entry.getValue());
|
||||
}
|
||||
|
||||
|
||||
return partial;
|
||||
} else return original;
|
||||
}
|
||||
}
|
||||
|
213
src/main/java/com/zontreck/items/ThrownMobCaptureBall.java
Normal file
213
src/main/java/com/zontreck/items/ThrownMobCaptureBall.java
Normal file
|
@ -0,0 +1,213 @@
|
|||
package com.zontreck.items;
|
||||
|
||||
|
||||
import com.zontreck.libzontreck.chat.ChatColor;
|
||||
import com.zontreck.libzontreck.lore.LoreContainer;
|
||||
import com.zontreck.libzontreck.lore.LoreEntry;
|
||||
import com.zontreck.libzontreck.util.ServerUtilities;
|
||||
import net.minecraft.core.particles.ItemParticleOption;
|
||||
import net.minecraft.core.particles.ParticleTypes;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.item.ItemEntity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.entity.projectile.ThrowableItemProjectile;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.phys.EntityHitResult;
|
||||
import net.minecraft.world.phys.HitResult;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ThrownMobCaptureBall extends ThrowableItemProjectile
|
||||
{
|
||||
boolean captured = false;
|
||||
LivingEntity shooter;
|
||||
ItemStack self;
|
||||
|
||||
public ThrownMobCaptureBall(EntityType entity, Level level)
|
||||
{
|
||||
super(entity, level);
|
||||
}
|
||||
public ThrownMobCaptureBall(Level level, LivingEntity shooter, ItemStack item)
|
||||
{
|
||||
super(EntityType.EGG, shooter, level);
|
||||
|
||||
this.shooter = shooter;
|
||||
if(item.getTag() == null)
|
||||
{
|
||||
item.setTag(new CompoundTag());
|
||||
}
|
||||
self=item;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Item getDefaultItem()
|
||||
{
|
||||
return ModItems.MIAB.get();
|
||||
}
|
||||
|
||||
void returnBall()
|
||||
{
|
||||
|
||||
ItemEntity x;
|
||||
|
||||
if(shooter!=null)
|
||||
x = new ItemEntity(level, shooter.position().x, shooter.position().y, shooter.position().z, self, 0, 0, 0);
|
||||
else
|
||||
x = new ItemEntity(level, position().x, position().y, position().z, self, 0, 0, 0);
|
||||
level.addFreshEntity(x);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleEntityEvent(byte pId) {
|
||||
if(pId == 3)
|
||||
{
|
||||
double size = 0.08;
|
||||
|
||||
for (int i = 0; i < 8; ++i)
|
||||
{
|
||||
this.level.addParticle(new ItemParticleOption(ParticleTypes.ITEM, this.getItem()), this.getX(), this.getY(), this.getZ(), ((double)this.random.nextFloat() - 0.5) * 0.08, ((double)this.random.nextFloat() - 0.5) * 0.08, ((double)this.random.nextFloat() - 0.5) * 0.08);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onHitEntity(EntityHitResult pResult) {
|
||||
super.onHitEntity(pResult);
|
||||
if(ServerUtilities.isServer())
|
||||
{
|
||||
CompoundTag tag = self.getTag();
|
||||
if(tag == null)tag = new CompoundTag();
|
||||
if(tag.contains(ItemStack.TAG_DAMAGE))
|
||||
{
|
||||
tag.remove(ItemStack.TAG_DAMAGE);
|
||||
}
|
||||
|
||||
|
||||
if(self.getTag() == null || !self.getTag().contains("entity"))
|
||||
{
|
||||
/*
|
||||
|
||||
Ensure the tag is not null
|
||||
|
||||
*/
|
||||
|
||||
if(pResult.getEntity() instanceof LivingEntity le && !(le instanceof Player player))
|
||||
{
|
||||
// We don't want to capture players
|
||||
// Store the entity in the entity tag, then kill the entity
|
||||
|
||||
|
||||
CompoundTag store = new CompoundTag();
|
||||
String entityName = le.getName().getString();
|
||||
le.save(store);
|
||||
|
||||
self.getTag().put("entity", store);
|
||||
self.setCount(1);
|
||||
captured=true;
|
||||
|
||||
LoreContainer cont = new LoreContainer(self);
|
||||
cont.miscData.loreData.clear();
|
||||
LoreEntry entry = new LoreEntry.Builder().bold(true).text(ChatColor.doColors("!Dark_Green!Captured Mob: !Dark_Purple!" + entityName)).build();
|
||||
cont.miscData.loreData.add(entry);
|
||||
|
||||
cont.commitLore();
|
||||
|
||||
le.remove(RemovalReason.DISCARDED);
|
||||
}
|
||||
} else {
|
||||
|
||||
// Don't capture the entity
|
||||
|
||||
//pResult.getEntity().hurt(this.shooter.getLastDamageSource().thrown(this, this.getOwner()), 0.1F);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onHit(HitResult pResult) {
|
||||
super.onHit(pResult);
|
||||
|
||||
if(ServerUtilities.isServer())
|
||||
{
|
||||
// We do two things here
|
||||
|
||||
// 1. If we contain an entity, spawn it
|
||||
// 2. If no entity, and none was captured, decrease the durability a little
|
||||
// 3. Drop the PossBall with entity, or without
|
||||
|
||||
ItemStack item = self;
|
||||
CompoundTag tag = item.getTag();
|
||||
|
||||
if(tag==null)tag=new CompoundTag();
|
||||
|
||||
if(tag.contains(ItemStack.TAG_DAMAGE))
|
||||
{
|
||||
tag.remove(ItemStack.TAG_DAMAGE); // Migrate existing poss balls to remove the obsolete damage tag
|
||||
}
|
||||
|
||||
if(tag.contains("entity"))
|
||||
{
|
||||
if(captured)
|
||||
{
|
||||
// Spawn poss ball item with the entity NBT
|
||||
returnBall();
|
||||
} else {
|
||||
// Spawn the real entity
|
||||
Optional<Entity> entity = EntityType.create(tag.getCompound("entity"), level);
|
||||
if(entity.isPresent())
|
||||
{
|
||||
Entity xEntity = entity.get();
|
||||
xEntity.setUUID(UUID.randomUUID());
|
||||
xEntity.setPos(position());
|
||||
level.addFreshEntity(xEntity);
|
||||
}
|
||||
|
||||
LoreContainer cont = new LoreContainer(item);
|
||||
cont.miscData.loreData.clear();
|
||||
cont.commitLore();
|
||||
|
||||
if(item.getDamageValue() == 0)
|
||||
{
|
||||
item.setTag(new CompoundTag());
|
||||
}else {
|
||||
tag.remove("entity");
|
||||
}
|
||||
|
||||
|
||||
returnBall();
|
||||
}
|
||||
} else {
|
||||
// No capture
|
||||
// Decrease the durability
|
||||
//int damage = item.getDamageValue();
|
||||
//damage++;
|
||||
//item.setDamageValue(damage);
|
||||
// Ensure no entity tag!
|
||||
tag.remove("entity");
|
||||
|
||||
if(tag.size()==0)
|
||||
{
|
||||
tag=null;
|
||||
item.setTag(new CompoundTag());
|
||||
}
|
||||
|
||||
|
||||
//if(item.getDamageValue() >= item.getMaxDamage())
|
||||
// return;
|
||||
|
||||
|
||||
returnBall();
|
||||
}
|
||||
|
||||
this.level.broadcastEntityEvent(this, (byte)3);
|
||||
this.discard();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
191
src/main/java/com/zontreck/items/abstracts/AbstractTIAB.java
Normal file
191
src/main/java/com/zontreck/items/abstracts/AbstractTIAB.java
Normal file
|
@ -0,0 +1,191 @@
|
|||
package com.zontreck.items.abstracts;
|
||||
|
||||
import com.zontreck.configs.server.AEServerConfig;
|
||||
import com.zontreck.entities.TimeBoostEntity;
|
||||
import com.zontreck.items.CreativeModeTabs;
|
||||
import com.zontreck.util.SoundUtilities;
|
||||
import net.minecraft.client.particle.Particle;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.particles.ParticleOptions;
|
||||
import net.minecraft.core.particles.ParticleTypes;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.PickaxeItem;
|
||||
import net.minecraft.world.item.context.UseOnContext;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public abstract class AbstractTIAB extends Item {
|
||||
private static final String[] NOTES = {"C", "D", "E", "F", "G2", "A2", "B2", "C2", "D2", "E2", "F2"};
|
||||
|
||||
public AbstractTIAB() {
|
||||
super(new Properties().stacksTo(1).tab(CreativeModeTabs.AETAB));
|
||||
}
|
||||
|
||||
public abstract void setExpired(ItemStack stack);
|
||||
public abstract boolean getExpired(ItemStack stack);
|
||||
public abstract int getAvailableUses(ItemStack stack);
|
||||
|
||||
public abstract void enableDurability(ItemStack stack);
|
||||
public abstract void updateDurability(ItemStack stack);
|
||||
|
||||
@Override
|
||||
public int getMaxDamage(ItemStack stack) {
|
||||
if(getExpired(stack)){
|
||||
return stack.getOrCreateTag().getInt("max");
|
||||
}else return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDamageable(ItemStack stack) {
|
||||
return getExpired(stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDamaged(ItemStack stack) {
|
||||
return getExpired(stack) ? (stack.getOrCreateTag().getInt("cur") > 0) : false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDamage(ItemStack stack) {
|
||||
if(getExpired(stack)) return stack.getOrCreateTag().getInt("cur");
|
||||
else return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InteractionResult useOn(UseOnContext context) {
|
||||
Level level = context.getLevel();
|
||||
|
||||
if (level.isClientSide) {
|
||||
return InteractionResult.PASS;
|
||||
}
|
||||
|
||||
BlockPos pos = context.getClickedPos();
|
||||
BlockState blockState = level.getBlockState(pos);
|
||||
BlockEntity targetTE = level.getBlockEntity(pos);
|
||||
ItemStack stack = context.getItemInHand();
|
||||
Player player = context.getPlayer();
|
||||
|
||||
if (targetTE == null && !blockState.isRandomlyTicking()) {
|
||||
return InteractionResult.FAIL;
|
||||
}
|
||||
|
||||
int nextRate = 1;
|
||||
int energyRequired = getEnergyCost(nextRate);
|
||||
boolean isCreativeMode = player != null && player.isCreative();
|
||||
|
||||
Optional<TimeBoostEntity> o = level.getEntitiesOfClass(TimeBoostEntity.class, new AABB(pos)).stream().findFirst();
|
||||
|
||||
if (o.isPresent()) {
|
||||
TimeBoostEntity entityTA = o.get();
|
||||
int currentRate = entityTA.getTimeRate();
|
||||
|
||||
if (currentRate >= Math.pow(2, AEServerConfig.getInstance().bottles.maxTimeRate - 1)) {
|
||||
return InteractionResult.SUCCESS;
|
||||
}
|
||||
|
||||
nextRate = currentRate * 2;
|
||||
energyRequired = getEnergyCost(nextRate);
|
||||
|
||||
if (!canUse(stack, isCreativeMode, energyRequired)) {
|
||||
return InteractionResult.SUCCESS;
|
||||
}
|
||||
|
||||
entityTA.setTimeRate(nextRate);
|
||||
entityTA.setRemainingTime(entityTA.getRemainingTime() + AEServerConfig.getInstance().bottles.eachUseDuration);
|
||||
} else {
|
||||
// First use
|
||||
if (!canUse(stack, isCreativeMode, energyRequired)) {
|
||||
return InteractionResult.SUCCESS;
|
||||
}
|
||||
|
||||
TimeBoostEntity entityTA = new TimeBoostEntity(level, pos, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5);
|
||||
entityTA.setRemainingTime(getEachUseDuration());
|
||||
level.addFreshEntity(entityTA);
|
||||
|
||||
|
||||
}
|
||||
|
||||
if (!isCreativeMode) {
|
||||
this.applyDamage(stack, energyRequired);
|
||||
}
|
||||
playSound(level, pos, nextRate);
|
||||
|
||||
if(getDamage(stack) >= getMaxDamage(stack) && getExpired(stack)) {
|
||||
level.playSound(null, pos, SoundEvents.GLASS_BREAK, SoundSource.PLAYERS, 0.5F, 0.5F);
|
||||
|
||||
player.getInventory().removeItem(stack);
|
||||
}
|
||||
|
||||
return InteractionResult.SUCCESS;
|
||||
}
|
||||
|
||||
protected int getEachUseDuration() {
|
||||
return AEServerConfig.getInstance().bottles.ticks * AEServerConfig.getInstance().bottles.eachUseDuration;
|
||||
}
|
||||
|
||||
public int getEnergyCost(int timeRate) {
|
||||
if (timeRate <= 1) return getEachUseDuration();
|
||||
return timeRate / 2 * getEachUseDuration();
|
||||
}
|
||||
|
||||
public boolean canUse(ItemStack stack, boolean isCreativeMode, int energyRequired) {
|
||||
return getStoredEnergy(stack) >= energyRequired || isCreativeMode;
|
||||
}
|
||||
|
||||
protected abstract int getStoredEnergy(ItemStack stack);
|
||||
|
||||
protected abstract void setStoredEnergy(ItemStack stack, int energy);
|
||||
|
||||
protected abstract void applyDamage(ItemStack stack, int damage);
|
||||
|
||||
public void playSound(Level level, BlockPos pos, int nextRate) {
|
||||
switch (nextRate) {
|
||||
case 1:
|
||||
SoundUtilities.playNoteBlockHarpSound(level, pos, NOTES[0]);
|
||||
break;
|
||||
case 2:
|
||||
SoundUtilities.playNoteBlockHarpSound(level, pos, NOTES[1]);
|
||||
break;
|
||||
case 4:
|
||||
SoundUtilities.playNoteBlockHarpSound(level, pos, NOTES[2]);
|
||||
break;
|
||||
case 8:
|
||||
SoundUtilities.playNoteBlockHarpSound(level, pos, NOTES[3]);
|
||||
break;
|
||||
case 16:
|
||||
SoundUtilities.playNoteBlockHarpSound(level, pos, NOTES[4]);
|
||||
break;
|
||||
case 32:
|
||||
SoundUtilities.playNoteBlockHarpSound(level, pos, NOTES[5]);
|
||||
break;
|
||||
case 64:
|
||||
SoundUtilities.playNoteBlockHarpSound(level, pos, NOTES[6]);
|
||||
break;
|
||||
case 128:
|
||||
SoundUtilities.playNoteBlockHarpSound(level, pos, NOTES[7]);
|
||||
break;
|
||||
case 256:
|
||||
SoundUtilities.playNoteBlockHarpSound(level, pos, NOTES[8]);
|
||||
break;
|
||||
case 512:
|
||||
SoundUtilities.playNoteBlockHarpSound(level, pos, NOTES[9]);
|
||||
break;
|
||||
default:
|
||||
SoundUtilities.playNoteBlockHarpSound(level, pos, NOTES[10]);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldCauseReequipAnimation(ItemStack oldStack, ItemStack newStack, boolean slotChanged) {
|
||||
return !ItemStack.isSame(oldStack, newStack);
|
||||
}
|
||||
}
|
145
src/main/java/com/zontreck/items/impl/TimeBottle.java
Normal file
145
src/main/java/com/zontreck/items/impl/TimeBottle.java
Normal file
|
@ -0,0 +1,145 @@
|
|||
package com.zontreck.items.impl;
|
||||
|
||||
import com.zontreck.ariaslib.util.TimeUtil;
|
||||
import com.zontreck.configs.server.AEServerConfig;
|
||||
import com.zontreck.items.NBTKeys;
|
||||
import com.zontreck.items.abstracts.AbstractTIAB;
|
||||
import com.zontreck.libzontreck.util.ChatHelpers;
|
||||
import net.minecraft.nbt.ByteTag;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.TooltipFlag;
|
||||
import net.minecraft.world.level.Level;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class TimeBottle extends AbstractTIAB
|
||||
{
|
||||
public TimeBottle() {
|
||||
super();
|
||||
}
|
||||
@Override
|
||||
public boolean isFoil(ItemStack stack) {
|
||||
sanityCheck(stack);
|
||||
|
||||
return stack.getTag().contains(NBTKeys.STORED_TIME);
|
||||
}
|
||||
|
||||
private void sanityCheck(ItemStack stack) {
|
||||
|
||||
if(!stack.hasTag() || stack.getTag()==null)
|
||||
{
|
||||
stack.setTag(new CompoundTag());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDurability(ItemStack stack) {
|
||||
stack.getOrCreateTag().putInt("cur", getMaxDamage(stack) - getAvailableUses(stack));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enableDurability(ItemStack stack) {
|
||||
stack.getOrCreateTag().putInt("max", getAvailableUses(stack));
|
||||
updateDurability(stack);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void appendHoverText(ItemStack itemStack, Level world, List<Component> tooltip, TooltipFlag flag) {
|
||||
super.appendHoverText(itemStack, world, tooltip, flag);
|
||||
|
||||
int storedTime = this.getStoredEnergy(itemStack);
|
||||
|
||||
int totalAccumulatedTime = this.getTotalAccumulatedTime(itemStack);
|
||||
|
||||
tooltip.add(ChatHelpers.macro(AEServerConfig.getInstance().bottles.storedTimeStr, TimeUtil.secondsToTimeNotation(TimeUtil.ticksToSeconds(storedTime, AEServerConfig.getInstance().bottles.ticks)).toString()));
|
||||
|
||||
tooltip.add(ChatHelpers.macro(AEServerConfig.getInstance().bottles.accumulatedTimeStr, TimeUtil.secondsToTimeNotation(TimeUtil.ticksToSeconds(totalAccumulatedTime, AEServerConfig.getInstance().bottles.ticks)).toString()));
|
||||
|
||||
tooltip.add(ChatHelpers.macro(AEServerConfig.getInstance().bottles.totalUses, "" + getAvailableUses(itemStack)));
|
||||
|
||||
tooltip.add(ChatHelpers.macro(AEServerConfig.getInstance().bottles.expiredBottle, "" + (getExpired(itemStack) ? "!Dark_Red!Expired" : "!Dark_Green!still able to be used"), getExpired(itemStack) ? ", !Dark_Red!This item will break when it hits zero available uses." : ""));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailableUses(ItemStack stack) {
|
||||
return TimeUtil.ticksToSeconds(getStoredEnergy(stack), AEServerConfig.getInstance().bottles.ticks) / AEServerConfig.getInstance().bottles.eachUseDuration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStoredEnergy(ItemStack stack) {
|
||||
return stack.getOrCreateTag().getInt(NBTKeys.STORED_TIME);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStoredEnergy(ItemStack stack, int energy) {
|
||||
int newStoredTime = Math.min(energy, AEServerConfig.getInstance().bottles.maxTime * 20);
|
||||
stack.getOrCreateTag().putInt(NBTKeys.STORED_TIME, newStoredTime);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyDamage(ItemStack stack, int damage) {
|
||||
setStoredEnergy(stack, getStoredEnergy(stack) - damage);
|
||||
|
||||
if(getExpired(stack)) {
|
||||
updateDurability(stack);
|
||||
}
|
||||
}
|
||||
|
||||
public int getTotalAccumulatedTime(ItemStack stack) {
|
||||
return stack.getOrCreateTag().getInt(NBTKeys.TOTAL_ACCUMULATED_TIME);
|
||||
}
|
||||
|
||||
public void setTotalAccumulatedTime(ItemStack stack, int value) {
|
||||
int newValue = Math.min(value, AEServerConfig.getInstance().bottles.maxTime * 20);
|
||||
stack.getOrCreateTag().putInt(NBTKeys.TOTAL_ACCUMULATED_TIME, newValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setExpired(ItemStack stack) {
|
||||
stack.getOrCreateTag().putBoolean("expired", true);
|
||||
|
||||
enableDurability(stack);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean getExpired(ItemStack stack) {
|
||||
return stack.getOrCreateTag().getBoolean("expired");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void inventoryTick(ItemStack itemStack, Level level, Entity entity, int itemSlot, boolean isSelected) {
|
||||
super.inventoryTick(itemStack, level, entity, itemSlot, isSelected);
|
||||
if (level.isClientSide) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (level.getGameTime() % AEServerConfig.getInstance().bottles.ticks == 0) {
|
||||
if(getExpired(itemStack)) return;
|
||||
|
||||
int storedTime = this.getStoredEnergy(itemStack);
|
||||
if (storedTime < (AEServerConfig.getInstance().bottles.maxTime * 20)) {
|
||||
this.setStoredEnergy(itemStack, storedTime + AEServerConfig.getInstance().bottles.ticks);
|
||||
}
|
||||
|
||||
int totalAccumulatedTime = this.getTotalAccumulatedTime(itemStack);
|
||||
if(totalAccumulatedTime >= Integer.MAX_VALUE && !getExpired(itemStack)) {
|
||||
}
|
||||
if (totalAccumulatedTime < (AEServerConfig.getInstance().bottles.maxTime * 20)) {
|
||||
//this.setTotalAccumulatedTime(itemStack, Integer.MAX_VALUE);
|
||||
this.setTotalAccumulatedTime(itemStack, totalAccumulatedTime + AEServerConfig.getInstance().bottles.ticks);
|
||||
}else {
|
||||
if(!getExpired(itemStack))
|
||||
// The time bottle has now exceeded total possible uses.
|
||||
// Set a flag so that the bottle is deleted after it reaches zero total uses.
|
||||
this.setExpired(itemStack);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
37
src/main/java/com/zontreck/items/tags/ItemStatTag.java
Normal file
37
src/main/java/com/zontreck/items/tags/ItemStatTag.java
Normal file
|
@ -0,0 +1,37 @@
|
|||
package com.zontreck.items.tags;
|
||||
|
||||
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
|
||||
public class ItemStatTag {
|
||||
public static final String STATS_TAG = "stat";
|
||||
public ItemStatType type;
|
||||
public int tagPosition;
|
||||
public int value;
|
||||
|
||||
public ItemStatTag(ItemStatType t, int tagPos, int tag)
|
||||
{
|
||||
type = t;
|
||||
value = tag;
|
||||
tagPosition = tagPos;
|
||||
}
|
||||
|
||||
public void increment(){
|
||||
value++;
|
||||
}
|
||||
public void decrement()
|
||||
{
|
||||
value--;
|
||||
}
|
||||
|
||||
public void setValue(int value)
|
||||
{
|
||||
this.value=value;
|
||||
}
|
||||
|
||||
public void save(CompoundTag tag)
|
||||
{
|
||||
tag.putInt(STATS_TAG+"_"+type.name().toLowerCase(), value);
|
||||
}
|
||||
}
|
||||
|
16
src/main/java/com/zontreck/items/tags/ItemStatType.java
Normal file
16
src/main/java/com/zontreck/items/tags/ItemStatType.java
Normal file
|
@ -0,0 +1,16 @@
|
|||
package com.zontreck.items.tags;
|
||||
|
||||
|
||||
public enum ItemStatType {
|
||||
SWORD,
|
||||
ARMOR,
|
||||
PICK,
|
||||
AXE,
|
||||
SHOVEL,
|
||||
SHOVELPATH,
|
||||
HOE,
|
||||
SHEARS,
|
||||
EGGING,
|
||||
EGG_CHANCE
|
||||
}
|
||||
|
54
src/main/java/com/zontreck/items/tags/ItemStatistics.java
Normal file
54
src/main/java/com/zontreck/items/tags/ItemStatistics.java
Normal file
|
@ -0,0 +1,54 @@
|
|||
package com.zontreck.items.tags;
|
||||
|
||||
|
||||
import com.zontreck.libzontreck.chat.ChatColor;
|
||||
|
||||
public class ItemStatistics {
|
||||
|
||||
public static String makeText(ItemStatTag tag)
|
||||
{
|
||||
return makeText(tag.type, tag.value);
|
||||
}
|
||||
public static String makeText(ItemStatType type, int val)
|
||||
{
|
||||
String lore = ChatColor.doColors("!White!");
|
||||
String sAppend = "";
|
||||
switch(type)
|
||||
{
|
||||
case SWORD -> {
|
||||
lore += "Mobs Killed: ";
|
||||
}
|
||||
case PICK -> {
|
||||
lore += "Blocks Mined: ";
|
||||
}
|
||||
case ARMOR -> {
|
||||
lore += "Damage Taken: ";
|
||||
}
|
||||
case SHOVEL -> {
|
||||
lore += "Blocks Dug Up: ";
|
||||
}
|
||||
case SHOVELPATH -> {
|
||||
lore += "Paths Made: ";
|
||||
}
|
||||
case AXE -> {
|
||||
lore += "Wood Chopped: ";
|
||||
}
|
||||
case HOE -> {
|
||||
lore += "Blocks Hoed: ";
|
||||
}
|
||||
case SHEARS -> {
|
||||
lore += "Sheep Shaved: ";
|
||||
}
|
||||
case EGGING -> {
|
||||
lore += "Spawn Eggs Dropped: ";
|
||||
}
|
||||
case EGG_CHANCE -> {
|
||||
lore += "Spawn Egg Chance: ";
|
||||
sAppend = "!White!%";
|
||||
}
|
||||
}
|
||||
lore += ChatColor.doColors("!Green!"+val + sAppend);
|
||||
return lore;
|
||||
}
|
||||
}
|
||||
|
24
src/main/java/com/zontreck/items/tags/ModIDs.java
Normal file
24
src/main/java/com/zontreck/items/tags/ModIDs.java
Normal file
|
@ -0,0 +1,24 @@
|
|||
package com.zontreck.items.tags;
|
||||
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public enum ModIDs {
|
||||
NULL(0,0),
|
||||
AC(0x9f, 0x9f),
|
||||
AE(5292022,1182023), // The date range of mod creation, then the day when this feature was added
|
||||
ITEM_STATS(154301182023L, 0x9f);
|
||||
|
||||
private UUID ID;
|
||||
|
||||
ModIDs(long A, long B)
|
||||
{
|
||||
ID=new UUID(A,B);
|
||||
}
|
||||
|
||||
public UUID get()
|
||||
{
|
||||
return ID;
|
||||
}
|
||||
}
|
||||
|
176
src/main/java/com/zontreck/libzontreck/LibZontreck.java
Normal file
176
src/main/java/com/zontreck/libzontreck/LibZontreck.java
Normal file
|
@ -0,0 +1,176 @@
|
|||
package com.zontreck.libzontreck;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
|
||||
import com.zontreck.libzontreck.chestgui.ChestGUIRegistry;
|
||||
import com.zontreck.libzontreck.config.ServerConfig;
|
||||
import com.zontreck.libzontreck.currency.Bank;
|
||||
import com.zontreck.libzontreck.currency.CurrencyHelper;
|
||||
import com.zontreck.libzontreck.events.BlockRestoreQueueRegistrationEvent;
|
||||
import com.zontreck.libzontreck.items.ModItems;
|
||||
import com.zontreck.libzontreck.memory.world.BlockRestoreQueueRegistry;
|
||||
import com.zontreck.libzontreck.memory.world.DatabaseMigrations;
|
||||
import com.zontreck.libzontreck.memory.world.DatabaseWrapper;
|
||||
import com.zontreck.libzontreck.menus.ChestGUIScreen;
|
||||
import com.zontreck.libzontreck.types.ModMenuTypes;
|
||||
import com.zontreck.libzontreck.networking.NetworkEvents;
|
||||
import net.minecraft.client.gui.screens.MenuScreens;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import com.mojang.logging.LogUtils;
|
||||
|
||||
import com.zontreck.libzontreck.commands.Commands;
|
||||
import com.zontreck.libzontreck.events.ForgeEventHandlers;
|
||||
import com.zontreck.libzontreck.memory.player.VolatilePlayerStorage;
|
||||
import com.zontreck.libzontreck.networking.ModMessages;
|
||||
import com.zontreck.libzontreck.profiles.Profile;
|
||||
import com.zontreck.libzontreck.util.FileTreeDatastore;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.server.ServerStartedEvent;
|
||||
import net.minecraftforge.event.server.ServerStoppingEvent;
|
||||
import net.minecraftforge.eventbus.api.IEventBus;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.LogicalSide;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
|
||||
@Mod(LibZontreck.MOD_ID)
|
||||
public class LibZontreck {
|
||||
public static final Logger LOGGER = LogUtils.getLogger();
|
||||
public static final String MOD_ID = "libzontreck";
|
||||
public static final Map<String, Profile> PROFILES;
|
||||
public static VolatilePlayerStorage playerStorage;
|
||||
public static boolean ALIVE=true;
|
||||
public static final String FILESTORE = FileTreeDatastore.get();
|
||||
public static final Path BASE_CONFIG;
|
||||
public static final String PLAYER_INFO_URL = "https://api.mojang.com/users/profiles/minecraft/";
|
||||
public static final String PLAYER_SKIN_URL = "https://sessionserver.mojang.com/session/minecraft/profile/";
|
||||
public static final UUID NULL_ID;
|
||||
|
||||
public static boolean LIBZONTRECK_SERVER_AVAILABLE=false;
|
||||
public static ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
|
||||
|
||||
|
||||
public static LogicalSide CURRENT_SIDE;
|
||||
|
||||
|
||||
|
||||
static{
|
||||
NULL_ID = new UUID(0,0);
|
||||
PROFILES = new HashMap<>();
|
||||
BASE_CONFIG = FileTreeDatastore.of("libzontreck");
|
||||
|
||||
if(!BASE_CONFIG.toFile().exists())
|
||||
{
|
||||
try {
|
||||
Files.createDirectory(BASE_CONFIG);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public LibZontreck(){
|
||||
LibZontreck.playerStorage=new VolatilePlayerStorage();
|
||||
IEventBus bus = FMLJavaModLoadingContext.get().getModEventBus();
|
||||
// Register the setup method for modloading
|
||||
bus.addListener(this::setup);
|
||||
|
||||
ServerConfig.init();
|
||||
|
||||
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
MinecraftForge.EVENT_BUS.register(new ForgeEventHandlers());
|
||||
MinecraftForge.EVENT_BUS.register(new Commands());
|
||||
MinecraftForge.EVENT_BUS.register(new NetworkEvents());
|
||||
MinecraftForge.EVENT_BUS.register(ChestGUIRegistry.class);
|
||||
|
||||
|
||||
ModMenuTypes.REGISTRY.register(bus);
|
||||
//CreativeModeTabs.register(bus);
|
||||
ModItems.register(bus);
|
||||
|
||||
MinecraftForge.EVENT_BUS.register(CurrencyHelper.class);
|
||||
MinecraftForge.EVENT_BUS.register(Bank.class);
|
||||
|
||||
}
|
||||
|
||||
private void setup(final FMLCommonSetupEvent event)
|
||||
{
|
||||
ModMessages.register();
|
||||
}
|
||||
|
||||
|
||||
@SubscribeEvent
|
||||
public void onServerStarted(final ServerStartedEvent event)
|
||||
{
|
||||
ALIVE=true;
|
||||
|
||||
ServerConfig.init();
|
||||
try {
|
||||
DatabaseWrapper.start();
|
||||
}catch(RuntimeException e) {
|
||||
LOGGER.warn("Database not configured properly, it will not be available.");
|
||||
DatabaseWrapper.invalidate();
|
||||
}
|
||||
|
||||
CURRENT_SIDE = LogicalSide.SERVER;
|
||||
|
||||
/*MinecraftForge.EVENT_BUS.post(new BlockRestoreQueueRegistrationEvent());
|
||||
|
||||
for(ServerLevel level : event.getServer().getAllLevels())
|
||||
{
|
||||
// Queues have been registered, but we now need to initialize the queue's data from saveddata
|
||||
BlockRestoreQueueRegistry.init(level);
|
||||
}
|
||||
*/
|
||||
if(!DatabaseWrapper.hasDB)return;
|
||||
|
||||
try {
|
||||
DatabaseMigrations.initMigrations();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onServerStopping(final ServerStoppingEvent ev)
|
||||
{
|
||||
ALIVE=false;
|
||||
|
||||
Iterator<Profile> iProfile = PROFILES.values().iterator();
|
||||
while(iProfile.hasNext())
|
||||
{
|
||||
Profile prof = iProfile.next();
|
||||
prof.commit();
|
||||
iProfile.remove();
|
||||
prof=null;
|
||||
}
|
||||
}
|
||||
|
||||
@Mod.EventBusSubscriber(modid = MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD)
|
||||
public static class ClientModEvents
|
||||
{
|
||||
@SubscribeEvent
|
||||
public static void onClientSetup(FMLClientSetupEvent ev) {
|
||||
LibZontreck.CURRENT_SIDE = LogicalSide.CLIENT;
|
||||
LibZontreck.ALIVE = false; // Prevents loops on the client that are meant for server tick processing
|
||||
|
||||
|
||||
MenuScreens.register(ModMenuTypes.CHEST_GUI_MENU.get(), ChestGUIScreen::new);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
138
src/main/java/com/zontreck/libzontreck/api/Vector2.java
Normal file
138
src/main/java/com/zontreck/libzontreck/api/Vector2.java
Normal file
|
@ -0,0 +1,138 @@
|
|||
package com.zontreck.libzontreck.api;
|
||||
|
||||
import com.zontreck.libzontreck.vectors.Vector2f;
|
||||
import com.zontreck.libzontreck.vectors.Vector2i;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.world.phys.Vec2;
|
||||
|
||||
public interface Vector2<T> extends Cloneable, Comparable<Vector2<T>>
|
||||
{
|
||||
/**
|
||||
* Converts the current Vector2 representation into a minecraft Vec2
|
||||
* @return Minecraft equivalent Vec2
|
||||
*/
|
||||
Vec2 asMinecraftVector();
|
||||
|
||||
/**
|
||||
* Parses a string in serialized format.
|
||||
* @param vector2 Expects it in the same format returned by Vector2#toString
|
||||
* @return New Vector2, or a null Vector2 initialized with zeros if invalid data
|
||||
*/
|
||||
static Vector2 parseString(String vector2){
|
||||
throw new UnsupportedOperationException("This method is not implemented by this implementation");
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies the values to a new and detached instance
|
||||
* @return New Vector2
|
||||
*/
|
||||
Vector2 Clone();
|
||||
|
||||
/**
|
||||
* Saves the X and Y positions to a NBT tag
|
||||
* @return NBT compound tag
|
||||
*/
|
||||
CompoundTag serialize();
|
||||
|
||||
/**
|
||||
* Loads a Vector2 from a NBT tag
|
||||
* @param tag The NBT tag to load
|
||||
*/
|
||||
static Vector2 deserialize(CompoundTag tag)
|
||||
{
|
||||
throw new UnsupportedOperationException("This method is not implemented by this implementation");
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares the two vector2 instances
|
||||
* @param other The position to check
|
||||
* @return True if same position
|
||||
*/
|
||||
boolean Same(Vector2 other);
|
||||
|
||||
/**
|
||||
* True if the current position is inside the two points
|
||||
* @param point1 Lowest point
|
||||
* @param point2 Hightest Point
|
||||
* @return True if inside
|
||||
*/
|
||||
boolean Inside(Vector2 point1, Vector2 point2);
|
||||
|
||||
/**
|
||||
* Converts, if necessary, to Vector2d
|
||||
* @return A vector2d instance
|
||||
*/
|
||||
Vector2f asVector2f();
|
||||
|
||||
/**
|
||||
* Converts, if necessary, to Vector2i
|
||||
* @return A vector2i instance
|
||||
*/
|
||||
Vector2i asVector2i();
|
||||
|
||||
/**
|
||||
* Checks if the current vector is greater than the provided one
|
||||
* @param other The other vector to check
|
||||
* @return True if greater
|
||||
*/
|
||||
boolean greater(Vector2 other);
|
||||
|
||||
/**
|
||||
* Checks if the current vector is less than the provided one
|
||||
* @param other The vector to check
|
||||
* @return True if less than other
|
||||
*/
|
||||
boolean less(Vector2 other);
|
||||
|
||||
/**
|
||||
* Alias for Vector2#same
|
||||
* @param other Vector to check
|
||||
* @return True if same position
|
||||
*/
|
||||
boolean equal(Vector2 other);
|
||||
|
||||
/**
|
||||
* Adds the two vectors together
|
||||
* @param other Vector to add
|
||||
* @return New instance after adding the other vector
|
||||
*/
|
||||
Vector2 add(Vector2 other);
|
||||
|
||||
/**
|
||||
* Subtracts the other vector from this one
|
||||
* @param other Vector to subtract
|
||||
* @return New instance after subtracting
|
||||
*/
|
||||
Vector2 subtract(Vector2 other);
|
||||
|
||||
/**
|
||||
* Calculates the distance between the two vectors
|
||||
* @param other
|
||||
* @return The distance
|
||||
*/
|
||||
double distance(Vector2 other);
|
||||
|
||||
/**
|
||||
* Increments the Y axis by 1
|
||||
* @return New instance
|
||||
*/
|
||||
Vector2 moveUp();
|
||||
|
||||
/**
|
||||
* Decrements the Y axis by 1
|
||||
* @return New instance
|
||||
*/
|
||||
Vector2 moveDown();
|
||||
|
||||
/**
|
||||
* Gets the X value
|
||||
* @return X
|
||||
*/
|
||||
T getX();
|
||||
|
||||
/**
|
||||
* Gets the Y value
|
||||
* @return Y
|
||||
*/
|
||||
T getY();
|
||||
}
|
158
src/main/java/com/zontreck/libzontreck/api/Vector3.java
Normal file
158
src/main/java/com/zontreck/libzontreck/api/Vector3.java
Normal file
|
@ -0,0 +1,158 @@
|
|||
package com.zontreck.libzontreck.api;
|
||||
|
||||
import com.zontreck.libzontreck.vectors.Vector3d;
|
||||
import com.zontreck.libzontreck.vectors.Vector3i;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Vec3i;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
public interface Vector3<T> extends Cloneable, Comparable<Vector3<T>>
|
||||
{
|
||||
/**
|
||||
* Converts the current Vector3 representation into a minecraft Vec3
|
||||
* @return Minecraft equivalent Vec3
|
||||
*/
|
||||
Vec3 asMinecraftVector();
|
||||
|
||||
/**
|
||||
* Converts to a vec3i position
|
||||
* @return Equivalent vec3i
|
||||
*/
|
||||
Vec3i asVec3i();
|
||||
|
||||
/**
|
||||
* Converts to a block position
|
||||
* @return Equivalent block position
|
||||
*/
|
||||
BlockPos asBlockPos();
|
||||
|
||||
/**
|
||||
* Parses a string in serialized format.
|
||||
* @param vector3 Expects it in the same format returned by Vector3#toString
|
||||
* @return New Vector3, or a null Vector3 initialized with zeros if invalid data
|
||||
*/
|
||||
static Vector3 parseString(String vector3){
|
||||
throw new UnsupportedOperationException("This method is not implemented by this implementation");
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies the values to a new and detached instance
|
||||
* @return New Vector3
|
||||
*/
|
||||
Vector3 Clone();
|
||||
|
||||
/**
|
||||
* Saves the X, Y, and Z positions to a NBT tag
|
||||
* @return NBT compound tag
|
||||
*/
|
||||
CompoundTag serialize();
|
||||
|
||||
/**
|
||||
* Loads a Vector3 from a NBT tag
|
||||
* @param tag The NBT tag to load
|
||||
*/
|
||||
static Vector3 deserialize(CompoundTag tag)
|
||||
{
|
||||
throw new UnsupportedOperationException("This method is not implemented by this implementation");
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares the two vector3 instances
|
||||
* @param other The position to check
|
||||
* @return True if same position
|
||||
*/
|
||||
boolean Same(Vector3 other);
|
||||
|
||||
/**
|
||||
* True if the current position is inside the two points
|
||||
* @param point1 Lowest point
|
||||
* @param point2 Hightest Point
|
||||
* @return True if inside
|
||||
*/
|
||||
boolean Inside(Vector3 point1, Vector3 point2);
|
||||
|
||||
/**
|
||||
* Converts, if necessary, to Vector3d
|
||||
* @return A vector2d instance
|
||||
*/
|
||||
Vector3d asVector3d();
|
||||
|
||||
/**
|
||||
* Converts, if necessary, to Vector3i
|
||||
* @return A vector3i instance
|
||||
*/
|
||||
Vector3i asVector3i();
|
||||
|
||||
/**
|
||||
* Checks if the current vector is greater than the provided one
|
||||
* @param other The other vector to check
|
||||
* @return True if greater
|
||||
*/
|
||||
boolean greater(Vector3 other);
|
||||
|
||||
/**
|
||||
* Checks if the current vector is less than the provided one
|
||||
* @param other The vector to check
|
||||
* @return True if less than other
|
||||
*/
|
||||
boolean less(Vector3 other);
|
||||
|
||||
/**
|
||||
* Alias for Vector3#same
|
||||
* @param other Vector to check
|
||||
* @return True if same position
|
||||
*/
|
||||
boolean equal(Vector3 other);
|
||||
|
||||
/**
|
||||
* Adds the two vectors together
|
||||
* @param other Vector to add
|
||||
* @return New instance after adding the other vector
|
||||
*/
|
||||
Vector3 add(Vector3 other);
|
||||
|
||||
/**
|
||||
* Subtracts the other vector from this one
|
||||
* @param other Vector to subtract
|
||||
* @return New instance after subtracting
|
||||
*/
|
||||
Vector3 subtract(Vector3 other);
|
||||
|
||||
/**
|
||||
* Calculates the distance between the two vectors
|
||||
* @param other
|
||||
* @return The distance
|
||||
*/
|
||||
double distance(Vector3 other);
|
||||
|
||||
/**
|
||||
* Increments the Y axis by 1
|
||||
* @return New instance
|
||||
*/
|
||||
Vector3 moveUp();
|
||||
|
||||
/**
|
||||
* Decrements the Y axis by 1
|
||||
* @return New instance
|
||||
*/
|
||||
Vector3 moveDown();
|
||||
|
||||
/**
|
||||
* Gets the X value
|
||||
* @return X
|
||||
*/
|
||||
T getX();
|
||||
|
||||
/**
|
||||
* Gets the Y value
|
||||
* @return Y
|
||||
*/
|
||||
T getY();
|
||||
|
||||
/**
|
||||
* Gets the Z value
|
||||
* @return Z
|
||||
*/
|
||||
T getZ();
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package com.zontreck.libzontreck.blocks;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.phys.shapes.CollisionContext;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
|
||||
public class BlockCustomVoxels extends PartialTransparentBlock
|
||||
{
|
||||
private VoxelShape superShape;
|
||||
public BlockCustomVoxels(Properties p_54120_, VoxelShape shape) {
|
||||
super(p_54120_);
|
||||
this.superShape = shape;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VoxelShape getShape(BlockState p_60555_, BlockGetter p_60556_, BlockPos p_60557_, CollisionContext p_60558_) {
|
||||
return superShape;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,95 @@
|
|||
package com.zontreck.libzontreck.blocks;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
/**
|
||||
* Code partially taken from HT's TreeChop
|
||||
* <p>
|
||||
* <a href="https://github.com/hammertater/treechop/blob/main/shared/src/main/java/ht/treechop/common/block/BlockImitator.java">Source Material</a>
|
||||
*/
|
||||
public abstract class BlockImitation extends Block
|
||||
{
|
||||
public BlockImitation(Properties pProperties) {
|
||||
super(pProperties);
|
||||
}
|
||||
|
||||
|
||||
public abstract BlockState getImitatedBlockState(BlockGetter level, BlockPos pos);
|
||||
|
||||
public abstract void updateImitation(BlockState newState, BlockGetter level, BlockPos pos);
|
||||
|
||||
@Override
|
||||
public void animateTick(BlockState blockState, Level level, BlockPos pos, RandomSource random) {
|
||||
BlockState imitatedBlockState = getImitatedBlockState(level, pos);
|
||||
imitatedBlockState.getBlock().animateTick(imitatedBlockState, level, pos, random);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stepOn(Level level, BlockPos pos, BlockState blockState, Entity entity) {
|
||||
BlockState imitatedBlockState = getImitatedBlockState(level, pos);
|
||||
imitatedBlockState.getBlock().stepOn(level, pos, imitatedBlockState, entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fallOn(Level level, BlockState blockState, BlockPos pos, Entity entity, float speed) {
|
||||
BlockState imitatedBlockState = getImitatedBlockState(level, pos);
|
||||
imitatedBlockState.getBlock().fallOn(level, imitatedBlockState, pos, entity, speed);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getCloneItemStack(BlockGetter level, BlockPos pos, BlockState blockState) {
|
||||
BlockState imitatedBlockState = getImitatedBlockState(level, pos);
|
||||
return imitatedBlockState.getBlock().getCloneItemStack(level, pos, imitatedBlockState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handlePrecipitation(BlockState blockState, Level level, BlockPos pos, Biome.Precipitation precipitation) {
|
||||
BlockState imitatedBlockState = getImitatedBlockState(level, pos);
|
||||
imitatedBlockState.getBlock().handlePrecipitation(imitatedBlockState, level, pos, precipitation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLightBlock(BlockState blockState, BlockGetter level, BlockPos pos) {
|
||||
return super.getLightBlock(blockState, level, pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getShadeBrightness(BlockState blockState, BlockGetter level, BlockPos pos) {
|
||||
return super.getShadeBrightness(blockState, level, pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAnalogOutputSignal(BlockState blockState, Level level, BlockPos pos) {
|
||||
return getImitatedBlockState(level, pos).getAnalogOutputSignal(level, pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void randomTick(BlockState blockState, ServerLevel level, BlockPos pos, RandomSource random) {
|
||||
getImitatedBlockState(level, pos).randomTick(level, pos, random);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick(BlockState blockState, ServerLevel level, BlockPos pos, RandomSource random) {
|
||||
getImitatedBlockState(level, pos).tick(level, pos, random);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSignal(BlockState blockState, BlockGetter level, BlockPos pos, Direction direction) {
|
||||
return getImitatedBlockState(level, pos).getSignal(level, pos, direction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDirectSignal(BlockState blockState, BlockGetter level, BlockPos pos, Direction direction) {
|
||||
return getImitatedBlockState(level, pos).getDirectSignal(level, pos, direction);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
package com.zontreck.libzontreck.blocks;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.block.AbstractGlassBlock;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
public class PartialTransparentBlock extends AbstractGlassBlock
|
||||
{
|
||||
public PartialTransparentBlock(Properties p_48729_) {
|
||||
super(p_48729_);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean propagatesSkylightDown(BlockState p_48740_, BlockGetter p_48741_, BlockPos p_48742_) {
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package com.zontreck.libzontreck.blocks;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.block.AbstractGlassBlock;
|
||||
import net.minecraft.world.level.block.SlabBlock;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
|
||||
public class PartialTransparentSlabBlock extends SlabBlock
|
||||
{
|
||||
public PartialTransparentSlabBlock(Properties p_48729_) {
|
||||
super(p_48729_);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean propagatesSkylightDown(BlockState p_48740_, BlockGetter p_48741_, BlockPos p_48742_) {
|
||||
return true;
|
||||
}
|
||||
}
|
100
src/main/java/com/zontreck/libzontreck/blocks/RedstoneBlock.java
Normal file
100
src/main/java/com/zontreck/libzontreck/blocks/RedstoneBlock.java
Normal file
|
@ -0,0 +1,100 @@
|
|||
package com.zontreck.libzontreck.blocks;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.item.context.BlockPlaceContext;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.LevelReader;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.StateDefinition;
|
||||
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
||||
import net.minecraft.world.level.block.state.properties.BooleanProperty;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class RedstoneBlock extends RotatableBlock
|
||||
{
|
||||
public static final BooleanProperty INPUT_POWER = BooleanProperty.create("inputpower");
|
||||
public static final BooleanProperty POWERED = BlockStateProperties.POWERED;
|
||||
private List<Direction> sides;
|
||||
|
||||
protected RedstoneBlock(Properties pProperties, Direction... validSides) {
|
||||
super(pProperties);
|
||||
sides=List.of(validSides);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getStateForPlacement(BlockPlaceContext pContext) {
|
||||
return super.getStateForPlacement(pContext).setValue(INPUT_POWER, false).setValue(POWERED, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> pBuilder) {
|
||||
super.createBlockStateDefinition(pBuilder);
|
||||
pBuilder.add(INPUT_POWER, POWERED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConnectRedstone(BlockState state, BlockGetter level, BlockPos pos, @Nullable Direction direction) {
|
||||
if(sides.contains(direction)) return true;
|
||||
else return false;
|
||||
}
|
||||
|
||||
private boolean redstoneIsActivated(LevelReader level, BlockPos pos)
|
||||
{
|
||||
ServerLevel srv = (ServerLevel)level;
|
||||
if(srv.hasNeighborSignal(pos))
|
||||
return true;
|
||||
else return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSignal(BlockState p_60483_, BlockGetter p_60484_, BlockPos p_60485_, Direction p_60486_) {
|
||||
if(!sides.contains(p_60486_)) return 0;
|
||||
|
||||
if(p_60483_.getValue(POWERED))
|
||||
return 15;
|
||||
else return 0;
|
||||
}
|
||||
|
||||
protected abstract void onRedstone(LevelReader level, BlockPos pos, boolean on);
|
||||
protected abstract void onRedstoneInputChanged(LevelReader level, BlockPos pos, boolean on);
|
||||
|
||||
@Override
|
||||
public void onNeighborChange(BlockState state, LevelReader level, BlockPos pos, BlockPos neighbor) {
|
||||
boolean rs = redstoneIsActivated(level, pos);
|
||||
onRedstone(level, pos, rs);
|
||||
boolean inp = state.getValue(INPUT_POWER);
|
||||
state.setValue(INPUT_POWER, rs);
|
||||
|
||||
if(inp != rs)
|
||||
onRedstoneInputChanged(level, pos, rs);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void neighborChanged(BlockState state, Level level, BlockPos pos, Block block, BlockPos other, boolean unknown) {
|
||||
boolean rs = redstoneIsActivated(level, pos);
|
||||
onRedstone(level, pos, rs);
|
||||
boolean inp = state.getValue(INPUT_POWER);
|
||||
state.setValue(INPUT_POWER, rs);
|
||||
|
||||
if(inp != rs)
|
||||
onRedstoneInputChanged(level, pos, rs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlace(BlockState state, Level level, BlockPos pos, BlockState p_60569_, boolean p_60570_) {
|
||||
boolean rs = redstoneIsActivated(level, pos);
|
||||
onRedstone(level, pos, rs);
|
||||
boolean inp = state.getValue(INPUT_POWER);
|
||||
state.setValue(INPUT_POWER, rs);
|
||||
|
||||
if(inp != rs)
|
||||
onRedstoneInputChanged(level, pos, rs);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package com.zontreck.libzontreck.blocks;
|
||||
|
||||
import net.minecraft.world.item.context.BlockPlaceContext;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.HorizontalDirectionalBlock;
|
||||
import net.minecraft.world.level.block.Mirror;
|
||||
import net.minecraft.world.level.block.Rotation;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.StateDefinition;
|
||||
|
||||
public class RotatableBlock extends HorizontalDirectionalBlock
|
||||
{
|
||||
public RotatableBlock(Properties pProperties) {
|
||||
super(pProperties);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> pBuilder) {
|
||||
super.createBlockStateDefinition(pBuilder);
|
||||
pBuilder.add(FACING);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public BlockState rotate(BlockState p_55115_, Rotation p_55116_) {
|
||||
return p_55115_.setValue(FACING, p_55116_.rotate(p_55115_.getValue(FACING)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState mirror(BlockState p_55112_, Mirror p_55113_) {
|
||||
return p_55112_.rotate(p_55113_.getRotation(p_55112_.getValue(FACING)));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public BlockState getStateForPlacement(BlockPlaceContext pContext) {
|
||||
return defaultBlockState().setValue(FACING, pContext.getHorizontalDirection());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package com.zontreck.libzontreck.blocks;
|
||||
|
||||
import com.zontreck.ariaslib.util.Maps;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.phys.shapes.CollisionContext;
|
||||
import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
public class RotatableBlockCustomVoxels extends RotatableBlock
|
||||
{
|
||||
private Map<Direction, VoxelShape> rotatedShapes = new HashMap<>();
|
||||
|
||||
public RotatableBlockCustomVoxels(Properties properties, VoxelShape north, VoxelShape south, VoxelShape east, VoxelShape west) {
|
||||
super(properties);
|
||||
rotatedShapes = Maps.of(new Maps.Entry<>(Direction.NORTH, north), new Maps.Entry<>(Direction.SOUTH, south), new Maps.Entry<>(Direction.WEST, west), new Maps.Entry<>(Direction.EAST, east), new Maps.Entry<>(Direction.NORTH, north), new Maps.Entry<>(Direction.DOWN, north));
|
||||
}
|
||||
|
||||
@Override
|
||||
public VoxelShape getShape(BlockState state, BlockGetter world, BlockPos pos, CollisionContext context) {
|
||||
Direction facing = state.getValue(FACING);
|
||||
return rotatedShapes.get(facing);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean propagatesSkylightDown(BlockState p_49928_, BlockGetter p_49929_, BlockPos p_49930_) {
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package com.zontreck.libzontreck.bossbars;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.server.bossevents.CustomBossEvents;
|
||||
import net.minecraft.server.commands.BossBarCommands;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
|
||||
public class BossBarUtils {
|
||||
public class BossBarStructure
|
||||
{
|
||||
public String Header;
|
||||
public int Percent;
|
||||
}
|
||||
public static void sendBossBarToPlayer(Player p, BossBarStructure struc)
|
||||
{
|
||||
if(Minecraft.getInstance().level.isClientSide())return;
|
||||
|
||||
ServerPlayer sp = (ServerPlayer)p;
|
||||
if(sp==null)return;
|
||||
|
||||
//sp.server.getCustomBossEvents().create(null, null)
|
||||
}
|
||||
}
|
179
src/main/java/com/zontreck/libzontreck/chat/ChatColor.java
Normal file
179
src/main/java/com/zontreck/libzontreck/chat/ChatColor.java
Normal file
|
@ -0,0 +1,179 @@
|
|||
package com.zontreck.libzontreck.chat;
|
||||
|
||||
public class ChatColor {
|
||||
public enum ColorOptions{
|
||||
Black,
|
||||
Dark_Blue,
|
||||
Dark_Green,
|
||||
Dark_Aqua,
|
||||
Dark_Red,
|
||||
Dark_Purple,
|
||||
Gold,
|
||||
Gray,
|
||||
Dark_Gray,
|
||||
Blue,
|
||||
Green,
|
||||
Aqua,
|
||||
Red,
|
||||
Light_Purple,
|
||||
Yellow,
|
||||
White,
|
||||
MinecoinGold,
|
||||
Underline,
|
||||
Bold,
|
||||
Italic,
|
||||
Strikethrough,
|
||||
Crazy,
|
||||
Reset
|
||||
}
|
||||
public static char CODE = '§';
|
||||
public static String BLACK = build("0");
|
||||
public static String DARK_BLUE = build("1");
|
||||
public static String DARK_GREEN = build("2");
|
||||
public static String DARK_AQUA = build("3");
|
||||
public static String DARK_RED = build("4");
|
||||
public static String DARK_PURPLE = build("5");
|
||||
public static String GOLD = build("6");
|
||||
public static String GRAY = build("7");
|
||||
public static String DARK_GRAY = build("8");
|
||||
public static String BLUE = build("9");
|
||||
public static String GREEN = build("a");
|
||||
public static String AQUA = build("b");
|
||||
public static String RED = build("c");
|
||||
public static String LIGHT_PURPLE = build("d");
|
||||
public static String YELLOW = build("e");
|
||||
public static String WHITE = build("f");
|
||||
public static String MINECOIN_GOLD = build("g");
|
||||
|
||||
public static String UNDERLINE = build("u");
|
||||
public static String BOLD = build("l");
|
||||
public static String ITALIC = build("o");
|
||||
public static String STRIKETHROUGH = build("m");
|
||||
public static String CRAZY = build("k");
|
||||
public static String RESET = build("r");
|
||||
|
||||
public static String doColors(String msg)
|
||||
{
|
||||
for(ChatColor.ColorOptions color : ChatColor.ColorOptions.values()){
|
||||
msg = msg.replace("!"+color.toString()+"!", ChatColor.from(color));
|
||||
msg = msg.replace("!"+color.toString().toLowerCase()+"!", ChatColor.from(color));
|
||||
}
|
||||
for(ChatColor.ColorOptions color : ChatColor.ColorOptions.values()){
|
||||
String correctCode = ChatColor.from(color);
|
||||
String searchCode = "&"+correctCode.substring(1);
|
||||
msg = msg.replace(searchCode, correctCode);
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
public static String build(String c)
|
||||
{
|
||||
return CODE+c;
|
||||
}
|
||||
|
||||
public static String resetChat()
|
||||
{
|
||||
return RESET+WHITE;
|
||||
}
|
||||
|
||||
public static String from(ColorOptions nick){
|
||||
switch(nick){
|
||||
case Black:
|
||||
{
|
||||
return BLACK;
|
||||
}
|
||||
case Dark_Blue:
|
||||
{
|
||||
return DARK_BLUE;
|
||||
}
|
||||
case Dark_Green:
|
||||
{
|
||||
return DARK_GREEN;
|
||||
}
|
||||
case Dark_Aqua:
|
||||
{
|
||||
return DARK_AQUA;
|
||||
}
|
||||
case Dark_Red:
|
||||
{
|
||||
return DARK_RED;
|
||||
}
|
||||
case Dark_Purple:
|
||||
{
|
||||
return DARK_PURPLE;
|
||||
}
|
||||
case Gold:
|
||||
{
|
||||
return GOLD;
|
||||
}
|
||||
case Gray:
|
||||
{
|
||||
return GRAY;
|
||||
}
|
||||
case Dark_Gray:
|
||||
{
|
||||
return DARK_GRAY;
|
||||
}
|
||||
case Blue:
|
||||
{
|
||||
return BLUE;
|
||||
}
|
||||
case Green:
|
||||
{
|
||||
return GREEN;
|
||||
}
|
||||
case Aqua:
|
||||
{
|
||||
return AQUA;
|
||||
}
|
||||
case Red:
|
||||
{
|
||||
return RED;
|
||||
}
|
||||
case Light_Purple:
|
||||
{
|
||||
return LIGHT_PURPLE;
|
||||
}
|
||||
case Yellow:
|
||||
{
|
||||
return YELLOW;
|
||||
}
|
||||
case White:
|
||||
{
|
||||
return WHITE;
|
||||
}
|
||||
case MinecoinGold:
|
||||
{
|
||||
return MINECOIN_GOLD;
|
||||
}
|
||||
case Underline:
|
||||
{
|
||||
return UNDERLINE;
|
||||
}
|
||||
case Bold:
|
||||
{
|
||||
return BOLD;
|
||||
}
|
||||
case Italic:
|
||||
{
|
||||
return ITALIC;
|
||||
}
|
||||
case Strikethrough:
|
||||
{
|
||||
return STRIKETHROUGH;
|
||||
}
|
||||
case Crazy:
|
||||
{
|
||||
return CRAZY;
|
||||
}
|
||||
case Reset:
|
||||
{
|
||||
return RESET+WHITE;
|
||||
}
|
||||
default:
|
||||
{
|
||||
return RESET+CRAZY;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
package com.zontreck.libzontreck.chat;
|
||||
|
||||
public class ChatColorFactory {
|
||||
public class ColorBuilder
|
||||
{
|
||||
private String built;
|
||||
public void append(String s){
|
||||
built+=s;
|
||||
}
|
||||
public String build(){
|
||||
return built;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the color builder
|
||||
*/
|
||||
public void reset()
|
||||
{
|
||||
built="";
|
||||
append(ChatColor.resetChat());
|
||||
}
|
||||
public ColorBuilder(){}
|
||||
}
|
||||
private ColorBuilder instance;
|
||||
|
||||
/**
|
||||
* Resets the chat color builder
|
||||
* @return The current builder
|
||||
*/
|
||||
public ChatColorFactory reset()
|
||||
{
|
||||
instance.reset();
|
||||
return this;
|
||||
}
|
||||
public ChatColorFactory set(ChatColor.ColorOptions option)
|
||||
{
|
||||
instance.append(ChatColor.from(option));
|
||||
return this;
|
||||
}
|
||||
|
||||
public static ChatColorFactory MakeBuilder()
|
||||
{
|
||||
ChatColorFactory inst=new ChatColorFactory();
|
||||
inst.instance=new ChatColorFactory().new ColorBuilder();
|
||||
return inst;
|
||||
}
|
||||
private ChatColorFactory(){}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
return instance.build();
|
||||
}
|
||||
}
|
16
src/main/java/com/zontreck/libzontreck/chat/Clickable.java
Normal file
16
src/main/java/com/zontreck/libzontreck/chat/Clickable.java
Normal file
|
@ -0,0 +1,16 @@
|
|||
package com.zontreck.libzontreck.chat;
|
||||
|
||||
import net.minecraft.network.chat.ClickEvent;
|
||||
import net.minecraft.network.chat.ClickEvent.Action;
|
||||
|
||||
/*
|
||||
* Because of some weird behavior with java not liking that both HoverEvent and ClickEvent have an Action implementation, these must both be in a custom factory here where Action can be imported by itself in both files
|
||||
*/
|
||||
public class Clickable {
|
||||
|
||||
public static ClickEvent command(String text)
|
||||
{
|
||||
return new ClickEvent(Action.RUN_COMMAND, text);
|
||||
}
|
||||
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue