Update the way flight works, add night vision enchantment

This commit is contained in:
zontreck 2024-01-12 00:31:06 -07:00
parent b0cb340f30
commit 99503453c2
13 changed files with 340 additions and 96 deletions

View file

@ -49,7 +49,7 @@ mod_name=OTEMod
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
mod_license=GPLv3
# The mod version. See https://semver.org/
mod_version=1.4.011124.0201
mod_version=1.4.011224.0030
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
# This should match the base package used for the mod sources.
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html

View file

@ -1,5 +1,6 @@
version:2975
version:3465
autoJump:false
operatorItemsTab:false
autoSuggestions:true
chatColors:true
chatLinks:true
@ -12,6 +13,7 @@ invertYMouse:false
realmsNotifications:true
reducedDebugInfo:false
showSubtitles:true
directionalAudio:false
touchscreen:false
fullscreen:false
bobView:true
@ -23,6 +25,11 @@ mouseSensitivity:0.5
fov:0.0
screenEffectScale:1.0
fovEffectScale:1.0
darknessEffectScale:1.0
glintSpeed:0.5
glintStrength:0.75
damageTiltStrength:1.0
highContrast:false
gamma:1.0
renderDistance:12
simulationDistance:12
@ -30,12 +37,11 @@ entityDistanceScaling:1.0
guiScale:2
particles:0
maxFps:120
difficulty:2
graphicsMode:1
ao:2
ao:true
prioritizeChunkUpdates:0
biomeBlendRadius:2
renderClouds:false
renderClouds:"false"
resourcePacks:[]
incompatibleResourcePacks:[]
lastServer:127.0.0.1
@ -51,15 +57,15 @@ advancedItemTooltips:true
pauseOnLostFocus:true
overrideWidth:0
overrideHeight:0
heldItemTooltips:true
chatHeightFocused:1.0
chatDelay:0.0
chatHeightUnfocused:0.4375
chatScale:1.0
chatWidth:1.0
notificationDisplayTime:1.0
mipmapLevels:4
useNativeTransport:true
mainHand:right
mainHand:"right"
attackIndicator:1
narrator:0
tutorialStep:none
@ -74,6 +80,10 @@ hideBundleTutorial:false
syncChunkWrites:true
showAutosaveIndicator:true
allowServerListing:true
onlyShowSecureChat:false
panoramaScrollSpeed:1.0
telemetryOptInExtra:false
onboardAccessibility:false
key_key.attack:key.mouse.left
key_key.use:key.mouse.right
key_key.forward:key.keyboard.w
@ -108,37 +118,6 @@ key_key.hotbar.6:key.keyboard.6
key_key.hotbar.7:key.keyboard.7
key_key.hotbar.8:key.keyboard.8
key_key.hotbar.9:key.keyboard.9
key_key.jei.toggleOverlay:key.keyboard.o:CONTROL
key_key.jei.focusSearch:key.keyboard.f:CONTROL
key_key.jei.previousPage:key.keyboard.unknown
key_key.jei.nextPage:key.keyboard.unknown
key_key.jei.toggleBookmarkOverlay:key.keyboard.unknown
key_key.jei.bookmark:key.keyboard.a
key_key.jei.showRecipe:key.keyboard.r
key_key.jei.showRecipe2:key.mouse.left
key_key.jei.showUses:key.keyboard.u
key_key.jei.showUses2:key.mouse.right
key_key.jei.clearSearchBar:key.mouse.right
key_key.jei.previousSearch:key.keyboard.up
key_key.jei.nextSearch:key.keyboard.down
key_key.jei.toggleCheatMode:key.keyboard.unknown
key_key.jei.cheatOneItem:key.mouse.left
key_key.jei.cheatOneItem2:key.mouse.right
key_key.jei.cheatItemStack:key.mouse.left:SHIFT
key_key.jei.cheatItemStack2:key.mouse.middle
key_key.jei.toggleCheatModeConfigButton:key.mouse.left:CONTROL
key_key.jei.toggleEditMode:key.keyboard.unknown
key_key.jei.toggleHideIngredient:key.mouse.left:CONTROL
key_key.jei.toggleWildcardHideIngredient:key.mouse.right:CONTROL
key_key.jei.recipeBack:key.keyboard.backspace
key_key.jei.previousRecipePage:key.keyboard.page.up
key_key.jei.nextRecipePage:key.keyboard.page.down
key_key.jei.previousCategory:key.keyboard.page.up:SHIFT
key_key.jei.nextCategory:key.keyboard.page.down:SHIFT
key_key.jei.closeRecipeGui:key.keyboard.escape
key_key.jei.copy.recipe.id:key.keyboard.unknown
key_key.tconstruct.helmet_interact:key.keyboard.z
key_key.tconstruct.leggings_interact:key.keyboard.i
key_key.mekanism.mode:key.keyboard.n
key_key.mekanism.head_mode:key.keyboard.v
key_key.mekanism.chest_mode:key.keyboard.g

