Skip to content

Commit

Permalink
update to 1.19.3
Browse files Browse the repository at this point in the history
  • Loading branch information
jihuayu committed Jan 7, 2023
1 parent ff7c23c commit 7d21d39
Show file tree
Hide file tree
Showing 15 changed files with 136 additions and 148 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ teacon {
modAuthors = ['BloCamLimb', '3TUSK', 'ustc-zzzz']
modDescription = 'Minecraft mod, adding a projector that can display online images.'

platform = 'forge-1.18.2-40.1.0'
parchment = '2022.03.13'
platform = 'forge-1.19.3-44.1.0'
parchment = '2022.12.18'

// uncomment these lines if you need
modName = 'Slide Show' // default to repo name
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
28 changes: 19 additions & 9 deletions src/main/java/org/teacon/slides/Registries.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
package org.teacon.slides;

import com.mojang.datafixers.DSL;
import net.minecraft.world.inventory.MenuType;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraftforge.registries.ObjectHolder;
import net.minecraftforge.common.extensions.IForgeMenuType;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;
import org.teacon.slides.projector.ProjectorBlock;
import org.teacon.slides.projector.ProjectorBlockEntity;
import org.teacon.slides.projector.ProjectorContainerMenu;
import org.teacon.slides.projector.ProjectorItem;

@ObjectHolder(SlideShow.ID)
public final class Registries {
import java.util.Set;

@ObjectHolder("projector")
public static Block PROJECTOR;
public final class Registries {
public static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, SlideShow.ID);
public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, SlideShow.ID);
public static final DeferredRegister<MenuType<?>> MENU_TYPES = DeferredRegister.create(ForgeRegistries.MENU_TYPES, SlideShow.ID);
public static final DeferredRegister<BlockEntityType<?>> BLOCK_ENTITY_TYPES = DeferredRegister.create(ForgeRegistries.BLOCK_ENTITY_TYPES, SlideShow.ID);
public static RegistryObject<ProjectorBlock> PROJECTOR = BLOCKS.register("projector", ProjectorBlock::new);
public static RegistryObject<ProjectorItem> PROJECTOR_ITEM = ITEMS.register("projector", ProjectorItem::new);
public static RegistryObject<MenuType<ProjectorContainerMenu>> MENU = MENU_TYPES.register("projector", ()->IForgeMenuType.create(ProjectorContainerMenu::new));

@ObjectHolder("projector")
public static BlockEntityType<ProjectorBlockEntity> BLOCK_ENTITY;
public static RegistryObject<BlockEntityType<ProjectorBlockEntity>> BLOCK_ENTITY = BLOCK_ENTITY_TYPES.register("projector",
()-> new BlockEntityType<>(ProjectorBlockEntity::new, Set.of(Registries.PROJECTOR.get()), DSL.remainderType()));

@ObjectHolder("projector")
public static MenuType<ProjectorContainerMenu> MENU;
}
53 changes: 13 additions & 40 deletions src/main/java/org/teacon/slides/SlideShow.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
package org.teacon.slides;

import com.mojang.datafixers.DSL;
import net.minecraft.client.gui.screens.MenuScreens;
import net.minecraft.client.renderer.ItemBlockRenderTypes;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderers;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.inventory.MenuType;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.item.CreativeModeTabs;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.client.event.ModelRegistryEvent;
import net.minecraftforge.client.event.RegisterShadersEvent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.extensions.IForgeMenuType;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.event.CreativeModeTabEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
Expand All @@ -35,7 +27,7 @@

import javax.annotation.ParametersAreNonnullByDefault;
import java.util.Optional;
import java.util.Set;


