Skip to content

Commit

Permalink
port to 1.16.1
Browse files Browse the repository at this point in the history
  • Loading branch information
TheIllusiveC4 committed Jul 2, 2020
1 parent 1ffc84d commit 16afeb8
Show file tree
Hide file tree
Showing 27 changed files with 364 additions and 774 deletions.
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
blank_issues_enabled: false
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ org.gradle.jvmargs=-Xmx3G
org.gradle.daemon=false

# Mod
mod_version=2.0-beta3
mod_version=2.0-beta4
mod_group=top.theillusivec4.caelus
mod_id=caelus
mod_name=Caelus API
Expand All @@ -13,9 +13,9 @@ mod_description=A coremod and API to provide developers access to elytra flight
mod_icon=caelus_icon.png

# Dependencies
version_minecraft=FORGE-1.15.2
version_forge=1.15.2-31.1.0
version_mcp=20200201-1.15.1
version_minecraft=FORGE-1.16.1
version_forge=1.16.1-32.0.34
version_mcp=20200514-1.16

# Curse
curse_id=308989
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#Wed Jul 01 02:12:49 PDT 2020
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-all.zip
2 changes: 1 addition & 1 deletion gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
DEFAULT_JVM_OPTS='"-Xmx64m"'

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
Expand Down
2 changes: 1 addition & 1 deletion gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=
set DEFAULT_JVM_OPTS="-Xmx64m"

@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
Expand Down
92 changes: 18 additions & 74 deletions src/main/java/top/theillusivec4/caelus/Caelus.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,121 +19,65 @@

package top.theillusivec4.caelus;

import java.util.function.Function;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.entity.EntityRendererManager;
import net.minecraft.client.renderer.entity.LivingRenderer;
import net.minecraft.client.renderer.entity.model.EntityModel;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.ai.attributes.IAttributeInstance;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.ai.attributes.ModifiableAttributeInstance;
import net.minecraft.inventory.EquipmentSlotType;
import net.minecraft.item.ElytraItem;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.EntityEvent;
import net.minecraftforge.event.entity.living.LivingEquipmentChangeEvent;
import net.minecraftforge.event.TickEvent.PlayerTickEvent;
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.config.ModConfig;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLLoadCompleteEvent;
import net.minecraftforge.fml.event.lifecycle.InterModProcessEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import top.theillusivec4.caelus.api.CaelusAPI;
import top.theillusivec4.caelus.api.CaelusAPI.ElytraRender;
import top.theillusivec4.caelus.api.CaelusAPI.IMC;
import top.theillusivec4.caelus.client.ClientEventHandler;
import top.theillusivec4.caelus.client.KeyRegistry;
import top.theillusivec4.caelus.client.renderer.CaelusElytraLayer;
import top.theillusivec4.caelus.common.CaelusConfig;
import top.theillusivec4.caelus.api.CaelusApi;
import top.theillusivec4.caelus.client.CaelusElytraLayer;
import top.theillusivec4.caelus.common.network.NetworkHandler;

