mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-20 12:20:11 +00:00
Added custom elytra support (#6791)
This commit is contained in:
1 parent
5224533d45
commit
a753a3eddc
12 files changed
+309
-9
No files matched your search
@@ -784,4 +784,35 @@ public interface IForgeItem
|
||||
default <T extends LivingEntity> int damageItem(ItemStack stack, int amount, T entity, Consumer<T> onBroken) {
|
||||
return amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to determine if the player can use Elytra flight.
|
||||
* This is called Client and Server side.
|
||||
*
|
||||
* @param stack The ItemStack in the Chest slot of the entity.
|
||||
* @param entity The entity trying to fly.
|
||||
* @return True if the entity can use Elytra flight.
|
||||
*/
|
||||
default boolean canElytraFly(ItemStack stack, LivingEntity entity)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to determine if the player can continue Elytra flight,
|
||||
* this is called each tick, and can be used to apply ItemStack damage,
|
||||
* consume Energy, or what have you.
|
||||
* For example the Vanilla implementation of this, applies damage to the
|
||||
* ItemStack every 20 ticks.
|
||||
*
|
||||
* @param stack ItemStack in the Chest slot of the entity.
|
||||
* @param entity The entity currently in Elytra flight.
|
||||
* @param flightTicks The number of ticks the entity has been Elytra flying for.
|
||||
* @return True if the entity should continue Elytra flight or False to stop.
|
||||
*/
|
||||
default boolean elytraFlightTick(ItemStack stack, LivingEntity entity, int flightTicks)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -448,4 +448,32 @@ public interface IForgeItemStack extends ICapabilitySerializable<CompoundNBT>
|
||||
{
|
||||
return getStack().getItem().isRepairable(getStack());
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to determine if the player can use Elytra flight.
|
||||
* This is called Client and Server side.
|
||||
*
|
||||
* @param entity The entity trying to fly.
|
||||
* @return True if the entity can use Elytra flight.
|
||||
*/
|
||||
default boolean canElytraFly(LivingEntity entity)
|
||||
{
|
||||
return getStack().getItem().canElytraFly(getStack(), entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to determine if the player can continue Elytra flight,
|
||||
* this is called each tick, and can be used to apply ItemStack damage,
|
||||
* consume Energy, or what have you.
|
||||
* For example the Vanilla implementation of this, applies damage to the
|
||||
* ItemStack every 20 ticks.
|
||||
*
|
||||
* @param entity The entity currently in Elytra flight.
|
||||
* @param flightTicks The number of ticks the entity has been Elytra flying for.
|
||||
* @return True if the entity should continue Elytra flight or False to stop.
|
||||
*/
|
||||
default boolean elytraFlightTick(LivingEntity entity, int flightTicks)
|
||||
{
|
||||
return getStack().getItem().elytraFlightTick(getStack(), entity, flightTicks);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
* Minecraft Forge
|
||||
* Copyright (c) 2016-2019.
|
||||
*
|
||||
* This library 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 version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A 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 this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package net.minecraftforge.debug.item;
|
||||
|
||||
import net.minecraft.block.DispenserBlock;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.entity.player.AbstractClientPlayerEntity;
|
||||
import net.minecraft.client.renderer.entity.IEntityRenderer;
|
||||
import net.minecraft.client.renderer.entity.PlayerRenderer;
|
||||
import net.minecraft.client.renderer.entity.layers.ElytraLayer;
|
||||
import net.minecraft.client.renderer.entity.model.ElytraModel;
|
||||
import net.minecraft.client.renderer.entity.model.PlayerModel;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.inventory.EquipmentSlotType;
|
||||
import net.minecraft.item.*;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.SoundEvent;
|
||||
import net.minecraftforge.api.distmarker.Dist;
|
||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||
import net.minecraftforge.eventbus.api.IEventBus;
|
||||
import net.minecraftforge.fml.DistExecutor;
|
||||
import net.minecraftforge.fml.RegistryObject;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.common.thread.EffectiveSide;
|
||||
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@Mod(CustomElytraTest.MOD_ID)
|
||||
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD, modid = CustomElytraTest.MOD_ID)
|
||||
public class CustomElytraTest
|
||||
{
|
||||
public static final String MOD_ID = "custom_elytra_test";
|
||||
private static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, MOD_ID);
|
||||
private static final RegistryObject<Item> TEST_ELYTRA = ITEMS.register("test_elytra",() -> new CustomElytra(new Item.Properties().maxDamage(100).group(ItemGroup.MISC)));
|
||||
|
||||
public CustomElytraTest()
|
||||
{
|
||||
final IEventBus modBus = FMLJavaModLoadingContext.get().getModEventBus();
|
||||
ITEMS.register(modBus);
|
||||
modBus.addListener(this::onClientSetup);
|
||||
}
|
||||
|
||||
private void onClientSetup(FMLClientSetupEvent event)
|
||||
{
|
||||
registerElytraLayer();
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
private void registerElytraLayer()
|
||||
{
|
||||
Minecraft.getInstance().getRenderManager().getSkinMap().values().forEach(player -> player.addLayer(new CustomElytraLayer(player)));
|
||||
}
|
||||
|
||||
public static class CustomElytra extends Item
|
||||
{
|
||||
|
||||
public CustomElytra(Properties properties)
|
||||
{
|
||||
super(properties);
|
||||
DispenserBlock.registerDispenseBehavior(this, ArmorItem.DISPENSER_BEHAVIOR);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public EquipmentSlotType getEquipmentSlot(ItemStack stack)
|
||||
{
|
||||
return EquipmentSlotType.CHEST; //Or you could just extend ItemArmor
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canElytraFly(ItemStack stack, LivingEntity entity)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean elytraFlightTick(ItemStack stack, LivingEntity entity, int flightTicks)
|
||||
{
|
||||
//Adding 1 to ticksElytraFlying prevents damage on the very first tick.
|
||||
if (!entity.world.isRemote && (flightTicks + 1) % 20 == 0)
|
||||
{
|
||||
stack.damageItem(1, entity, e -> e.sendBreakAnimation(EquipmentSlotType.CHEST));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public static class CustomElytraLayer extends ElytraLayer<AbstractClientPlayerEntity, PlayerModel<AbstractClientPlayerEntity>>
|
||||
{
|
||||
private static final ResourceLocation TEXTURE_ELYTRA = new ResourceLocation(MOD_ID, "textures/entity/custom_elytra.png");
|
||||
|
||||
public CustomElytraLayer(IEntityRenderer<AbstractClientPlayerEntity, PlayerModel<AbstractClientPlayerEntity>> rendererIn)
|
||||
{
|
||||
super(rendererIn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldRender(ItemStack stack, AbstractClientPlayerEntity entity)
|
||||
{
|
||||
return stack.getItem() == TEST_ELYTRA.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation getElytraTexture(ItemStack stack, AbstractClientPlayerEntity entity)
|
||||
{
|
||||
return TEXTURE_ELYTRA;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -69,4 +69,6 @@ loaderVersion="[28,)"
|
||||
[[mods]]
|
||||
modId="deferred_registry_test"
|
||||
[[mods]]
|
||||
modId="player_name_event_test"
|
||||
modId="player_name_event_test"
|
||||
[[mods]]
|
||||
modId="custom_elytra_test"
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"parent": "item/generated",
|
||||
"textures": {
|
||||
"layer0": "custom_elytra_test:item/custom_elytra"
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 2.5 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 2.0 KiB |
Reference in new issue
Block a user