@Mod(SlideShow.ID)
@ParametersAreNonnullByDefault
Expand Down Expand Up @@ -67,29 +59,10 @@ public final class SlideShow {
public SlideShow() {
FMLJavaModLoadingContext.get().getModEventBus().register(SlideShow.class);
MinecraftForge.EVENT_BUS.addListener(SlideShow::gatherPermNodes);
}

@SubscribeEvent
public static void registerBlocks(final RegistryEvent.Register<Block> event) {
event.getRegistry().register(new ProjectorBlock().setRegistryName("projector"));
}

@SubscribeEvent
public static void registerItems(final RegistryEvent.Register<Item> event) {
event.getRegistry().register(new ProjectorItem().setRegistryName("projector"));
}

@SubscribeEvent
public static void registerMenus(final RegistryEvent.Register<MenuType<?>> event) {
event.getRegistry().register(IForgeMenuType.create(ProjectorContainerMenu::new)
.setRegistryName("projector"));
}

@SubscribeEvent
public static void registerBlockEntities(final RegistryEvent.Register<BlockEntityType<?>> event) {
event.getRegistry().register(new BlockEntityType<>(ProjectorBlockEntity::new,
Set.of(Registries.PROJECTOR), DSL.remainderType())
.setRegistryName("projector"));
Registries.BLOCKS.register(FMLJavaModLoadingContext.get().getModEventBus());
Registries.ITEMS.register(FMLJavaModLoadingContext.get().getModEventBus());
Registries.MENU_TYPES.register(FMLJavaModLoadingContext.get().getModEventBus());
Registries.BLOCK_ENTITY_TYPES.register(FMLJavaModLoadingContext.get().getModEventBus());
}

//FIXME permission resolving
Expand Down Expand Up @@ -117,15 +90,15 @@ public static void setupCommon(final FMLCommonSetupEvent event) {
@OnlyIn(Dist.CLIENT)
@SubscribeEvent
public static void setupClient(final FMLClientSetupEvent event) {
MenuScreens.register(Registries.MENU, ProjectorScreen::new);
ItemBlockRenderTypes.setRenderLayer(Registries.PROJECTOR, RenderType.cutout());
BlockEntityRenderers.register(Registries.BLOCK_ENTITY, ProjectorRenderer.INSTANCE::onCreate);
MenuScreens.register(Registries.MENU.get(), ProjectorScreen::new);
BlockEntityRenderers.register(Registries.BLOCK_ENTITY.get(), ProjectorRenderer.INSTANCE::onCreate);
}

@OnlyIn(Dist.CLIENT)
@SubscribeEvent
public static void onModelRegistry(final ModelRegistryEvent event) {
//RenderSystem.recordRenderCall(ProjectorWorldRender::loadShader);
public static void onBuildContents(final CreativeModeTabEvent.BuildContents event) {
if (event.getTab() == CreativeModeTabs.FUNCTIONAL_BLOCKS){
event.accept(Registries.PROJECTOR_ITEM);
}
}

@OnlyIn(Dist.CLIENT)
Expand Down
30 changes: 15 additions & 15 deletions src/main/java/org/teacon/slides/projector/ProjectorBlock.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package org.teacon.slides.projector;

import com.mojang.math.Matrix3f;
import com.mojang.math.Matrix4f;
import com.mojang.math.Vector4f;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.util.StringRepresentable;
Expand All @@ -24,6 +21,9 @@
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.joml.Matrix3f;
import org.joml.Matrix4f;
import org.joml.Vector4f;

import javax.annotation.Nonnull;
import javax.annotation.ParametersAreNonnullByDefault;
Expand Down Expand Up @@ -152,14 +152,14 @@ public InteractionResult use(BlockState state, Level level, BlockPos pos, Player
}

public enum InternalRotation implements StringRepresentable {
NONE(new float[]{1F, 0F, 0F, 0F, 0F, 1F, 0F, 0F, 0F, 0F, 1F, 0F, 0F, 0F, 0F, 1F}),
CLOCKWISE_90(new float[]{0F, 0F, -1F, 0F, 0F, 1F, 0F, 0F, 1F, 0F, 0F, 0F, 0F, 0F, 0F, 1F}),
CLOCKWISE_180(new float[]{-1F, 0F, 0F, 0F, 0F, 1F, 0F, 0F, 0F, 0F, -1F, 0F, 0F, 0F, 0F, 1F}),
COUNTERCLOCKWISE_90(new float[]{0F, 0F, 1F, 0F, 0F, 1F, 0F, 0F, -1F, 0F, 0F, 0F, 0F, 0F, 0F, 1F}),
HORIZONTAL_FLIPPED(new float[]{-1F, 0F, 0F, 0F, 0F, -1F, 0F, 0F, 0F, 0F, 1F, 0F, 0F, 0F, 0F, 1F}),
DIAGONAL_FLIPPED(new float[]{0F, 0F, -1F, 0F, 0F, -1F, 0F, 0F, -1F, 0F, 0F, 0F, 0F, 0F, 0F, 1F}),
VERTICAL_FLIPPED(new float[]{1F, 0F, 0F, 0F, 0F, -1F, 0F, 0F, 0F, 0F, -1F, 0F, 0F, 0F, 0F, 1F}),
ANTI_DIAGONAL_FLIPPED(new float[]{0F, 0F, 1F, 0F, 0F, -1F, 0F, 0F, 1F, 0F, 0F, 0F, 0F, 0F, 0F, 1F});
NONE(new Matrix4f(1F, 0F, 0F, 0F, 0F, 1F, 0F, 0F, 0F, 0F, 1F, 0F, 0F, 0F, 0F, 1F)),
CLOCKWISE_90(new Matrix4f(0F, 0F, -1F, 0F, 0F, 1F, 0F, 0F, 1F, 0F, 0F, 0F, 0F, 0F, 0F, 1F)),
CLOCKWISE_180(new Matrix4f(-1F, 0F, 0F, 0F, 0F, 1F, 0F, 0F, 0F, 0F, -1F, 0F, 0F, 0F, 0F, 1F)),
COUNTERCLOCKWISE_90(new Matrix4f(0F, 0F, 1F, 0F, 0F, 1F, 0F, 0F, -1F, 0F, 0F, 0F, 0F, 0F, 0F, 1F)),
HORIZONTAL_FLIPPED(new Matrix4f(-1F, 0F, 0F, 0F, 0F, -1F, 0F, 0F, 0F, 0F, 1F, 0F, 0F, 0F, 0F, 1F)),
DIAGONAL_FLIPPED(new Matrix4f(0F, 0F, -1F, 0F, 0F, -1F, 0F, 0F, -1F, 0F, 0F, 0F, 0F, 0F, 0F, 1F)),
VERTICAL_FLIPPED(new Matrix4f(1F, 0F, 0F, 0F, 0F, -1F, 0F, 0F, 0F, 0F, -1F, 0F, 0F, 0F, 0F, 1F)),
ANTI_DIAGONAL_FLIPPED(new Matrix4f(0F, 0F, 1F, 0F, 0F, -1F, 0F, 0F, 1F, 0F, 0F, 0F, 0F, 0F, 0F, 1F));

public static final InternalRotation[] VALUES = values();

Expand All @@ -177,9 +177,9 @@ public enum InternalRotation implements StringRepresentable {
private final Matrix4f mMatrix;
private final Matrix3f mNormal;

InternalRotation(float[] matrix) {
InternalRotation(Matrix4f matrix) {
mSerializedName = name().toLowerCase(Locale.ROOT);
mMatrix = new Matrix4f(matrix);
mMatrix = matrix;
mNormal = new Matrix3f(mMatrix);
}

Expand All @@ -200,11 +200,11 @@ public boolean isFlipped() {
}

public void transform(Vector4f vector) {
vector.transform(mMatrix);
mMatrix.transform(vector);
}

public void transform(Matrix4f poseMatrix) {
poseMatrix.multiply(mMatrix);
poseMatrix.mul(mMatrix);
}

public void transform(Matrix3f normalMatrix) {
Expand Down
44 changes: 24 additions & 20 deletions src/main/java/org/teacon/slides/projector/ProjectorBlockEntity.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
package org.teacon.slides.projector;

import com.mojang.math.Matrix3f;
import com.mojang.math.Matrix4f;
import com.mojang.math.Vector3f;
import com.mojang.math.Vector4f;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.Connection;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.MenuProvider;
Expand All @@ -21,6 +16,10 @@
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.phys.AABB;
import net.minecraftforge.network.NetworkHooks;
import org.joml.Matrix3f;
import org.joml.Matrix4f;
import org.joml.Vector3f;
import org.joml.Vector4f;
import org.teacon.slides.Registries;
import org.teacon.slides.renderer.ProjectorWorldRender;

Expand All @@ -31,7 +30,7 @@
@ParametersAreNonnullByDefault
public final class ProjectorBlockEntity extends BlockEntity implements MenuProvider {

private static final Component TITLE = new TranslatableComponent("gui.slide_show.title");
private static final Component TITLE = Component.translatable("gui.slide_show.title");

public String mLocation = "";
public int mColor = ~0;
Expand All @@ -43,11 +42,11 @@ public final class ProjectorBlockEntity extends BlockEntity implements MenuProvi
public boolean mDoubleSided = true;

public ProjectorBlockEntity(BlockPos blockPos, BlockState blockState) {
super(Registries.BLOCK_ENTITY, blockPos, blockState);
super(Registries.BLOCK_ENTITY.get(), blockPos, blockState);
}

public void openGui(BlockPos pos, Player player) {
NetworkHooks.openGui((ServerPlayer) player, this, buf -> {
NetworkHooks.openScreen((ServerPlayer) player, this, buf -> {
buf.writeBlockPos(pos);
CompoundTag tag = new CompoundTag();
writeCustomTag(tag);
Expand Down Expand Up @@ -150,16 +149,16 @@ public void handleUpdateTag(CompoundTag tag) {

@Override
public AABB getRenderBoundingBox() {
Matrix3f normal = Matrix3f.createScaleMatrix(1, 1, 1); // identity
Matrix4f pose = Matrix4f.createScaleMatrix(1, 1, 1); // identity
Matrix3f normal = new Matrix3f(); // identity
Matrix4f pose = new Matrix4f(); // identity
this.transformToSlideSpace(pose, normal);

Vector3f nHalf = new Vector3f(0, 0.5f, 0);
Vector4f v00 = new Vector4f(0, 0, 0, 1);
Vector4f v01 = new Vector4f(1, 0, 1, 1);
nHalf.transform(normal);
v00.transform(pose);
v01.transform(pose);
nHalf.mul(normal);
v00.mul(pose);
v01.mul(pose);

AABB base = new AABB(v00.x(), v00.y(), v00.z(), v01.x(), v01.y(), v01.z());
return base.move(this.getBlockPos()).inflate(nHalf.x(), nHalf.y(), nHalf.z());
Expand All @@ -172,20 +171,25 @@ public void transformToSlideSpace(Matrix4f pose, Matrix3f normal) {
// get internal rotation
ProjectorBlock.InternalRotation rotation = state.getValue(ProjectorBlock.ROTATION);
// matrix 1: translation to block center
pose.multiplyWithTranslation(0.5f, 0.5f, 0.5f);
pose.translate(0.5f, 0.5f, 0.5f);
// matrix 2: rotation
pose.multiply(direction.getRotation());
normal.mul(direction.getRotation());
pose.rotate(direction.getRotation());
direction.getRotation().setFromNormalized(normal);
// matrix 3: translation to block surface
pose.multiplyWithTranslation(0.0f, 0.5f, 0.0f);
pose.translate(0.0f, 0.5f, 0.0f);
// matrix 4: internal rotation
rotation.transform(pose);
rotation.transform(normal);
// matrix 5: translation for slide
pose.multiplyWithTranslation(-0.5F, 0.0F, 0.5F - mHeight);
pose.translate(-0.5F, 0.0F, 0.5F - mHeight);
// matrix 6: offset for slide
pose.multiplyWithTranslation(mOffsetX, -mOffsetZ, mOffsetY);
pose.translate( mOffsetX, -mOffsetZ, mOffsetY);
// matrix 7: scaling
pose.multiply(Matrix4f.createScaleMatrix(mWidth, 1.0F, mHeight));
Matrix4f mat4 = new Matrix4f();
mat4.m00(mWidth);
mat4.m11(1.0F);
mat4.m22(mHeight);
mat4.m33(1.0F);
pose.mul(mat4);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.server.permission.PermissionAPI;
import org.jetbrains.annotations.NotNull;
import org.teacon.slides.Registries;
import org.teacon.slides.SlideShow;

Expand All @@ -19,19 +21,24 @@ public final class ProjectorContainerMenu extends AbstractContainerMenu {
ProjectorBlockEntity mEntity;

public ProjectorContainerMenu(int containerId, ProjectorBlockEntity entity) {
super(Registries.MENU, containerId);
super(Registries.MENU.get(), containerId);
mEntity = entity;
}

public ProjectorContainerMenu(int containerId, Inventory inventory, FriendlyByteBuf buf) {
super(Registries.MENU, containerId);
super(Registries.MENU.get(), containerId);
if (inventory.player.level.getBlockEntity(buf.readBlockPos()) instanceof ProjectorBlockEntity t) {
CompoundTag tag = Objects.requireNonNull(buf.readNbt());
t.readCustomTag(tag);
mEntity = t;
}
}

@Override
public @NotNull ItemStack quickMoveStack(Player pPlayer, int pIndex) {
return ItemStack.EMPTY;
}

@Override
public boolean stillValid(Player player) {
return mEntity.getLevel() == player.getLevel() &&
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/teacon/slides/projector/ProjectorItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
public final class ProjectorItem extends BlockItem {

public ProjectorItem() {
super(Registries.PROJECTOR, new Item.Properties()
.tab(CreativeModeTab.TAB_MISC)
super(Registries.PROJECTOR.get(), new Item.Properties()
.rarity(Rarity.RARE));
}

Expand Down
Loading

0 comments on commit 7d21d39

Please sign in to comment.