Skip to content

Commit

Permalink
Merge pull request #391 from xiaoxing2005/PowerChair
Browse files Browse the repository at this point in the history
Power chair!!!!
  • Loading branch information
Nxer committed Apr 13, 2024
2 parents 92c5ee0 + f42794c commit 3ebb25a
Show file tree
Hide file tree
Showing 7 changed files with 181 additions and 66 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.Nxer.TwistSpaceTechnology.client.Audio;

import net.minecraft.client.audio.PositionedSoundRecord;
import net.minecraft.util.ResourceLocation;

public class Sound extends PositionedSoundRecord {

public Sound(ResourceLocation soundResource, float volume, float pitch, boolean repeat, float xPosition,
float yPosition, float zPosition) {
super(soundResource, volume, pitch, xPosition, yPosition, zPosition);
this.repeat = repeat;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.Nxer.TwistSpaceTechnology.client.render;

import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
Expand Down Expand Up @@ -49,11 +50,18 @@ public void renderTileEntityAt(TileEntity tile, double x, double y, double z, fl
if (!(tile instanceof TilePowerChair)) return;
GL11.glPushMatrix();
getTileEntityFacing((TilePowerChair) tile, x, y, z);
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glDisable(GL11.GL_CULL_FACE);
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glScaled(0.07, 0.07, 0.07);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
this.bindTexture(textures);
GL11.glScaled(0.07, 0.07, 0.07);
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240f, 240f);
Renderer.renderAll();
GL11.glDisable(GL11.GL_BLEND);
GL11.glDepthMask(true);
GL11.glEnable(GL11.GL_CULL_FACE);
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glPopMatrix();
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@
package com.Nxer.TwistSpaceTechnology.common.Entity;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;

import com.Nxer.TwistSpaceTechnology.util.BlockPos;
import com.Nxer.TwistSpaceTechnology.client.Audio.Sound;
import com.Nxer.TwistSpaceTechnology.config.Config;

public class EntityMountableBlock extends Entity {

public static final HashMap<BlockPos, EntityMountableBlock> OCCUPIED = new HashMap<>();
public static final ResourceLocation BGM = new ResourceLocation("gtnhcommunitymod:PowerChair");

public int orgBlockPosX;
public int orgBlockPosY;
public int orgBlockPosZ;
public Block orgBlock;
public EntityPlayer player;
public Sound sound;

public EntityMountableBlock(World worldIn) {
super(worldIn);
Expand All @@ -19,22 +33,98 @@ public EntityMountableBlock(World worldIn) {
width = 0.0001F;
}

public EntityMountableBlock(World world, BlockPos pos) {
public EntityMountableBlock(World world, EntityPlayer player, int x, int y, int z, double mountingX,
double mountingY, double mountingZ) {
super(world);
setPosition(pos.x + 0.5D, pos.y + 0.68D, pos.z + 0.5D);
noClip = true;
height = 0.0001F;
width = 0.0001F;
OCCUPIED.put(pos, this);
this.player = player;
this.noClip = true;
this.preventEntitySpawning = true;
this.width = 0.0F;
this.height = 0.0F;
this.orgBlockPosX = x;
this.orgBlockPosY = y;
this.orgBlockPosZ = z;
this.orgBlock = world.getBlock(x, y, z);
this.setPosition(mountingX, mountingY, mountingZ);
if (Config.Enable_PowerChairBGM) {
this.sound = new Sound(BGM, 0.4f, 1.0f, true, x, y, z);
}
}

public static boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, float hitX,
float hitY, float hitZ) {
if (!world.isRemote) {
List listEMB = world.getEntitiesWithinAABB(
EntityMountableBlock.class,
AxisAlignedBB.getBoundingBox(x, y, z, (double) x + 1.0D, (double) y + 1.0D, (double) z + 1.0D)
.expand(1.0D, 1.0D, 1.0D));
Iterator i = listEMB.iterator();
EntityMountableBlock mounting;

do {
if (!i.hasNext()) {
double mountingX = (double) x + hitX;
double mountingY = (double) y + hitY;
double mountingZ = (double) z + hitZ;

EntityMountableBlock entity = new EntityMountableBlock(
world,
player,
x,
y,
z,
mountingX,
mountingY,
mountingZ);
world.spawnEntityInWorld(entity);
entity.interact(player);
if (Config.Enable_PowerChairBGM) {
Minecraft.getMinecraft()
.getSoundHandler()
.playSound(entity.sound);
}
return true;
}

mounting = (EntityMountableBlock) i.next();
} while (mounting.orgBlockPosX != x || mounting.orgBlockPosY != y || mounting.orgBlockPosZ != z);

mounting.interact(player);
return true;
} else {
return false;
}
}

public boolean interact(EntityPlayer entityplayer) {
if (this.riddenByEntity != null && this.riddenByEntity instanceof EntityPlayer
&& this.riddenByEntity != entityplayer) {
return true;
} else {
if (!this.worldObj.isRemote) {
entityplayer.mountEntity(this);
}

return false;
}
}

@Override
public void onUpdate() {
if (worldObj.isRemote) {
if (this.riddenByEntity == null) {
this.setDead();
public void onEntityUpdate() {
this.worldObj.theProfiler.startSection("entityBaseTick");
if (this.riddenByEntity != null && !this.riddenByEntity.isDead) {
return;
} else {
this.setDead();
if (this.sound != null) {
Minecraft.getMinecraft()
.getSoundHandler()
.stopSound(this.sound);
}
}

++this.ticksExisted;
this.worldObj.theProfiler.endSection();
}

/**
Expand All @@ -45,21 +135,11 @@ protected void entityInit() {

}

/**
* (abstract) Protected helper method to read subclass entity data from NBT.
*
* @param tagCompund
*/
@Override
protected void readEntityFromNBT(NBTTagCompound tagCompund) {

}

/**
* (abstract) Protected helper method to write subclass entity data to NBT.
*
* @param tagCompound
*/
@Override
protected void writeEntityToNBT(NBTTagCompound tagCompound) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import com.Nxer.TwistSpaceTechnology.client.GTCMCreativeTabs;
import com.Nxer.TwistSpaceTechnology.common.Entity.EntityMountableBlock;
import com.Nxer.TwistSpaceTechnology.common.tile.TilePowerChair;
import com.Nxer.TwistSpaceTechnology.util.BlockPos;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
Expand Down Expand Up @@ -85,48 +84,37 @@ public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase p
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7,
float par8, float par9) {
if (world.isRemote) {
return false;
} else {
TileEntity tile = world.getTileEntity(x, y, z);
if (tile instanceof TilePowerChair) {
int metadata = world.getBlockMetadata(x, y, z);
metadata %= 4;
if (metadata == 0) {
player.rotationYaw = 90.0F;
EntityMountableBlock entityMountableBlock = new EntityMountableBlock(world, new BlockPos(x, y, z));
world.spawnEntityInWorld(entityMountableBlock);
player.mountEntity(entityMountableBlock);

return true;
}

if (metadata == 1) {
player.rotationYaw = -90.0F;
EntityMountableBlock entityMountableBlock = new EntityMountableBlock(world, new BlockPos(x, y, z));
world.spawnEntityInWorld(entityMountableBlock);
player.mountEntity(entityMountableBlock);
return true;
}

if (metadata == 2) {
player.rotationYaw = 180.0F;
EntityMountableBlock entityMountableBlock = new EntityMountableBlock(world, new BlockPos(x, y, z));
world.spawnEntityInWorld(entityMountableBlock);
player.mountEntity(entityMountableBlock);
return true;
}

if (metadata == 3) {
player.rotationYaw = 0.0F;
EntityMountableBlock entityMountableBlock = new EntityMountableBlock(world, new BlockPos(x, y, z));
world.spawnEntityInWorld(entityMountableBlock);
player.mountEntity(entityMountableBlock);
return true;
} else return false;

TileEntity tile = world.getTileEntity(x, y, z);
if (tile instanceof TilePowerChair) {
int metadata = world.getBlockMetadata(x, y, z);
metadata %= 4;
if (metadata == 0) {
player.rotationYaw = 90.0F;

return EntityMountableBlock.onBlockActivated(world, x, y, z, player, 0.5F, 0.68F, 0.5F);
}

if (metadata == 1) {
player.rotationYaw = -90.0F;

return EntityMountableBlock.onBlockActivated(world, x, y, z, player, 0.5F, 0.68F, 0.5F);
}

if (metadata == 2) {
player.rotationYaw = 180.0F;

return EntityMountableBlock.onBlockActivated(world, x, y, z, player, 0.5F, 0.68F, 0.5F);
}
return false;

if (metadata == 3) {
player.rotationYaw = 0.0F;

return EntityMountableBlock.onBlockActivated(world, x, y, z, player, 0.5F, 0.68F, 0.5F);
} else return false;
}

return false;
}

@Override
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/com/Nxer/TwistSpaceTechnology/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public class Config {
public static final String SpaceApiary = "SpaceApiary";
public static final String IndustrialMagnetarSeparator = "IndustrialMagnetarSeparator";
public static final String CombatStats = "CombatStats";
public static final String IndustrialMagicMatrix = "IndustrialMagicMatrix";
public static final String PowerChairBGM = "PowerChairBGM";
// endregion

// region General
Expand Down Expand Up @@ -343,8 +345,13 @@ public class Config {

public static boolean Enable_LargeCanner = true;

// region IndustrialMagicMatrix
public static boolean Enable_IndustrialMagicMatrix = true;
// endregion

// region PowerChair BGM
public static boolean Enable_PowerChairBGM = true;
// endregion

public static void synchronizeConfiguration(File configFile) {
Configuration configuration = new Configuration(configFile);
Expand Down Expand Up @@ -635,6 +642,14 @@ public static void synchronizeConfiguration(File configFile) {
ParallelMultiply_IndustrialMagnetarSeparator = configuration.getInt("ParallelMultiply_IndustrialMagnetarSeparator", IndustrialMagnetarSeparator, ParallelMultiply_IndustrialMagnetarSeparator, 1, 2147483646, "Parallel Multiply of Industrial Magnetar Separator. Type: int");;
// endregion

// region Industrial Magic Matrix
Enable_IndustrialMagicMatrix = configuration.getBoolean("EnableIndustrialMagicMatrix",IndustrialMagicMatrix,Enable_IndustrialMagicMatrix,"Enable Industrial Magic Matrix");
// endregion

// region Power Chair
Enable_PowerChairBGM = configuration.getBoolean("Enable Power Chair BGM",PowerChairBGM,Enable_PowerChairBGM,"Enable Power Chair BGM");
// endregion

// region Mega Tree Farm

// endregion
Expand Down
11 changes: 11 additions & 0 deletions src/main/resources/assets/gtnhcommunitymod/sounds.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"PowerChair": {
"category": "master",
"sounds": [
{
"name": "PowerChair",
"stream": false
}
]
}
}
Binary file not shown.

0 comments on commit 3ebb25a

Please sign in to comment.