-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: 秋雨落 <[email protected]>
- Loading branch information
Showing
8 changed files
with
243 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
src/main/java/org/teacon/chromeball/client/entity/renderer/DoorChromeRenderer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package org.teacon.chromeball.client.entity.renderer; | ||
|
||
import com.mojang.blaze3d.vertex.PoseStack; | ||
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.client.renderer.entity.ItemRenderer; | ||
import net.minecraft.client.renderer.texture.OverlayTexture; | ||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.entity.EntityAttachment; | ||
import net.minecraft.world.item.ItemDisplayContext; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.phys.Vec3; | ||
import net.neoforged.neoforge.client.ClientHooks; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.joml.Matrix4f; | ||
import org.teacon.chromeball.ChromeBall; | ||
import org.teacon.chromeball.common.ChromeBallRegistry; | ||
import org.teacon.chromeball.common.entity.ChromeLivingEntity; | ||
|
||
public class DoorChromeRenderer extends EntityRenderer<ChromeLivingEntity> { | ||
|
||
private static ItemStack CHROME_BALL; | ||
|
||
private final ItemRenderer itemRenderer; | ||
|
||
public DoorChromeRenderer(EntityRendererProvider.Context context) { | ||
super(context); | ||
this.itemRenderer = context.getItemRenderer(); | ||
|
||
if (CHROME_BALL == null) { | ||
CHROME_BALL = new ItemStack(ChromeBallRegistry.CHROME_BALL_ITEM); | ||
} | ||
} | ||
|
||
@Override | ||
public void render(@NotNull ChromeLivingEntity entity, float entityYaw, float partialTick, | ||
@NotNull PoseStack poseStack, @NotNull MultiBufferSource bufferSource, int packedLight) { | ||
poseStack.pushPose(); | ||
poseStack.translate(0, 0.6, 0); | ||
poseStack.scale(3F, 3F, 3F); | ||
poseStack.mulPose(this.entityRenderDispatcher.cameraOrientation()); | ||
this.itemRenderer.renderStatic(CHROME_BALL, ItemDisplayContext.GROUND, packedLight, | ||
OverlayTexture.NO_OVERLAY, poseStack, bufferSource, entity.level(), entity.getId()); | ||
poseStack.popPose(); | ||
super.render(entity, entityYaw, partialTick, poseStack, bufferSource, packedLight); | ||
} | ||
|
||
@Override | ||
protected boolean shouldShowName(@NotNull ChromeLivingEntity entity) { | ||
return entity.getClientClicked() > 0; | ||
} | ||
|
||
@Override | ||
protected void renderNameTag(@NotNull ChromeLivingEntity entity, @NotNull Component displayName, | ||
@NotNull PoseStack poseStack, @NotNull MultiBufferSource bufferSource, | ||
int packedLight, float partialTick) { | ||
double distance = this.entityRenderDispatcher.distanceToSqr(entity); | ||
if (ClientHooks.isNameplateInRenderDistance(entity, distance)) { | ||
Vec3 vec3 = entity.getAttachments().getNullable(EntityAttachment.NAME_TAG, 0, entity.getViewYRot(partialTick)); | ||
if (vec3 != null) { | ||
boolean flag = !entity.isDiscrete(); | ||
poseStack.pushPose(); | ||
poseStack.translate(vec3.x, vec3.y + 2.3, vec3.z); | ||
poseStack.mulPose(this.entityRenderDispatcher.cameraOrientation()); | ||
poseStack.scale(0.025F, -0.025F, 0.025F); | ||
Matrix4f matrix4f = poseStack.last().pose(); | ||
var f = Minecraft.getInstance().options.getBackgroundOpacity(0.25F); | ||
var j = (int)(f * 255.0F) << 24; | ||
var f1 = (float)(-getFont().width(displayName) / 2); | ||
getFont().drawInBatch(displayName, f1, entity.getClientClicked(), 553648127, false, matrix4f, bufferSource, flag ? Font.DisplayMode.SEE_THROUGH : Font.DisplayMode.NORMAL, j, packedLight); | ||
if (flag) { | ||
getFont().drawInBatch(displayName, f1, entity.getClientClicked(), -1, false, matrix4f, bufferSource, Font.DisplayMode.NORMAL, 0, packedLight); | ||
} | ||
poseStack.popPose(); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public @NotNull ResourceLocation getTextureLocation(@NotNull ChromeLivingEntity chromeLivingEntity) { | ||
return ResourceLocation.fromNamespaceAndPath(ChromeBall.MOD_ID, "item/chrome"); | ||
} | ||
} |
45 changes: 37 additions & 8 deletions
45
src/main/java/org/teacon/chromeball/common/ChromeBallRegistry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,78 @@ | ||
package org.teacon.chromeball.common; | ||
|
||
import net.minecraft.MethodsReturnNonnullByDefault; | ||
import net.minecraft.Util; | ||
import net.minecraft.core.registries.BuiltInRegistries; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.stats.Stats; | ||
import net.minecraft.world.entity.EntityType; | ||
import net.minecraft.world.entity.LivingEntity; | ||
import net.minecraft.world.entity.Mob; | ||
import net.minecraft.world.entity.MobCategory; | ||
import net.minecraft.world.entity.ai.attributes.AttributeSupplier; | ||
import net.minecraft.world.entity.ai.attributes.Attributes; | ||
import net.minecraft.world.item.CreativeModeTab; | ||
import net.minecraft.world.item.CreativeModeTabs; | ||
import net.minecraft.world.item.Item; | ||
import net.minecraft.world.item.SpawnEggItem; | ||
import net.neoforged.bus.api.SubscribeEvent; | ||
import net.neoforged.fml.common.EventBusSubscriber; | ||
import net.neoforged.neoforge.common.DeferredSpawnEggItem; | ||
import net.neoforged.neoforge.event.BuildCreativeModeTabContentsEvent; | ||
import net.neoforged.neoforge.event.entity.EntityAttributeCreationEvent; | ||
import net.neoforged.neoforge.registries.DeferredHolder; | ||
import net.neoforged.neoforge.registries.DeferredRegister; | ||
import org.teacon.chromeball.ChromeBall; | ||
import org.teacon.chromeball.common.entity.ChromeLivingEntity; | ||
import org.teacon.chromeball.common.entity.ChromeProjectileEntity; | ||
|
||
import javax.annotation.ParametersAreNonnullByDefault; | ||
|
||
import java.util.function.Supplier; | ||
|
||
import static net.minecraft.resources.ResourceLocation.fromNamespaceAndPath; | ||
|
||
@MethodsReturnNonnullByDefault | ||
@ParametersAreNonnullByDefault | ||
@EventBusSubscriber(modid = ChromeBall.MOD_ID, bus = EventBusSubscriber.Bus.MOD) | ||
public class ChromeBallRegistry { | ||
public static final DeferredRegister<Item> ITEMS; | ||
public static final DeferredRegister<EntityType<?>> ENTITIES; | ||
public static final DeferredRegister<ResourceLocation> CUSTOM_STATS; | ||
|
||
public static final DeferredHolder<Item, ChromeItem> ITEM; | ||
public static final DeferredHolder<EntityType<?>, EntityType<ChromeEntity>> ENTITY_TYPE; | ||
public static final DeferredHolder<Item, ChromeItem> CHROME_BALL_ITEM; | ||
public static final DeferredHolder<EntityType<?>, EntityType<ChromeProjectileEntity>> PROJECTILE_ENTITY_TYPE; | ||
public static final DeferredHolder<EntityType<?>, EntityType<ChromeLivingEntity>> DOOR_CHROME_ENTITY_TYPE; | ||
public static final DeferredHolder<ResourceLocation, ResourceLocation> HITS_BY_STAT; | ||
public static final DeferredHolder<ResourceLocation, ResourceLocation> MERIT_STAT; | ||
|
||
static { | ||
ITEMS = DeferredRegister.create(BuiltInRegistries.ITEM, ChromeBall.MOD_ID); | ||
ENTITIES = DeferredRegister.create(BuiltInRegistries.ENTITY_TYPE, ChromeBall.MOD_ID); | ||
CUSTOM_STATS = DeferredRegister.create(BuiltInRegistries.CUSTOM_STAT, ChromeBall.MOD_ID); | ||
|
||
ITEM = ITEMS.register("chrome", () -> new ChromeItem(new Item.Properties().stacksTo(16))); | ||
ENTITY_TYPE = ENTITIES.register("chrome", () -> EntityType.Builder | ||
.<ChromeEntity>of(ChromeEntity::new, MobCategory.MISC).sized(0.25F, 0.25F).build("chrome")); | ||
CHROME_BALL_ITEM = ITEMS.register("chrome", () -> new ChromeItem(new Item.Properties().stacksTo(16))); | ||
|
||
PROJECTILE_ENTITY_TYPE = ENTITIES.register("chrome", () -> EntityType.Builder | ||
.<ChromeProjectileEntity>of(ChromeProjectileEntity::new, MobCategory.MISC).sized(0.25F, 0.25F).build("chrome")); | ||
|
||
DOOR_CHROME_ENTITY_TYPE = ENTITIES.register("door_chrome", () -> EntityType.Builder | ||
.of(ChromeLivingEntity::new, MobCategory.MISC) | ||
.sized(1, 1.5F) | ||
.nameTagOffset(0) | ||
.build("door_chrome")); | ||
|
||
HITS_BY_STAT = CUSTOM_STATS.register("hits_by", () -> fromNamespaceAndPath(ChromeBall.MOD_ID, "hits_by")); | ||
|
||
MERIT_STAT = CUSTOM_STATS.register("merit", () -> fromNamespaceAndPath(ChromeBall.MOD_ID, "merit")); | ||
} | ||
|
||
public static void registerCreativeTabs(BuildCreativeModeTabContentsEvent event) { | ||
if (CreativeModeTabs.SEARCH.equals(event.getTabKey())) { | ||
event.accept(ChromeBallRegistry.ITEM.get(), CreativeModeTab.TabVisibility.PARENT_AND_SEARCH_TABS); | ||
event.accept(ChromeBallRegistry.CHROME_BALL_ITEM.get(), CreativeModeTab.TabVisibility.PARENT_AND_SEARCH_TABS); | ||
} | ||
} | ||
|
||
@SubscribeEvent | ||
public static void onEntityAttributeCreationEvent(EntityAttributeCreationEvent event) { | ||
event.put(DOOR_CHROME_ENTITY_TYPE.get(), LivingEntity.createLivingAttributes().build()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
src/main/java/org/teacon/chromeball/common/entity/ChromeLivingEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package org.teacon.chromeball.common.entity; | ||
|
||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.server.level.ServerPlayer; | ||
import net.minecraft.world.InteractionHand; | ||
import net.minecraft.world.InteractionResult; | ||
import net.minecraft.world.entity.*; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.level.Level; | ||
import net.neoforged.neoforge.network.PacketDistributor; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.teacon.chromeball.common.ChromeBallRegistry; | ||
import org.teacon.chromeball.network.DingPack; | ||
|
||
import java.util.List; | ||
|
||
public class ChromeLivingEntity extends LivingEntity { | ||
private int clientClicked = 0; | ||
|
||
public ChromeLivingEntity(EntityType<? extends ChromeLivingEntity> entityType, Level level) { | ||
super(entityType, level); | ||
} | ||
|
||
@Override | ||
public @NotNull Iterable<ItemStack> getArmorSlots() { | ||
return List.of(); | ||
} | ||
|
||
@Override | ||
public @NotNull ItemStack getItemBySlot(@NotNull EquipmentSlot equipmentSlot) { | ||
return ItemStack.EMPTY; | ||
} | ||
|
||
@Override | ||
public void setItemSlot(@NotNull EquipmentSlot equipmentSlot, @NotNull ItemStack itemStack) { | ||
} | ||
|
||
@Override | ||
public @NotNull HumanoidArm getMainArm() { | ||
return HumanoidArm.RIGHT; | ||
} | ||
|
||
@Override | ||
public void tick() { | ||
super.tick(); | ||
|
||
if (clientClicked > 0) { | ||
clientClicked -= 1; | ||
} | ||
} | ||
|
||
public int getClientClicked() { | ||
return clientClicked; | ||
} | ||
|
||
@Override | ||
public Component getDisplayName() { | ||
return Component.translatable("chromeball.hint.merit_plus"); | ||
} | ||
|
||
@Override | ||
public @NotNull InteractionResult interact(@NotNull Player player, @NotNull InteractionHand hand) { | ||
if (getClientClicked() == 0) { | ||
clientClicked = 20; | ||
if (!level().isClientSide()) { | ||
player.awardStat(ChromeBallRegistry.MERIT_STAT.get()); | ||
if (player instanceof ServerPlayer serverPlayer) { | ||
PacketDistributor.sendToPlayer(serverPlayer, DingPack.INSTANCE); | ||
} | ||
} | ||
return InteractionResult.SUCCESS; | ||
} | ||
|
||
return super.interact(player, hand); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
{ | ||
"item.chromeball.chrome": "Chrome Ball", | ||
"entity.chromeball.chrome": "Chrome Ball", | ||
"stat.chromeball.hits_by": "Hits by Chrome Ball" | ||
"entity.chromeball.door_chrome": "Door God Chrome Ball", | ||
"stat.chromeball.hits_by": "Hits by Chrome Ball", | ||
"stat.chromeball.merit": "Merits", | ||
"chromeball.hint.merit_plus": "Merits +1" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
{ | ||
"item.chromeball.chrome": "土球", | ||
"entity.chromeball.chrome": "土球", | ||
"stat.chromeball.hits_by": "被土球击中次数" | ||
"entity.chromeball.door_chrome": "门神土球", | ||
"stat.chromeball.hits_by": "被土球击中次数", | ||
"stat.chromeball.merit": "功德", | ||
"chromeball.hint.merit_plus": "功德 +1" | ||
} |