View file

@ -16,6 +16,7 @@ import dev.zontreck.libzontreck.profiles.Profile;
import dev.zontreck.libzontreck.profiles.UserProfileNotYetExistsException;
import dev.zontreck.libzontreck.util.ChatHelpers;
import dev.zontreck.libzontreck.vectors.Vector3;
import dev.zontreck.otemod.effects.ModEffects;
import dev.zontreck.otemod.implementation.CreativeModeTabs;
import dev.zontreck.otemod.implementation.InventoryBackup;
import dev.zontreck.otemod.implementation.Messages;
@ -133,6 +134,7 @@ public class OTEMod
ModEnchantments.register(bus);
ModEntityTypes.register(bus);
ModRecipes.register(bus);
ModEffects.register(bus);
//MenuInitializer.register(bus);

View file

@ -0,0 +1,101 @@
package dev.zontreck.otemod.effects;
import dev.zontreck.libzontreck.LibZontreck;
import dev.zontreck.libzontreck.util.ChatHelpers;
import dev.zontreck.libzontreck.util.ItemUtils;
import dev.zontreck.libzontreck.util.ServerUtilities;
import dev.zontreck.otemod.enchantments.ModEnchantments;
import dev.zontreck.otemod.implementation.Messages;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.effect.MobEffectCategory;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.ai.attributes.AttributeMap;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.entity.player.Abilities;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.fml.LogicalSide;
import org.jetbrains.annotations.Nullable;
public class FlightEffect extends MobEffect {
protected FlightEffect(MobEffectCategory pCategory, int pColor) {
super(pCategory, pColor);
}
@Override
public void applyEffectTick(LivingEntity pLivingEntity, int pAmplifier) {
super.applyEffectTick(pLivingEntity, pAmplifier);
if(LibZontreck.CURRENT_SIDE == LogicalSide.CLIENT) return;
if(pLivingEntity instanceof Player)
{
if(LibZontreck.CURRENT_SIDE == LogicalSide.SERVER)
{
ServerPlayer player = ServerUtilities.getPlayerByID(pLivingEntity.getStringUUID());
recheck(player);
}
}
}
@Override
public boolean isDurationEffectTick(int pDuration, int pAmplifier) {
return true;
}
@Override
public void applyInstantenousEffect(@Nullable Entity pSource, @Nullable Entity pIndirectSource, LivingEntity pLivingEntity, int pAmplifier, double pHealth) {
if(LibZontreck.CURRENT_SIDE == LogicalSide.CLIENT) return;
if(pLivingEntity instanceof Player)
{
ServerPlayer player = ServerUtilities.getPlayerByID(pLivingEntity.getStringUUID());
recheck(player);
}
super.applyInstantenousEffect(pSource, pIndirectSource, pLivingEntity, pAmplifier, pHealth);
}
private static void recheck(ServerPlayer sp)
{
if(sp.gameMode.isCreative())return; // Don't mess with the creative mode attributes
ItemStack feet = sp.getItemBySlot(EquipmentSlot.FEET);
boolean hasFlight = false;
if(ItemUtils.getEnchantmentLevel(ModEnchantments.FLIGHT_ENCHANTMENT.get(), feet)>0)hasFlight=true;
if(!hasFlight)
{
sp.removeEffect(ModEffects.FLIGHT.get());
}
Abilities playerAbilities = sp.getAbilities();
if(hasFlight)
{
if(playerAbilities.mayfly == false)
{
playerAbilities.mayfly=true;
sp.onUpdateAbilities();
ChatHelpers.broadcastTo(sp, ChatHelpers.macro(Messages.FLIGHT_GIVEN), sp.server);
}
}else {
if(playerAbilities.mayfly)
{
playerAbilities.mayfly=false;
playerAbilities.flying=false;
sp.onUpdateAbilities();
ChatHelpers.broadcastTo(sp, ChatHelpers.macro(Messages.FLIGHT_REMOVED), sp.server);
}
}
}
}