@Mod(Caelus.MODID)
public class Caelus {

public static final String MODID = "caelus";

public static final ResourceLocation DISABLED_ICON = new ResourceLocation(Caelus.MODID,
"textures/gui/flight_disabled.png");
public static final String MODID = CaelusApi.MODID;

public Caelus() {
IEventBus eventBus = FMLJavaModLoadingContext.get().getModEventBus();
CaelusApi.ATTRIBUTES.register(eventBus);
eventBus.addListener(this::setup);
eventBus.addListener(this::process);
ModLoadingContext.get().registerConfig(ModConfig.Type.CLIENT, CaelusConfig.clientSpec);
MinecraftForge.EVENT_BUS.register(this);
}

private void setup(FMLCommonSetupEvent evt) {
NetworkHandler.register();
}

private void process(InterModProcessEvent evt) {
evt.getIMCStream(IMC.ELYTRA_RENDER::equals)
.filter(msg -> msg.getMessageSupplier().get() instanceof Function)
.map(msg -> (Function<LivingEntity, ElytraRender>) msg.getMessageSupplier().get())
.forEach(func -> CaelusAPI.renderFunctions.add(func));
}

@SubscribeEvent
public void attachAttribute(EntityEvent.EntityConstructing evt) {

if (evt.getEntity() instanceof PlayerEntity) {
((PlayerEntity) evt.getEntity()).getAttributes().registerAttribute(CaelusAPI.ELYTRA_FLIGHT);
}
}

@SubscribeEvent
public void onLivingEquipmentChange(LivingEquipmentChangeEvent evt) {

if (!(evt.getEntityLiving() instanceof PlayerEntity)
|| evt.getSlot() != EquipmentSlotType.CHEST) {
return;
}

ItemStack from = evt.getFrom();
ItemStack to = evt.getTo();
IAttributeInstance attributeInstance = evt.getEntityLiving()
.getAttribute(CaelusAPI.ELYTRA_FLIGHT);

if (from.getItem() instanceof ElytraItem) {
attributeInstance.removeModifier(CaelusAPI.ELYTRA_MODIFIER);
}

if (to.getItem() instanceof ElytraItem && !attributeInstance
.hasModifier(CaelusAPI.ELYTRA_MODIFIER) && ElytraItem.isUsable(to)) {
attributeInstance.applyModifier(CaelusAPI.ELYTRA_MODIFIER);
public void playerTick(PlayerTickEvent evt) {
ModifiableAttributeInstance attributeInstance = evt.player
.getAttribute(CaelusApi.ELYTRA_FLIGHT.get());

if (attributeInstance != null) {
attributeInstance.removeModifier(CaelusApi.ELYTRA_MODIFIER);
ItemStack stack = evt.player.getItemStackFromSlot(EquipmentSlotType.CHEST);

if (stack.getItem() instanceof ElytraItem && !attributeInstance
.hasModifier(CaelusApi.ELYTRA_MODIFIER) && ElytraItem.isUsable(stack)) {
attributeInstance.func_233767_b_(CaelusApi.ELYTRA_MODIFIER);
}
}
}

@Mod.EventBusSubscriber(modid = MODID, value = Dist.CLIENT, bus = Mod.EventBusSubscriber.Bus.MOD)
public static class ClientSetup {

@SubscribeEvent
public static void clientSetup(FMLClientSetupEvent evt) {

KeyRegistry.register();
MinecraftForge.EVENT_BUS.register(new ClientEventHandler());
}

@SubscribeEvent
public static void postSetup(FMLLoadCompleteEvent evt) {

EntityRendererManager rendererManager = Minecraft.getInstance().getRenderManager();
rendererManager.getSkinMap().values()
.forEach(renderer -> renderer.addLayer(new CaelusElytraLayer<>(renderer)));
rendererManager.renderers.values().forEach(renderer -> {
if (renderer instanceof LivingRenderer) {
LivingRenderer<? extends LivingEntity, ? extends EntityModel> livingRenderer = (LivingRenderer<? extends LivingEntity, ? extends EntityModel>) renderer;
livingRenderer.addLayer(new CaelusElytraLayer(livingRenderer));
}
});
}
}
}
110 changes: 0 additions & 110 deletions src/main/java/top/theillusivec4/caelus/api/CaelusAPI.java

This file was deleted.

73 changes: 73 additions & 0 deletions src/main/java/top/theillusivec4/caelus/api/CaelusApi.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright (C) 2019 C4
*
* This file is part of Caelus, a mod made for Minecraft.
*
* Caelus is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Caelus is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with Caelus. If not, see <https://www.gnu.org/licenses/>.
*/

package top.theillusivec4.caelus.api;

import java.util.UUID;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.ai.attributes.Attribute;
import net.minecraft.entity.ai.attributes.AttributeModifier;
import net.minecraft.entity.ai.attributes.ModifiableAttributeInstance;
import net.minecraft.entity.ai.attributes.RangedAttribute;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.EquipmentSlotType;
import net.minecraft.item.ElytraItem;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraftforge.fml.RegistryObject;
import net.minecraftforge.registries.DeferredRegister;

public class CaelusApi {

public static final String MODID = "caelus";
public static final DeferredRegister<Attribute> ATTRIBUTES = DeferredRegister
.create(Attribute.class, MODID);

/**
* The elytra flight attribute, will provide elytra flight if the value is 1.0 or above. No flight
* otherwise.
*/
public static final RegistryObject<Attribute> ELYTRA_FLIGHT = ATTRIBUTES.register("elytra_flight",
() -> new RangedAttribute("caelus.elytraFlight", 0.0d, 0.0d, 1.0d).func_233753_a_(true));

/**
* The attribute modifier used for the vanilla elytra item.
*/
public static final AttributeModifier ELYTRA_MODIFIER = new AttributeModifier(
UUID.fromString("5b6c3728-9c24-42ae-83ac-70d61d8b8199"), "Elytra modifier", 1.0f,
AttributeModifier.Operation.ADDITION);

/**
* Checks whether or not an entity is able to elytra fly. Checks against the elytra flight
* attribute if the entity is a {@link PlayerEntity}. Otherwise checks against the ItemStack in
* the chest slot to see if it's a vanilla elytra item.
*
* @param livingEntity The entity to check for elytra flight capabilities
* @return True if the entity can elytra fly, false otherwise.
*/
public static boolean canElytraFly(LivingEntity livingEntity) {

if (!(livingEntity instanceof PlayerEntity)) {
ItemStack stack = livingEntity.getItemStackFromSlot(EquipmentSlotType.CHEST);
return stack.getItem() == Items.ELYTRA && ElytraItem.isUsable(stack);
}
ModifiableAttributeInstance attribute = livingEntity.getAttribute(ELYTRA_FLIGHT.get());
return attribute != null && attribute.getValue() >= 1.0d;
}
}
Loading

0 comments on commit 16afeb8

Please sign in to comment.