mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-17 10:55:17 +00:00
Fix missing mossy dremawood planks model, semi-fix ghost rails
This commit is contained in:
1 parent
35df76b230
commit
a3b6a2ca6b
2 files changed
+65
-30
No files matched your search
@@ -13,6 +13,7 @@ package vazkii.botania.common.block;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.AbstractRailBlock;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.item.minecart.AbstractMinecartEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.state.IProperty;
|
||||
@@ -21,6 +22,10 @@ import net.minecraft.state.properties.BlockStateProperties;
|
||||
import net.minecraft.state.properties.RailShape;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.dimension.DimensionType;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.TickEvent;
|
||||
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import vazkii.botania.api.lexicon.ILexiconable;
|
||||
import vazkii.botania.api.lexicon.LexiconEntry;
|
||||
@@ -28,15 +33,23 @@ import vazkii.botania.common.lexicon.LexiconData;
|
||||
import vazkii.botania.common.lib.LibMisc;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
@Mod.EventBusSubscriber(modid = LibMisc.MOD_ID)
|
||||
public class BlockGhostRail extends AbstractRailBlock implements ILexiconable {
|
||||
|
||||
private static final String TAG_FLOAT_TICKS = "Botania_FloatTicks";
|
||||
private static final String TAG_FLOAT_TICKS = "botania:float_ticks";
|
||||
|
||||
public BlockGhostRail(Properties builder) {
|
||||
super(true, builder);
|
||||
setDefaultState(stateContainer.getBaseState().with(BlockStateProperties.RAIL_SHAPE_STRAIGHT, RailShape.NORTH_SOUTH));
|
||||
MinecraftForge.EVENT_BUS.addListener(this::cartSpawn);
|
||||
MinecraftForge.EVENT_BUS.addListener(this::worldTick);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -44,38 +57,60 @@ public class BlockGhostRail extends AbstractRailBlock implements ILexiconable {
|
||||
builder.add(BlockStateProperties.RAIL_SHAPE_STRAIGHT);
|
||||
}
|
||||
|
||||
/* todo 1.13
|
||||
@SubscribeEvent
|
||||
public static void onMinecartUpdate(MinecartUpdateEvent event) {
|
||||
BlockPos entPos = new BlockPos(event.getEntity());
|
||||
IBlockState state = event.getEntity().world.getBlockState(entPos);
|
||||
Block block = state.getBlock();
|
||||
boolean air = block.isAir(state, event.getEntity().world, entPos);
|
||||
int floatTicks = event.getEntity().getEntityData().getInteger(TAG_FLOAT_TICKS);
|
||||
|
||||
if(block == ModBlocks.ghostRail)
|
||||
event.getEntity().getEntityData().setInteger(TAG_FLOAT_TICKS, 20);
|
||||
else if(block instanceof BlockRailBase || block == ModBlocks.dreamwood) {
|
||||
event.getEntity().getEntityData().setInteger(TAG_FLOAT_TICKS, 0);
|
||||
if(floatTicks > 0)
|
||||
event.getEntity().world.playEvent(2003, entPos, 0);
|
||||
}
|
||||
floatTicks = event.getEntity().getEntityData().getInteger(TAG_FLOAT_TICKS);
|
||||
|
||||
private static void updateFloating(AbstractMinecartEntity cart, int floatTicks) {
|
||||
BlockPos entPos = new BlockPos(cart);
|
||||
BlockState state = cart.world.getBlockState(entPos);
|
||||
boolean air = state.isAir(cart.world, entPos);
|
||||
if(floatTicks > 0) {
|
||||
IBlockState stateBelow = event.getEntity().world.getBlockState(entPos.down());
|
||||
BlockState stateBelow = cart.world.getBlockState(entPos.down());
|
||||
Block blockBelow = stateBelow.getBlock();
|
||||
boolean airBelow = blockBelow.isAir(stateBelow, event.getEntity().world, entPos.down());
|
||||
boolean airBelow = blockBelow.isAir(stateBelow, cart.world, entPos.down());
|
||||
if(air && airBelow || !air && !airBelow)
|
||||
event.getEntity().noClip = true;
|
||||
event.getEntity().motionY = 0.2;
|
||||
event.getEntity().motionX *= 1.4;
|
||||
event.getEntity().motionZ *= 1.4;
|
||||
event.getEntity().getEntityData().setInteger(TAG_FLOAT_TICKS, floatTicks - 1);
|
||||
event.getEntity().world.playEvent(2000, entPos, 0);
|
||||
} else event.getEntity().noClip = false;
|
||||
cart.noClip = true;
|
||||
cart.setMotion(cart.getMotion().getX() * 1.4, 0.2, cart.getMotion().getZ() * 1.4);
|
||||
cart.getPersistentData().putInt(TAG_FLOAT_TICKS, floatTicks - 1);
|
||||
cart.world.playEvent(2000, entPos, 0);
|
||||
} else cart.noClip = false; // todo 1.14 doesn't seem to work for some reason?
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMinecartPass(BlockState state, World world, BlockPos pos, AbstractMinecartEntity cart) {
|
||||
super.onMinecartPass(state, world, pos, cart);
|
||||
if(!world.isRemote) {
|
||||
int floatTicks = 20;
|
||||
cart.getPersistentData().putInt(TAG_FLOAT_TICKS, floatTicks);
|
||||
updateFloating(cart, floatTicks);
|
||||
}
|
||||
}
|
||||
|
||||
private final Map<DimensionType, Set<AbstractMinecartEntity>> carts = new HashMap<>();
|
||||
|
||||
private void cartSpawn(EntityJoinWorldEvent evt) {
|
||||
if(!evt.getWorld().isRemote && evt.getEntity() instanceof AbstractMinecartEntity) {
|
||||
carts.computeIfAbsent(evt.getWorld().getDimension().getType(), t -> Collections.newSetFromMap(new WeakHashMap<>()))
|
||||
.add((AbstractMinecartEntity) evt.getEntity());
|
||||
}
|
||||
}
|
||||
|
||||
private void worldTick(TickEvent.WorldTickEvent evt) {
|
||||
if(!evt.world.isRemote() && evt.phase == TickEvent.Phase.END) {
|
||||
for (AbstractMinecartEntity c : carts.getOrDefault(evt.world.getDimension().getType(), Collections.emptySet())) {
|
||||
BlockPos entPos = new BlockPos(c);
|
||||
BlockState state = c.world.getBlockState(entPos);
|
||||
Block block = state.getBlock();
|
||||
int floatTicks = c.getPersistentData().getInt(TAG_FLOAT_TICKS);
|
||||
|
||||
if(block != ModBlocks.ghostRail
|
||||
&& (block instanceof AbstractRailBlock || block == ModBlocks.dreamwood)) {
|
||||
c.getPersistentData().putInt(TAG_FLOAT_TICKS, 0);
|
||||
if(floatTicks > 0)
|
||||
c.world.playEvent(2003, entPos, 0);
|
||||
}
|
||||
|
||||
updateFloating(c, c.getPersistentData().getInt(TAG_FLOAT_TICKS));
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
@Override
|
||||
public LexiconEntry getEntry(World world, BlockPos pos, PlayerEntity player, ItemStack lexicon) {
|
||||
|
||||
Reference in new issue
Block a user