View file

@ -0,0 +1,23 @@
package dev.zontreck.otemod.effects;
import dev.zontreck.otemod.OTEMod;
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, OTEMod.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);
}
}

View file

@ -0,0 +1,33 @@
package dev.zontreck.otemod.enchantments;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.world.item.enchantment.EnchantmentCategory;
public class BorrowedProtectionEnchantment extends Enchantment
{
protected BorrowedProtectionEnchantment(Rarity pRarity, EnchantmentCategory pCategory, EquipmentSlot[] pApplicableSlots) {
super(pRarity, pCategory, pApplicableSlots);
}
@Override
public boolean isCurse() {
return false;
}
@Override
public boolean isTradeable() {
return true;
}
@Override
public boolean isDiscoverable() {
return true;
}
@Override
public boolean isTreasureOnly() {
return false;
}
}

View file

@ -2,9 +2,13 @@ package dev.zontreck.otemod.enchantments;
import dev.zontreck.libzontreck.util.ItemUtils;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.configs.OTEServerConfig;
import dev.zontreck.otemod.effects.ModEffects;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.level.ServerPlayerGameMode;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.player.Abilities;
import net.minecraft.world.entity.player.Player;
@ -14,71 +18,19 @@ import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.world.item.enchantment.EnchantmentCategory;
import net.minecraft.world.item.enchantment.Enchantments;
import net.minecraft.world.item.enchantment.SoulSpeedEnchantment;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.event.entity.living.LivingEquipmentChangeEvent;
import net.minecraftforge.event.entity.player.PlayerEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.LogicalSide;
import net.minecraftforge.fml.common.Mod;
import java.util.concurrent.atomic.AtomicInteger;
@Mod.EventBusSubscriber(modid = OTEMod.MOD_ID)
public class FlightEnchantment extends Enchantment
{
@Mod.EventBusSubscriber(modid = OTEMod.MOD_ID, bus=Mod.EventBusSubscriber.Bus.FORGE)
public static class EventHandler{
@SubscribeEvent
public static void onLivingUpdate(LivingEquipmentChangeEvent ev)
{
if(ev.getEntity() instanceof Player)
{
if(ev.getEntity().level().isClientSide)return;
ServerPlayer sp = (ServerPlayer)ev.getEntity();
recheck(sp);
}
}
private static void recheck(ServerPlayer sp)
{
if(sp.gameMode.isCreative())return; // Don't mess with the creative mode attributes
ItemStack feet = sp.getItemBySlot(EquipmentSlot.FEET);
boolean hasFlight = false;
if(ItemUtils.getEnchantmentLevel(ModEnchantments.FLIGHT_ENCHANTMENT.get(), feet)>0)hasFlight=true;
Abilities playerAbilities = sp.getAbilities();
if(playerAbilities.mayfly == false)
{
if(hasFlight){
playerAbilities.mayfly=true;
sp.onUpdateAbilities();
}
}else {
if(!hasFlight){
playerAbilities.mayfly=false;
playerAbilities.flying=false;
sp.onUpdateAbilities();
}
}
}
@SubscribeEvent
public static void onGameModeChange(PlayerEvent.PlayerChangeGameModeEvent ev)
{
if(ev.getEntity().level().isClientSide)return;
recheck((ServerPlayer)ev.getEntity());
}
@SubscribeEvent
public static void onArmorBreak(LivingEquipmentChangeEvent ev)
{
}
}
public FlightEnchantment(EquipmentSlot... slots)
{
@ -120,4 +72,46 @@ public class FlightEnchantment extends Enchantment
{
return true;
}
public static AtomicInteger TICKS = new AtomicInteger(0);
@SubscribeEvent
public static void onEnchantmentTick(TickEvent.PlayerTickEvent event)
{
if(event.side == LogicalSide.CLIENT) return;
if(TICKS.getAndIncrement() >= (5*20))
{
TICKS.set(0);
if(OTEServerConfig.DEBUG.get())
{
OTEMod.LOGGER.info("> Flight Enchantment Tick <");
}
if(event.phase == TickEvent.Phase.END)
{
ServerPlayer sp = (ServerPlayer) event.player;
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(), -1, 0, false, false, true);
event.player.addEffect(inst);
}
}
}
}
}

