mirror of
https://github.com/Sollace/Unicopia.git
synced 2025-03-03 16:51:28 +01:00
Fixed gear not rendering on ponies
This commit is contained in:
parent
f45817bfd6
commit
a1f84872f2
5 changed files with 51 additions and 21 deletions
|
@ -15,7 +15,6 @@ import net.minecraft.client.render.VertexConsumer;
|
|||
import net.minecraft.client.render.entity.model.BipedEntityModel;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EquipmentSlot;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
|
@ -32,8 +31,7 @@ class AmuletGear extends AmuletModel implements IGear {
|
|||
|
||||
@Override
|
||||
public boolean canRender(IModel model, Entity entity) {
|
||||
return entity instanceof LivingEntity living
|
||||
&& living.getEquippedStack(EquipmentSlot.CHEST).getItem() instanceof AmuletItem;
|
||||
return entity instanceof LivingEntity living && !AmuletItem.getForEntity(living).isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -43,7 +41,7 @@ class AmuletGear extends AmuletModel implements IGear {
|
|||
|
||||
@Override
|
||||
public <T extends Entity> Identifier getTexture(T entity, Context<T, ?> context) {
|
||||
return textures.computeIfAbsent(Registry.ITEM.getId(((LivingEntity)entity).getEquippedStack(EquipmentSlot.CHEST).getItem()), id -> new Identifier(id.getNamespace(), "textures/models/armor/" + id.getPath() + ".png"));
|
||||
return textures.computeIfAbsent(Registry.ITEM.getId(AmuletItem.getForEntity((LivingEntity)entity).getItem()), id -> new Identifier(id.getNamespace(), "textures/models/armor/" + id.getPath() + ".png"));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -10,6 +10,7 @@ import com.minelittlepony.unicopia.client.render.BraceletFeatureRenderer;
|
|||
import com.minelittlepony.unicopia.client.render.BraceletFeatureRenderer.BraceletModel;
|
||||
import com.minelittlepony.unicopia.item.FriendshipBraceletItem;
|
||||
import com.minelittlepony.unicopia.item.GlowableItem;
|
||||
import com.minelittlepony.unicopia.trinkets.TrinketsDelegate;
|
||||
|
||||
import net.minecraft.client.model.Dilation;
|
||||
import net.minecraft.client.network.ClientPlayerEntity;
|
||||
|
@ -17,10 +18,9 @@ import net.minecraft.client.render.VertexConsumer;
|
|||
import net.minecraft.client.render.entity.model.BipedEntityModel;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EquipmentSlot;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.item.DyeableItem;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.Arm;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
class BangleGear implements IGear {
|
||||
|
@ -33,7 +33,10 @@ class BangleGear implements IGear {
|
|||
|
||||
private IModel model;
|
||||
|
||||
public BangleGear() {
|
||||
private final Identifier slot;
|
||||
|
||||
public BangleGear(Identifier slot) {
|
||||
this.slot = slot;
|
||||
Dilation dilation = new Dilation(0.3F);
|
||||
steveModel = new BraceletModel(BraceletModel.getData(dilation, false, -1, 4, 0).createModel());
|
||||
alexModel = new BraceletModel(BraceletModel.getData(dilation, true, -1, 4, 0).createModel());
|
||||
|
@ -41,8 +44,7 @@ class BangleGear implements IGear {
|
|||
|
||||
@Override
|
||||
public boolean canRender(IModel model, Entity entity) {
|
||||
return entity instanceof LivingEntity living
|
||||
&& living.getEquippedStack(EquipmentSlot.CHEST).getItem() instanceof FriendshipBraceletItem;
|
||||
return entity instanceof LivingEntity living && FriendshipBraceletItem.getWornBangles(living, slot).findFirst().isPresent();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -57,19 +59,19 @@ class BangleGear implements IGear {
|
|||
|
||||
@Override
|
||||
public void setModelAttributes(IModel model, Entity entity) {
|
||||
ItemStack item = ((LivingEntity)entity).getEquippedStack(EquipmentSlot.CHEST);
|
||||
|
||||
color = ((DyeableItem)item.getItem()).getColor(item);
|
||||
glowing = ((GlowableItem)item.getItem()).isGlowing(item);
|
||||
alex = entity instanceof ClientPlayerEntity && ((ClientPlayerEntity)entity).getModel().startsWith("slim");
|
||||
this.model = model;
|
||||
|
||||
alex = entity instanceof ClientPlayerEntity && ((ClientPlayerEntity)entity).getModel().startsWith("slim");
|
||||
FriendshipBraceletItem.getWornBangles((LivingEntity)entity, slot).findFirst().ifPresent(bracelet -> {
|
||||
color = ((DyeableItem)bracelet.getItem()).getColor(bracelet);
|
||||
glowing = ((GlowableItem)bracelet.getItem()).isGlowing(bracelet);
|
||||
});
|
||||
BraceletModel m = alex ? alexModel : steveModel;
|
||||
|
||||
if (model instanceof BipedEntityModel<?> biped) {
|
||||
m.setAngles(biped);
|
||||
}
|
||||
m.setVisible(((LivingEntity)entity).getMainArm());
|
||||
Arm mainArm = ((LivingEntity)entity).getMainArm();
|
||||
m.setVisible(slot == TrinketsDelegate.MAINHAND ? mainArm : mainArm.getOpposite());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -77,7 +79,6 @@ class BangleGear implements IGear {
|
|||
popAndApply(model, BodyPart.LEGS, stack);
|
||||
|
||||
BraceletModel m = alex ? alexModel : steveModel;
|
||||
|
||||
m.render(stack, consumer, glowing ? 0x0F00F0 : light, overlay, Color.r(color), Color.g(color), Color.b(color), 1);
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ import com.minelittlepony.client.render.LevitatingItemRenderer;
|
|||
import com.minelittlepony.unicopia.*;
|
||||
import com.minelittlepony.unicopia.client.render.PlayerPoser.Animation;
|
||||
import com.minelittlepony.unicopia.entity.player.Pony;
|
||||
import com.minelittlepony.unicopia.trinkets.TrinketsDelegate;
|
||||
import com.minelittlepony.unicopia.util.AnimationUtil;
|
||||
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
|
@ -29,7 +30,8 @@ public class Main extends MineLPDelegate implements ClientModInitializer {
|
|||
public void onInitializeClient() {
|
||||
INSTANCE = this;
|
||||
PonyModelPrepareCallback.EVENT.register(this::onPonyModelPrepared);
|
||||
IGear.register(BangleGear::new);
|
||||
IGear.register(() -> new BangleGear(TrinketsDelegate.MAINHAND));
|
||||
IGear.register(() -> new BangleGear(TrinketsDelegate.OFFHAND));
|
||||
IGear.register(AmuletGear::new);
|
||||
}
|
||||
|
||||
|
|
|
@ -4,23 +4,26 @@ import com.minelittlepony.unicopia.trinkets.TrinketsDelegate;
|
|||
|
||||
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
|
||||
import net.minecraft.block.DispenserBlock;
|
||||
import net.minecraft.entity.EquipmentSlot;
|
||||
import net.minecraft.block.dispenser.DispenserBehavior;
|
||||
import net.minecraft.block.dispenser.ItemDispenserBehavior;
|
||||
import net.minecraft.entity.*;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ArmorItem;
|
||||
import net.minecraft.item.ArmorMaterials;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Wearable;
|
||||
import net.minecraft.predicate.entity.EntityPredicates;
|
||||
import net.minecraft.sound.SoundEvent;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.TypedActionResult;
|
||||
import net.minecraft.util.math.*;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public abstract class WearableItem extends Item implements Wearable {
|
||||
|
||||
public WearableItem(FabricItemSettings settings) {
|
||||
super(configureEquipmentSlotSupplier(settings));
|
||||
DispenserBlock.registerBehavior(this, ArmorItem.DISPENSER_BEHAVIOR);
|
||||
DispenserBlock.registerBehavior(this, DISPENSER_BEHAVIOR);
|
||||
TrinketsDelegate.getInstance().registerTrinket(this);
|
||||
}
|
||||
|
||||
|
@ -49,4 +52,26 @@ public abstract class WearableItem extends Item implements Wearable {
|
|||
public EquipmentSlot getPreferredSlot(ItemStack stack) {
|
||||
return EquipmentSlot.OFFHAND;
|
||||
}
|
||||
|
||||
public static boolean dispenseArmor(BlockPointer pointer, ItemStack armor) {
|
||||
return pointer.getWorld().getEntitiesByClass(
|
||||
LivingEntity.class,
|
||||
new Box(pointer.getPos().offset(pointer.getBlockState().get(DispenserBlock.FACING))),
|
||||
EntityPredicates.EXCEPT_SPECTATOR.and(new EntityPredicates.Equipable(armor))
|
||||
)
|
||||
.stream()
|
||||
.flatMap(entity -> TrinketsDelegate.getInstance()
|
||||
.getAvailableTrinketSlots(entity, TrinketsDelegate.ALL)
|
||||
.stream()
|
||||
.filter(slotId -> TrinketsDelegate.getInstance().equipStack(entity, slotId, armor)))
|
||||
.findFirst()
|
||||
.isPresent();
|
||||
}
|
||||
|
||||
private static final DispenserBehavior DISPENSER_BEHAVIOR = new ItemDispenserBehavior(){
|
||||
@Override
|
||||
protected ItemStack dispenseSilently(BlockPointer pointer, ItemStack stack) {
|
||||
return dispenseArmor(pointer, stack) ? stack : super.dispenseSilently(pointer, stack);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -39,6 +39,10 @@ public interface TrinketsDelegate {
|
|||
}
|
||||
|
||||
entity.equipStack(eq, stack.split(1));
|
||||
if (entity instanceof MobEntity mob) {
|
||||
mob.setEquipmentDropChance(eq, 2.0f);
|
||||
mob.setPersistent();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue