Skip to content

Commit

Permalink
Tweaks to handle new Forge breaking changes
Browse files Browse the repository at this point in the history
  • Loading branch information
rubensworks committed Jul 17, 2022
1 parent 56f2b25 commit 4c2f5a2
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.cyclops.cyclopscore.client.model;

import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.resources.model.BakedModel;
import net.minecraft.core.Direction;
import net.minecraft.util.RandomSource;
Expand All @@ -23,8 +24,8 @@ public DelegatingChildDynamicItemAndBlockModel(BakedModel baseModel) {
}

public DelegatingChildDynamicItemAndBlockModel(BakedModel baseModel, BlockState blockState, Direction facing,
RandomSource rand, ModelData modelData) {
super(blockState, facing, rand, modelData);
RandomSource rand, ModelData modelData, RenderType renderType) {
super(blockState, facing, rand, modelData, renderType);
this.baseModel = baseModel;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.cyclops.cyclopscore.client.model;

import net.minecraft.client.renderer.RenderType;
import net.minecraft.core.Direction;
import net.minecraft.util.RandomSource;
import net.minecraft.world.entity.LivingEntity;
Expand All @@ -22,6 +23,7 @@ public abstract class DelegatingDynamicItemAndBlockModel extends DynamicItemAndB
protected final Direction facing;
protected final RandomSource rand;
protected final ModelData modelData;
protected final RenderType renderType;

protected final ItemStack itemStack;
protected final Level world;
Expand All @@ -32,19 +34,21 @@ public DelegatingDynamicItemAndBlockModel() {
this.blockState = null;
this.facing = null;
this.rand = RandomSource.create();
this.modelData = ModelData.builder().build();
this.modelData = ModelData.EMPTY;
this.renderType = RenderType.cutout();

this.itemStack = null;
this.world = null;
this.entity = null;
}

public DelegatingDynamicItemAndBlockModel(BlockState blockState, Direction facing, RandomSource rand, ModelData modelData) {
public DelegatingDynamicItemAndBlockModel(BlockState blockState, Direction facing, RandomSource rand, ModelData modelData, RenderType renderType) {
super(false, false);
this.blockState = blockState;
this.facing = facing;
this.rand = rand;
this.modelData = modelData;
this.renderType = renderType;

this.itemStack = null;
this.world = null;
Expand All @@ -56,7 +60,8 @@ public DelegatingDynamicItemAndBlockModel(ItemStack itemStack, Level world, Livi
this.blockState = null;
this.facing = null;
this.rand = RandomSource.create();
this.modelData = ModelData.builder().build();
this.modelData = ModelData.EMPTY;
this.renderType = RenderType.cutout();

this.itemStack = itemStack;
this.world = world;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,20 @@ protected boolean isItemStack() {

@Override
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, RandomSource rand) {
return this.getQuads(state, side, rand, ModelData.builder().build(), RenderType.cutout());
return this.getQuads(state, side, rand, ModelData.EMPTY, RenderType.cutout());
}

@Override
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side,
@Nonnull RandomSource rand, @Nonnull ModelData extraData,
RenderType renderType) {
@Nullable RenderType renderType) {
this.renderingSide = side;
if(factory) {
BakedModel bakedModel;
if(isItemStack()) {
bakedModel = handleItemState(null, null, null);
} else {
bakedModel = handleBlockState(state, side, rand, extraData);
bakedModel = handleBlockState(state, side, rand, extraData, renderType);
}
if (bakedModel != null) {
return bakedModel.getQuads(state, side, rand);
Expand All @@ -69,7 +69,8 @@ public List<BakedQuad> getGeneralQuads() {
}

public abstract BakedModel handleBlockState(@Nullable BlockState state, @Nullable Direction side,
@Nonnull RandomSource rand, @Nonnull ModelData extraData);
@Nonnull RandomSource rand, @Nonnull ModelData extraData,
@Nullable RenderType renderType);
public abstract BakedModel handleItemState(@Nullable ItemStack stack, @Nullable Level world,
@Nullable LivingEntity entity);

Expand Down
10 changes: 9 additions & 1 deletion src/main/java/org/cyclops/cyclopscore/init/ModBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import net.minecraft.world.item.CreativeModeTab;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.client.event.RegisterKeyMappingsEvent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.server.ServerAboutToStartEvent;
import net.minecraftforge.event.server.ServerStartedEvent;
Expand Down Expand Up @@ -96,6 +97,7 @@ public ModBase(String modId, Consumer<T> instanceSetter) {
DistExecutor.runWhenOn(Dist.CLIENT, () -> () -> FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setupClient));
FMLJavaModLoadingContext.get().getModEventBus().addListener(EventPriority.LOWEST, this::afterRegistriesCreated);
FMLJavaModLoadingContext.get().getModEventBus().addListener(EventPriority.HIGHEST, this::beforeRegistriedFilled);
FMLJavaModLoadingContext.get().getModEventBus().addListener(this::onRegisterKeyMappings);
MinecraftForge.EVENT_BUS.register(this);

// Register proxies
Expand Down Expand Up @@ -263,7 +265,13 @@ protected void setupClient(FMLClientSetupEvent event) {
ICommonProxy proxy = getProxy();
if(proxy != null) {
proxy.registerRenderers();
proxy.registerKeyBindings(getKeyRegistry());
}
}

protected void onRegisterKeyMappings(RegisterKeyMappingsEvent event) {
ICommonProxy proxy = getProxy();
if(proxy != null) {
proxy.registerKeyBindings(getKeyRegistry(), event);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.minecraft.client.renderer.blockentity.BlockEntityRenderers;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraftforge.client.event.RegisterKeyMappingsEvent;
import net.minecraftforge.common.MinecraftForge;
import org.apache.logging.log4j.Level;
import org.cyclops.cyclopscore.client.icon.IconProvider;
Expand Down Expand Up @@ -53,7 +54,7 @@ public void registerRenderers() {
}

@Override
public void registerKeyBindings(IKeyRegistry keyRegistry) {
public void registerKeyBindings(IKeyRegistry keyRegistry, RegisterKeyMappingsEvent event) {
getMod().getLoggerHelper().log(Level.TRACE, "Registered key bindings");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraftforge.client.event.RegisterKeyMappingsEvent;
import net.minecraftforge.common.MinecraftForge;
import org.cyclops.cyclopscore.client.key.IKeyRegistry;
import org.cyclops.cyclopscore.event.PlayerRingOfFire;
Expand All @@ -26,7 +27,7 @@ public void registerRenderers() {
}

@Override
public void registerKeyBindings(IKeyRegistry keyRegistry) {
public void registerKeyBindings(IKeyRegistry keyRegistry, RegisterKeyMappingsEvent event) {
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraftforge.client.event.RegisterKeyMappingsEvent;
import org.cyclops.cyclopscore.client.key.IKeyRegistry;
import org.cyclops.cyclopscore.init.ModBase;
import org.cyclops.cyclopscore.network.PacketHandler;
Expand Down Expand Up @@ -35,8 +36,9 @@ public interface ICommonProxy {
/**
* Register key bindings.
* @param keyRegistry The key registry to register to.
* @param event Register mappings event
*/
public void registerKeyBindings(IKeyRegistry keyRegistry);
public void registerKeyBindings(IKeyRegistry keyRegistry, RegisterKeyMappingsEvent event);

/**
* Register packet handlers.
Expand Down

0 comments on commit 4c2f5a2

Please sign in to comment.