View file

@ -3,6 +3,7 @@ package dev.zontreck.otemod.enchantments;
import dev.zontreck.otemod.OTEMod;
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;
@ -17,6 +18,10 @@ public class ModEnchantments {
public static final RegistryObject<Enchantment> FLIGHT_ENCHANTMENT = REGISTERS.register("player_flight", ()->new FlightEnchantment(EquipmentSlot.FEET));
public static final RegistryObject<Enchantment> BORROWED_PROTECTION = REGISTERS.register("borrowed_protection", ()->new BorrowedProtectionEnchantment(Enchantment.Rarity.UNCOMMON, EnchantmentCategory.ARMOR, ARMOR_SLOTS));
public static final RegistryObject<Enchantment> NIGHT_VISION_ENCHANT = REGISTERS.register("night_vision", ()->new NightVisionEnchantment(EquipmentSlot.HEAD));
public static void register(IEventBus bus){
REGISTERS.register(bus);
}

View file

@ -0,0 +1,95 @@
package dev.zontreck.otemod.enchantments;
import dev.zontreck.libzontreck.util.ItemUtils;
import dev.zontreck.otemod.OTEMod;
import dev.zontreck.otemod.configs.OTEServerConfig;
import dev.zontreck.otemod.effects.ModEffects;
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;
import net.minecraftforge.api.distmarker.Dist;
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.concurrent.atomic.AtomicInteger;
@Mod.EventBusSubscriber(modid = OTEMod.MOD_ID)
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 AtomicInteger TICKS = new AtomicInteger(0);
@SubscribeEvent
public static void onEnchantmentTick(TickEvent.PlayerTickEvent event)
{
if(event.side == LogicalSide.CLIENT) return;
if(TICKS.getAndIncrement() >= (2*20))
{
TICKS.set(0);
if(OTEServerConfig.DEBUG.get())
{
OTEMod.LOGGER.info("> NVision Enchantment Tick <");
}
if(event.phase == TickEvent.Phase.END)
{
ServerPlayer sp = (ServerPlayer) event.player;
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);
event.player.addEffect(inst);
}
}
}
}
}

View file

@ -11,6 +11,9 @@ public class Messages {
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;
static{
OTE_PREFIX = "!Dark_Gray![!Dark_Purple!OTE!Dark_Gray!] ";
@ -23,5 +26,7 @@ public class Messages {
STARTER_FAILURE_CONSOLE = OTE_PREFIX + "!Dark_Red!This command can only be executed from within the game";
STARTER_FAILURE_PERMISSIONS = OTE_PREFIX + "!Dark_Red!This command can only be executed by server operators";
STARTER_KIT_GIVEN = OTE_PREFIX + "!Dark_Purple!You have been given a starter kit. Welcome to the server.";
FLIGHT_GIVEN = OTE_PREFIX + "!Dark_Green!You start to feel lighter than a feather";
FLIGHT_REMOVED = OTE_PREFIX + "!Dark_Red!You have a sinking feeling you are no longer lighter than a feather.";
}
}

View file

@ -73,6 +73,12 @@
"enchantment.otemod.player_flight": "Flight",
"enchantment.otemod.mob_egging.desc": "Chance of mob spawn eggs to drop",
"enchantment.otemod.player_flight.desc": "Allows you to fly!",
"enchantment.otemod.borrowed_protection": "Borrowed Protection",
"enchantment.otemod.borrowed_protection.desc": "Borrows protection from any nearby player.",
"enchantment.otemod.night_vision": "Night Vision",
"effect.otemod.flight": "Flight",
"dev.zontreck.otemod.msgs.only_player": "§cOnly players are allowed to execute this command",

Binary file not shown.

After

Width:  |  Height:  |  Size: 309 B

View file

@ -5,5 +5,6 @@
},
"input": {
"item": "otemod:encased_singularity"
}
},
"time": 60
}