Fix pipe model and fluid interaction

- Fix pipes with 5 or 6 connections not rendering
  - Fix PipeAttachmentModel#getRenderTypes returning an empty set for
these block states
- Fix honey and chocolate lava interactions
  - Use FluidInteractionRegistry instead of FluidPlaceBlockEvent
This commit is contained in:
PepperCode1 2022-11-23 18:52:39 -08:00
parent f12701ccc4
commit 73491d8e77
4 changed files with 48 additions and 33 deletions

View file

@ -16,10 +16,14 @@ import com.tterrag.registrate.util.entry.FluidEntry;
import net.minecraft.core.BlockPos;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.BlockAndTintGetter;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Fluid;
import net.minecraft.world.level.material.FluidState;
import net.minecraftforge.client.extensions.common.IClientFluidTypeExtensions;
import net.minecraftforge.common.ForgeMod;
import net.minecraftforge.fluids.FluidInteractionRegistry;
import net.minecraftforge.fluids.FluidInteractionRegistry.InteractionInformation;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidType;
import net.minecraftforge.fluids.ForgeFlowingFluid;
@ -68,6 +72,34 @@ public class AllFluids {
public static void register() {}
public static void registerFluidInteractions() {
FluidInteractionRegistry.addInteraction(ForgeMod.LAVA_TYPE.get(), new InteractionInformation(
HONEY.get().getFluidType(),
fluidState -> {
if (fluidState.isSource()) {
return Blocks.OBSIDIAN.defaultBlockState();
} else {
return AllPaletteStoneTypes.LIMESTONE.getBaseBlock()
.get()
.defaultBlockState();
}
}
));
FluidInteractionRegistry.addInteraction(ForgeMod.LAVA_TYPE.get(), new InteractionInformation(
CHOCOLATE.get().getFluidType(),
fluidState -> {
if (fluidState.isSource()) {
return Blocks.OBSIDIAN.defaultBlockState();
} else {
return AllPaletteStoneTypes.SCORIA.getBaseBlock()
.get()
.defaultBlockState();
}
}
));
}
@Nullable
public static BlockState getLavaInteraction(FluidState fluidState) {
Fluid fluid = fluidState.getType();

View file

@ -44,7 +44,6 @@ import com.simibubi.create.foundation.worldgen.BuiltinRegistration;
import net.minecraft.data.DataGenerator;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.RandomSource;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.level.Level;
@ -151,6 +150,7 @@ public class Create {
AllAdvancements.register();
AllTriggers.register();
BoilerHeaters.registerDefaults();
AllFluids.registerFluidInteractions();
});
}

View file

@ -4,6 +4,8 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.jetbrains.annotations.NotNull;
import com.simibubi.create.AllBlockPartials;
import com.simibubi.create.content.contraptions.fluids.FluidTransportBehaviour.AttachmentTypes;
import com.simibubi.create.content.contraptions.fluids.FluidTransportBehaviour.AttachmentTypes.ComponentPartials;
@ -14,6 +16,7 @@ import com.simibubi.create.foundation.tileEntity.TileEntityBehaviour;
import com.simibubi.create.foundation.utility.Iterate;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.ItemBlockRenderTypes;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.resources.model.BakedModel;
@ -22,6 +25,7 @@ import net.minecraft.core.Direction;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.BlockAndTintGetter;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraftforge.client.ChunkRenderTypeSet;
import net.minecraftforge.client.model.data.ModelData;
import net.minecraftforge.client.model.data.ModelData.Builder;
import net.minecraftforge.client.model.data.ModelProperty;
@ -50,6 +54,17 @@ public class PipeAttachmentModel extends BakedModelWrapperWithData {
return builder.with(PIPE_PROPERTY, data);
}
// TODO: Update once MinecraftForge#9163 is merged
@SuppressWarnings("removal")
@Override
public ChunkRenderTypeSet getRenderTypes(@NotNull BlockState state, @NotNull RandomSource rand, @NotNull ModelData data) {
ChunkRenderTypeSet set = super.getRenderTypes(state, rand, data);
if (set.isEmpty()) {
return ItemBlockRenderTypes.getRenderLayers(state);
}
return set;
}
@Override
public List<BakedQuad> getQuads(BlockState state, Direction side, RandomSource rand, ModelData data, RenderType renderType) {
List<BakedQuad> quads = super.getQuads(state, side, rand, data, renderType);

View file

@ -1,6 +1,5 @@
package com.simibubi.create.events;
import com.simibubi.create.AllFluids;
import com.simibubi.create.Create;
import com.simibubi.create.content.contraptions.components.structureMovement.ContraptionHandler;
import com.simibubi.create.content.contraptions.components.structureMovement.interaction.controls.ControlsServerHandler;
@ -15,27 +14,20 @@ import com.simibubi.create.content.logistics.item.LinkedControllerServerHandler;
import com.simibubi.create.content.logistics.trains.entity.CarriageEntityHandler;
import com.simibubi.create.foundation.ModFilePackResources;
import com.simibubi.create.foundation.command.AllCommands;
import com.simibubi.create.foundation.fluid.FluidHelper;
import com.simibubi.create.foundation.utility.Iterate;
import com.simibubi.create.foundation.utility.ServerSpeedProvider;
import com.simibubi.create.foundation.utility.WorldAttached;
import com.simibubi.create.foundation.utility.recipe.RecipeFinder;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.packs.PackType;
import net.minecraft.server.packs.repository.Pack;
import net.minecraft.server.packs.repository.PackSource;
import net.minecraft.tags.FluidTags;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.FluidState;
import net.minecraftforge.common.capabilities.RegisterCapabilitiesEvent;
import net.minecraftforge.event.AddPackFindersEvent;
import net.minecraftforge.event.AddReloadListenerEvent;
@ -52,7 +44,6 @@ import net.minecraftforge.event.entity.player.AttackEntityEvent;
import net.minecraftforge.event.entity.player.PlayerEvent;
import net.minecraftforge.event.entity.player.PlayerEvent.PlayerLoggedInEvent;
import net.minecraftforge.event.entity.player.PlayerEvent.PlayerLoggedOutEvent;
import net.minecraftforge.event.level.BlockEvent.FluidPlaceBlockEvent;
import net.minecraftforge.event.level.ChunkEvent;
import net.minecraftforge.event.level.LevelEvent;
import net.minecraftforge.event.server.ServerStoppingEvent;
@ -93,29 +84,6 @@ public class CommonEvents {
Create.RAILWAYS.playerLogout(player);
}
@SubscribeEvent
public static void whenFluidsMeet(FluidPlaceBlockEvent event) {
BlockState blockState = event.getOriginalState();
FluidState fluidState = blockState.getFluidState();
BlockPos pos = event.getPos();
LevelAccessor world = event.getLevel();
if (fluidState.isSource() && FluidHelper.isLava(fluidState.getType()))
return;
for (Direction direction : Iterate.directions) {
FluidState metFluidState =
fluidState.isSource() ? fluidState : world.getFluidState(pos.relative(direction));
if (!metFluidState.is(FluidTags.WATER))
continue;
BlockState lavaInteraction = AllFluids.getLavaInteraction(metFluidState);
if (lavaInteraction == null)
continue;
event.setNewState(lavaInteraction);
break;
}
}
@SubscribeEvent
public static void onWorldTick(LevelTickEvent event) {
if (event.phase == Phase.START)