New hook for better custom scaffolding movement (#7261)

This commit is contained in:
ChampionAsh5357 2020-09-08 17:00:09 -04:00 committed by GitHub
parent f68344cd7c
commit 15733a18e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 132 additions and 1 deletions

View File

@ -351,6 +351,7 @@ project(':forge') {
'--mod', 'data_gen_test',
'--mod', 'piston_event_test',
'--mod', 'global_loot_test',
'--mod', 'scaffolding_test',
'--output', rootProject.file('src/generated_test/resources/'),
'--existing', sourceSets.main.resources.srcDirs[0]
}

View File

@ -343,6 +343,15 @@
float f4 = this.field_70122_E ? f3 * 0.91F : 0.91F;
Vector3d vector3d5 = this.func_233633_a_(p_213352_1_, f3);
double d2 = vector3d5.field_72448_b;
@@ -2049,7 +2081,7 @@
double d0 = MathHelper.func_151237_a(p_213362_1_.field_72450_a, (double)-0.15F, (double)0.15F);
double d1 = MathHelper.func_151237_a(p_213362_1_.field_72449_c, (double)-0.15F, (double)0.15F);
double d2 = Math.max(p_213362_1_.field_72448_b, (double)-0.15F);
- if (d2 < 0.0D && !this.func_213339_cH().func_203425_a(Blocks.field_222420_lI) && this.func_230491_ea_() && this instanceof PlayerEntity) {
+ if (d2 < 0.0D && !this.func_213339_cH().isScaffolding(this) && this.func_230491_ea_() && this instanceof PlayerEntity) {
d2 = 0.0D;
}
@@ -2077,6 +2109,7 @@
}

View File

@ -66,6 +66,7 @@ a012d6d92bab1c91913bd0f2dc0492a0fce916f2 assets/minecraft/blockstates/wall_torch
273e0ed992d227f09f1c83bc22d066fb68d03c84 assets/piston_event_test/blockstates/shiftonmove.json
d2c8e860521c5e738ed0798337f5728d610825ff assets/piston_event_test/models/block/shiftonmove.json
f51f026a75e27a0a53a76771d553c0e3385a2966 assets/piston_event_test/models/item/shiftonmove.json
cf16f861eaf5815238c2278eb48bde0688cb73b7 assets/scaffolding_test/blockstates/scaffolding_method_test.json
4fbaf6f4a3ea05cc071076e27f44ac81f9cc50e3 data/data_gen_test/advancements/conditional.json
ed4cbf1a3a2f5d8969f6346fdc9acdbe81d0c919 data/data_gen_test/recipes/conditional.json
40208299608468b044f64317995f9182ec219d90 data/data_gen_test/tags/blocks/test.json

View File

@ -0,0 +1,10 @@
{
"variants": {
"bottom=false": {
"model": "minecraft:block/scaffolding_stable"
},
"bottom=true": {
"model": "minecraft:block/scaffolding_unstable"
}
}
}

View File

@ -911,4 +911,18 @@ public interface IForgeBlock
else if(toolType == ToolType.HOE) return HoeItem.getHoeTillingState(state);
else return toolType == ToolType.SHOVEL ? ShovelItem.getShovelPathingState(state) : null;
}
/**
* Checks if a player or entity handles movement on this block like scaffolding.
*
* @param state The current state
* @param world The current world
* @param pos The block position in world
* @param entity The entity on the scaffolding
* @return True if the block should act like scaffolding
*/
default boolean isScaffolding(BlockState state, IWorldReader world, BlockPos pos, LivingEntity entity)
{
return state.isIn(Blocks.SCAFFOLDING);
}
}

View File

@ -798,4 +798,15 @@ public interface IForgeBlockState
BlockState eventState = net.minecraftforge.event.ForgeEventFactory.onToolUse(getBlockState(), world, pos, player, stack, toolType);
return eventState != getBlockState() ? eventState : getBlockState().getBlock().getToolModifiedState(getBlockState(), world, pos, player, stack, toolType);
}
/**
* Checks if a player or entity handles movement on this block like scaffolding.
*
* @param entity The entity on the scaffolding
* @return True if the block should act like scaffolding
*/
default boolean isScaffolding(LivingEntity entity)
{
return getBlockState().getBlock().isScaffolding(getBlockState(), entity.world, entity.func_233580_cy_(), entity);
}
}

View File

@ -0,0 +1,83 @@
package net.minecraftforge.debug.block;
import net.minecraft.block.AbstractBlock;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.ScaffoldingBlock;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.block.material.MaterialColor;
import net.minecraft.data.DataGenerator;
import net.minecraft.entity.LivingEntity;
import net.minecraft.tags.BlockTags;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IWorldReader;
import net.minecraftforge.client.model.generators.BlockStateProvider;
import net.minecraftforge.client.model.generators.ConfiguredModel;
import net.minecraftforge.client.model.generators.ModelFile;
import net.minecraftforge.common.Tags.IOptionalNamedTag;
import net.minecraftforge.common.data.ExistingFileHelper;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.RegistryObject;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.GatherDataEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
/**
* This test mod allows a custom scaffolding to move down
* while sneaking through a method.
*/
@Mod(ScaffoldingTest.MODID)
public class ScaffoldingTest
{
static final String MODID = "scaffolding_test";
static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, MODID);
static final IOptionalNamedTag<Block> SCAFFOLDING = BlockTags.createOptional(new ResourceLocation("forge", "scaffolding"));
static final RegistryObject<Block> SCAFFOLDING_METHOD_TEST = BLOCKS.register("scaffolding_method_test", () -> new ScaffoldingMethodTestBlock(AbstractBlock.Properties.create(Material.MISCELLANEOUS, MaterialColor.SAND).doesNotBlockMovement().sound(SoundType.SCAFFOLDING).variableOpacity()));
public ScaffoldingTest()
{
IEventBus modBus = FMLJavaModLoadingContext.get().getModEventBus();
BLOCKS.register(modBus);
modBus.addListener(this::gatherData);
}
private void gatherData(final GatherDataEvent event)
{
DataGenerator gen = event.getGenerator();
if(event.includeClient()) gen.addProvider(new ScaffoldingBlockState(gen, MODID, event.getExistingFileHelper()));
}
static class ScaffoldingBlockState extends BlockStateProvider
{
public ScaffoldingBlockState(DataGenerator gen, String modid, ExistingFileHelper exFileHelper)
{
super(gen, modid, exFileHelper);
}
@Override
protected void registerStatesAndModels()
{
this.getVariantBuilder(SCAFFOLDING_METHOD_TEST.get()).forAllStatesExcept((state) -> ConfiguredModel.builder().modelFile(state.get(ScaffoldingBlock.field_220120_c) ? new ModelFile.ExistingModelFile(new ResourceLocation("block/scaffolding_unstable"), this.models().existingFileHelper) : new ModelFile.ExistingModelFile(new ResourceLocation("block/scaffolding_stable"), this.models().existingFileHelper)).build(), ScaffoldingBlock.field_220118_a, ScaffoldingBlock.WATERLOGGED);
}
}
static class ScaffoldingMethodTestBlock extends ScaffoldingBlock
{
public ScaffoldingMethodTestBlock(Properties properties)
{
super(properties);
}
@Override
public boolean isScaffolding(BlockState state, IWorldReader world, BlockPos pos, LivingEntity entity)
{
return true;
}
}
}

View File

@ -79,4 +79,6 @@ license="LGPL v2.1"
[[mods]]
modId="custom_elytra_test"
[[mods]]
modId="finite_water_test"
modId="finite_water_test"
[[mods]]
modId="scaffolding_test"