Browse files

Overhauled how items are activated.

  • Loading branch information...
1 parent 68b83d0 commit c24b9f11d85ea7318144cf9a46439a9f82b5c5f8 @immortius committed May 11, 2012
Showing with 133 additions and 268 deletions.
  1. +1 −1 src/main/java/org/terasology/componentSystem/action/ExplosionAction.java
  2. +15 −1 src/main/java/org/terasology/componentSystem/action/PlaySoundAction.java
  3. +0 −3 src/main/java/org/terasology/componentSystem/action/ReadBookAction.java
  4. +12 −1 src/main/java/org/terasology/componentSystem/action/SpawnPrefabAction.java
  5. +1 −1 src/main/java/org/terasology/componentSystem/action/TunnelAction.java
  6. +3 −1 src/main/java/org/terasology/componentSystem/block/BlockEntityRegistry.java
  7. +11 −37 src/main/java/org/terasology/componentSystem/controllers/LocalPlayerSystem.java
  8. +2 −7 src/main/java/org/terasology/componentSystem/controllers/SimpleMinionAISystem.java
  9. +32 −39 src/main/java/org/terasology/componentSystem/items/ItemSystem.java
  10. +4 −15 ...ava/org/terasology/{events/item/UseItemOnEntityEvent.java → components/actions/ActionTarget.java}
  11. +0 −1 src/main/java/org/terasology/components/actions/ExplosionActionComponent.java
  12. +1 −0 src/main/java/org/terasology/components/actions/PlaySoundActionComponent.java
  13. +1 −0 src/main/java/org/terasology/components/actions/SpawnPrefabActionComponent.java
  14. +38 −25 src/main/java/org/terasology/events/ActivateEvent.java
  15. +0 −39 src/main/java/org/terasology/events/item/UseItemEvent.java
  16. +0 −45 src/main/java/org/terasology/events/item/UseItemInDirectionEvent.java
  17. +0 −49 src/main/java/org/terasology/events/item/UseItemOnBlockEvent.java
  18. +5 −0 src/main/java/org/terasology/math/Side.java
  19. +4 −3 src/main/java/org/terasology/model/structures/RayBlockIntersection.java
  20. +3 −0 src/main/java/org/terasology/rendering/gui/components/UIMinionbarCell.java
View
2 src/main/java/org/terasology/componentSystem/action/ExplosionAction.java
@@ -35,7 +35,7 @@ public void initialise() {
@ReceiveEvent(components = {ExplosionActionComponent.class})
public void onActivate(ActivateEvent event, EntityRef entity) {
- Vector3f origin = event.getLocation();
+ Vector3f origin = event.getTargetLocation();
if (origin == null) return;
Vector3i blockPos = new Vector3i();
View
16 src/main/java/org/terasology/componentSystem/action/PlaySoundAction.java
@@ -10,6 +10,8 @@
import org.terasology.logic.manager.SoundManager;
import org.terasology.utilities.FastRandom;
+import javax.vecmath.Vector3f;
+
/**
* @author Immortius <immortius@gmail.com>
*/
@@ -26,7 +28,19 @@ public void onActivate(ActivateEvent event, EntityRef entity) {
PlaySoundActionComponent playSound = entity.getComponent(PlaySoundActionComponent.class);
if (playSound.sounds.size() > 0) {
Sound sound = playSound.sounds.get(random.randomIntAbs(playSound.sounds.size()));
- AudioManager.play(sound, event.getLocation(), playSound.volume, SoundManager.PRIORITY_NORMAL);
+ Vector3f pos = null;
+ switch (playSound.relativeTo) {
+ case Instigator:
+ pos = event.getInstigatorLocation();
+ break;
+ case Target:
+ pos = event.getTargetLocation();
+ break;
+ }
+ if (pos == null) {
+ pos = event.getOrigin();
+ }
+ AudioManager.play(sound, pos, playSound.volume, SoundManager.PRIORITY_NORMAL);
}
}
}
View
3 src/main/java/org/terasology/componentSystem/action/ReadBookAction.java
@@ -5,10 +5,7 @@
import org.terasology.entitySystem.EventHandlerSystem;
import org.terasology.entitySystem.ReceiveEvent;
import org.terasology.events.ActivateEvent;
-import org.terasology.events.item.UseItemEvent;
import org.terasology.logic.manager.GUIManager;
-import org.terasology.rendering.gui.components.UIOpenBook;
-import org.terasology.rendering.gui.framework.UIDisplayWindow;
import org.terasology.rendering.gui.menus.UIOpenBookScreen;
import java.util.logging.Level;
View
13 src/main/java/org/terasology/componentSystem/action/SpawnPrefabAction.java
@@ -26,6 +26,7 @@
import org.terasology.game.CoreRegistry;
import javax.vecmath.Quat4f;
+import javax.vecmath.Vector3f;
/**
* @author Immortius
@@ -46,7 +47,17 @@ public void onActivate(ActivateEvent event, EntityRef entity) {
EntityRef newEntity = entityManager.create(spawnInfo.prefab);
LocationComponent loc = newEntity.getComponent(LocationComponent.class);
if (loc != null) {
- loc.setWorldPosition(event.getLocation());
+ switch (spawnInfo.spawnLocationRelativeTo) {
+ case Instigator:
+ loc.setWorldPosition(event.getInstigatorLocation());
+ break;
+ case Target:
+ Vector3f pos = event.getTargetLocation();
+ if (pos != null) {
+ loc.setWorldPosition(pos);
+ }
+ break;
+ }
// TODO: Set rotation
newEntity.saveComponent(loc);
}
View
2 src/main/java/org/terasology/componentSystem/action/TunnelAction.java
@@ -37,7 +37,7 @@ public void initialise() {
public void onActivate(ActivateEvent event, EntityRef entity) {
Vector3f dir = new Vector3f(event.getDirection());
- Vector3f origin = new Vector3f(event.getLocation());
+ Vector3f origin = new Vector3f(event.getOrigin());
Vector3i blockPos = new Vector3i();
for (int s = 4; s <= 10000; s += 30) {
origin.add(dir);
View
4 src/main/java/org/terasology/componentSystem/block/BlockEntityRegistry.java
@@ -52,7 +52,9 @@ public EntityRef getOrCreateEntityAt(Vector3i blockPosition) {
// TODO: Better cleanup of temporary block entities
blockEntity.addComponent(new BlockComponent(blockPosition, block.isEntityTemporary()));
// TODO: Get regen and wait from block config?
- blockEntity.addComponent(new HealthComponent(block.getHardness(), 2.0f, 1.0f));
+ if (block.isDestructible()) {
+ blockEntity.addComponent(new HealthComponent(block.getHardness(), 2.0f, 1.0f));
+ }
}
return blockEntity;
}
View
48 src/main/java/org/terasology/componentSystem/controllers/LocalPlayerSystem.java
@@ -16,9 +16,6 @@
import org.terasology.events.DamageEvent;
import org.terasology.events.NoHealthEvent;
import org.terasology.events.OpenInventoryEvent;
-import org.terasology.events.item.UseItemEvent;
-import org.terasology.events.item.UseItemInDirectionEvent;
-import org.terasology.events.item.UseItemOnBlockEvent;
import org.terasology.game.CoreRegistry;
import org.terasology.game.Timer;
import org.terasology.logic.LocalPlayer;
@@ -377,21 +374,8 @@ private void processInteractions(int button) {
// Process primary button actions, which depends on the selected item (if any)
if (Mouse.isButtonDown(0) || button == 0) {
ItemComponent item = selectedItemEntity.getComponent(ItemComponent.class);
- if (item != null) {
- switch (item.usage) {
- case OnBlock:
- useItemOnBlock(entity, selectedItemEntity);
- break;
- case OnUser:
- selectedItemEntity.send(new UseItemEvent(entity));
- break;
- case InDirection:
- selectedItemEntity.send(new UseItemInDirectionEvent(entity, new Vector3f(playerCamera.getPosition()), new Vector3f(playerCamera.getViewingDirection())));
- break;
- default:
- attack(entity, selectedItemEntity);
- break;
- }
+ if (item != null && item.usage != ItemComponent.UsageType.None) {
+ useItem(entity, selectedItemEntity);
}
else {
attack(entity, selectedItemEntity);
@@ -431,30 +415,22 @@ private void processFrob() {
}
}
- private void useItemOnBlock(EntityRef player, EntityRef item) {
+ private void useItem(EntityRef player, EntityRef item) {
+ // TODO: Raytrace against entities too
RayBlockIntersection.Intersection blockIntersection = calcSelectedBlock();
if (blockIntersection != null) {
Vector3i centerPos = blockIntersection.getBlockPosition();
- Vector3i blockPos = blockIntersection.calcAdjacentBlockPos();
-
- // Need two things:
- // 1. The Side of attachment
- Side attachmentSide = Side.inDirection(blockPos.x - centerPos.x, blockPos.y - centerPos.y, blockPos.z - centerPos.z);
- // 2. The secondary direction
- Vector3f attachDir = new Vector3f(centerPos.x - blockPos.x, centerPos.y - blockPos.y, centerPos.z - blockPos.z);
- Vector3f rawDirection = new Vector3f(playerCamera.getViewingDirection());
- float dot = rawDirection.dot(attachDir);
- rawDirection.sub(new Vector3f(dot * attachDir.x, dot * attachDir.y, dot * attachDir.z));
- Side direction = Side.inDirection(rawDirection.x, rawDirection.y, rawDirection.z).reverse();
-
- item.send(new UseItemOnBlockEvent(player, centerPos, attachmentSide, direction));
+
+ item.send(new ActivateEvent(CoreRegistry.get(BlockEntityRegistry.class).getOrCreateEntityAt(centerPos), player, new Vector3f(playerCamera.getPosition()), new Vector3f(playerCamera.getViewingDirection()), blockIntersection.getSurfaceNormal()));
+ } else {
+ item.send(new ActivateEvent(player, new Vector3f(playerCamera.getPosition()), new Vector3f(playerCamera.getViewingDirection())));
}
}
/**
* Attacks with currently held item
*/
- // TODO: Move this somewhere more central, for use by all creatures.
+ // TODO: Move this somewhere more central, for use by all creatures. And activate with event
private void attack(EntityRef player, EntityRef withItem) {
RayBlockIntersection.Intersection selectedBlock = calcSelectedBlock();
ItemComponent item = withItem.getComponent(ItemComponent.class);
@@ -473,10 +449,8 @@ private void attack(EntityRef player, EntityRef withItem) {
}
}
- if (block.isDestructible()) {
- EntityRef blockEntity = blockEntityRegistry.getOrCreateEntityAt(blockPos);
- blockEntity.send(new DamageEvent(damage, player));
- }
+ EntityRef blockEntity = blockEntityRegistry.getOrCreateEntityAt(blockPos);
+ blockEntity.send(new DamageEvent(damage, player));
}
View
9 src/main/java/org/terasology/componentSystem/controllers/SimpleMinionAISystem.java
@@ -145,8 +145,6 @@ private void attack(EntityRef player, Vector3f position) {
//if (selectedBlock != null) {
//BlockPosition blockPos = selectedBlock.getBlockPosition();
- byte currentBlockType = worldProvider.getBlock((int)position.x, (int)position.y, (int)position.z);
- Block block = BlockManager.getInstance().getBlock(currentBlockType);
int damage = 1;
/*if (item != null) {
@@ -155,11 +153,8 @@ private void attack(EntityRef player, Vector3f position) {
damage += item.getPerBlockDamageBonus().get(block.getBlockFamily().getTitle());
}
}*/
-
- if (block.isDestructible()) {
- EntityRef blockEntity = blockEntityRegistry.getOrCreateEntityAt(new Vector3i(position));
- blockEntity.send(new DamageEvent(damage, player));
- }
+ EntityRef blockEntity = blockEntityRegistry.getOrCreateEntityAt(new Vector3i(position));
+ blockEntity.send(new DamageEvent(damage, player));
//}
View
71 src/main/java/org/terasology/componentSystem/items/ItemSystem.java
@@ -8,10 +8,6 @@
import org.terasology.entitySystem.ReceiveEvent;
import org.terasology.entitySystem.event.RemovedComponentEvent;
import org.terasology.events.ActivateEvent;
-import org.terasology.events.item.UseItemEvent;
-import org.terasology.events.item.UseItemInDirectionEvent;
-import org.terasology.events.item.UseItemOnBlockEvent;
-import org.terasology.events.item.UseItemOnEntityEvent;
import org.terasology.game.ComponentSystemManager;
import org.terasology.game.CoreRegistry;
import org.terasology.logic.manager.AudioManager;
@@ -23,6 +19,7 @@
import org.terasology.model.blocks.management.BlockManager;
import org.terasology.model.structures.AABB;
+import javax.print.attribute.standard.Sides;
import javax.vecmath.Vector3f;
/**
@@ -45,51 +42,48 @@ public void onDestroyed(RemovedComponentEvent event, EntityRef entity) {
entity.getComponent(BlockItemComponent.class).placedEntity.destroy();
}
- @ReceiveEvent(components=ItemComponent.class)
- public void useItemOnBlock(UseItemOnBlockEvent event, EntityRef item) {
+ @ReceiveEvent(components={BlockItemComponent.class, ItemComponent.class})
+ public void onPlaceBlock(ActivateEvent event, EntityRef item) {
ItemComponent itemComp = item.getComponent(ItemComponent.class);
- if (itemComp == null || itemComp.usage != ItemComponent.UsageType.OnBlock) return;
-
BlockItemComponent blockItem = item.getComponent(BlockItemComponent.class);
- if (blockItem != null) {
- if (placeBlock(blockItem.blockFamily, event.getTargetBlock(), event.getSurfaceDirection(), event.getSecondaryDirection(), blockItem)) {
- checkConsumeItem(item, itemComp);
- }
- } else {
- EntityRef targetEntity = blockEntityRegistry.getOrCreateEntityAt(event.getTargetBlock());
- item.send(new ActivateEvent(targetEntity, event.getInstigator()));
- checkConsumeItem(item, itemComp);
- }
- }
- @ReceiveEvent(components=ItemComponent.class)
- public void useItem(UseItemEvent event, EntityRef item) {
- ItemComponent itemComp = item.getComponent(ItemComponent.class);
- if (itemComp == null || itemComp.usage != ItemComponent.UsageType.OnUser) return;
- item.send(new ActivateEvent(event.getInstigator(), event.getInstigator()));
- checkConsumeItem(item, itemComp);
- }
+ Side surfaceDir = Side.inDirection(event.getNormal());
- @ReceiveEvent(components = ItemComponent.class)
- public void useItemOnEntity(UseItemOnEntityEvent event, EntityRef item) {
- ItemComponent itemComp = item.getComponent(ItemComponent.class);
- if (itemComp == null) return;
+ Vector3f attachDir = surfaceDir.reverse().getVector3i().toVector3f();
+ Vector3f rawDirection = new Vector3f(event.getDirection());
+ float dot = rawDirection.dot(attachDir);
+ rawDirection.sub(new Vector3f(dot * attachDir.x, dot * attachDir.y, dot * attachDir.z));
+ Side secondaryDirection = Side.inDirection(rawDirection.x, rawDirection.y, rawDirection.z).reverse();
- item.send(new ActivateEvent(event.getTarget(), event.getInstigator()));
- checkConsumeItem(item, itemComp);
+ if (!placeBlock(blockItem.blockFamily, event.getTarget().getComponent(BlockComponent.class).getPosition(), surfaceDir, secondaryDirection, blockItem)) {
+ event.cancel();
+ }
}
- @ReceiveEvent(components = ItemComponent.class)
- public void useItemInDirection(UseItemInDirectionEvent event, EntityRef item) {
+ @ReceiveEvent(components=ItemComponent.class,priority = ReceiveEvent.PRIORITY_CRITICAL)
+ public void checkCanUseItem(ActivateEvent event, EntityRef item) {
ItemComponent itemComp = item.getComponent(ItemComponent.class);
- if (itemComp == null) return;
-
- item.send(new ActivateEvent(event.getLocation(), event.getDirection(), event.getInstigator()));
- checkConsumeItem(item, itemComp);
+ switch (itemComp.usage) {
+ case None:
+ event.cancel();
+ break;
+ case OnBlock:
+ if (event.getTarget().getComponent(BlockComponent.class) == null) {
+ event.cancel();
+ }
+ break;
+ case OnEntity:
+ if (event.getTarget().getComponent(BlockComponent.class) != null) {
+ event.cancel();
+ }
+ break;
+ }
}
- private void checkConsumeItem(EntityRef item, ItemComponent itemComp) {
+ @ReceiveEvent(components=ItemComponent.class,priority = ReceiveEvent.PRIORITY_TRIVIAL)
+ public void usedItem(ActivateEvent event, EntityRef item) {
+ ItemComponent itemComp = item.getComponent(ItemComponent.class);
if (itemComp.consumedOnUse) {
itemComp.stackCount--;
if (itemComp.stackCount == 0) {
@@ -100,7 +94,6 @@ private void checkConsumeItem(EntityRef item, ItemComponent itemComp) {
}
}
}
-
/**
* Places a block of a given type in front of the player.
*
View
19 ...ogy/events/item/UseItemOnEntityEvent.java → ...logy/components/actions/ActionTarget.java
@@ -14,23 +14,12 @@
* limitations under the License.
*/
-package org.terasology.events.item;
-
-import org.terasology.entitySystem.EntityRef;
+package org.terasology.components.actions;
/**
* @author Immortius
*/
-public class UseItemOnEntityEvent extends UseItemEvent
-{
- private EntityRef target;
-
- public UseItemOnEntityEvent(EntityRef instigator, EntityRef target) {
- super(instigator);
- this.target = target;
- }
-
- public EntityRef getTarget() {
- return target;
- }
+public enum ActionTarget {
+ Instigator,
+ Target;
}
View
1 src/main/java/org/terasology/components/actions/ExplosionActionComponent.java
@@ -6,5 +6,4 @@
* @author Immortius <immortius@gmail.com>
*/
public class ExplosionActionComponent extends AbstractComponent {
-
}
View
1 src/main/java/org/terasology/components/actions/PlaySoundActionComponent.java
@@ -14,6 +14,7 @@
public class PlaySoundActionComponent extends AbstractComponent {
public List<Sound> sounds = Lists.newArrayList();
public float volume = 1.0f;
+ public ActionTarget relativeTo = ActionTarget.Instigator;
public PlaySoundActionComponent() {}
View
1 src/main/java/org/terasology/components/actions/SpawnPrefabActionComponent.java
@@ -25,4 +25,5 @@
public class SpawnPrefabActionComponent extends AbstractComponent
{
public String prefab;
+ public ActionTarget spawnLocationRelativeTo = ActionTarget.Target;
}
View
63 src/main/java/org/terasology/events/ActivateEvent.java
@@ -14,35 +14,24 @@
public class ActivateEvent extends AbstractEvent {
private EntityRef instigator;
private EntityRef target;
- private Vector3f location;
+ private Vector3f origin;
private Vector3f direction;
+ private Vector3f normal;
+
+ public ActivateEvent(EntityRef instigator, Vector3f origin, Vector3f direction) {
+ this(EntityRef.NULL, instigator, origin, direction, new Vector3f());
+ }
- // For OnUser/OnBlock/OnEntity
public ActivateEvent(EntityRef target, EntityRef instigator) {
- this.instigator = instigator;
- this.target = target;
- LocationComponent loc = target.getComponent(LocationComponent.class);
- if (loc != null) {
- location = loc.getWorldPosition();
- }
- else {
- BlockComponent blockComp = target.getComponent(BlockComponent.class);
- if (blockComp != null) {
- location = blockComp.getPosition().toVector3f();
- }
- else {
- location = new Vector3f();
- }
- }
- direction = new Vector3f();
+ this(target, instigator, new Vector3f(), new Vector3f(), new Vector3f());
}
-
- // For InDirection
- public ActivateEvent(Vector3f location, Vector3f direction, EntityRef instigator) {
+
+ public ActivateEvent(EntityRef target, EntityRef instigator, Vector3f origin, Vector3f direction, Vector3f normal) {
this.instigator = instigator;
- this.target = EntityRef.NULL;
- this.location = location;
+ this.target = target;
this.direction = direction;
+ this.normal = normal;
+ this.origin = origin;
}
public EntityRef getInstigator() {
@@ -53,11 +42,35 @@ public EntityRef getTarget() {
return target;
}
- public Vector3f getLocation() {
- return location;
+ public Vector3f getOrigin() {
+ return origin;
}
public Vector3f getDirection() {
return direction;
}
+
+ public Vector3f getNormal() {
+ return normal;
+ }
+
+ public Vector3f getTargetLocation() {
+ LocationComponent loc = target.getComponent(LocationComponent.class);
+ if (loc != null) {
+ return loc.getWorldPosition();
+ }
+ BlockComponent blockComp = target.getComponent(BlockComponent.class);
+ if (blockComp != null) {
+ return blockComp.getPosition().toVector3f();
+ }
+ return null;
+ }
+
+ public Vector3f getInstigatorLocation() {
+ LocationComponent loc = instigator.getComponent(LocationComponent.class);
+ if (loc != null) {
+ return loc.getWorldPosition();
+ }
+ return new Vector3f();
+ }
}
View
39 src/main/java/org/terasology/events/item/UseItemEvent.java
@@ -1,39 +0,0 @@
-/*
- * Copyright 2012
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.terasology.events.item;
-
-import org.terasology.entitySystem.AbstractEvent;
-import org.terasology.entitySystem.EntityRef;
-import org.terasology.math.Side;
-import org.terasology.math.Vector3i;
-
-/**
- * @author Immortius
- */
-public class UseItemEvent extends AbstractEvent {
- private EntityRef instigator;
-
-
- public UseItemEvent(EntityRef instigator) {
- this.instigator = instigator;
-
- }
-
- public EntityRef getInstigator() {
- return instigator;
- }
-}
View
45 src/main/java/org/terasology/events/item/UseItemInDirectionEvent.java
@@ -1,45 +0,0 @@
-/*
- * Copyright 2012
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.terasology.events.item;
-
-import org.terasology.entitySystem.EntityRef;
-import org.terasology.math.Side;
-import org.terasology.math.Vector3i;
-
-import javax.vecmath.Vector3f;
-
-/**
- * @author Immortius
- */
-public class UseItemInDirectionEvent extends UseItemEvent {
- Vector3f location;
- Vector3f direction;
-
- public UseItemInDirectionEvent(EntityRef instigator, Vector3f location, Vector3f direction) {
- super(instigator);
- this.location = location;
- this.direction = direction;
- }
-
- public Vector3f getLocation() {
- return location;
- }
-
- public Vector3f getDirection() {
- return direction;
- }
-}
View
49 src/main/java/org/terasology/events/item/UseItemOnBlockEvent.java
@@ -1,49 +0,0 @@
-/*
- * Copyright 2012
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.terasology.events.item;
-
-import org.terasology.entitySystem.EntityRef;
-import org.terasology.math.Side;
-import org.terasology.math.Vector3i;
-
-/**
- * @author Immortius
- */
-public class UseItemOnBlockEvent extends UseItemEvent {
- private Vector3i targetBlock;
- private Side surfaceDirection;
- private Side secondaryDirection;
-
- public UseItemOnBlockEvent(EntityRef instigator, Vector3i targetBlock, Side surfaceDirection, Side secondaryDirection) {
- super(instigator);
- this.targetBlock = targetBlock;
- this.surfaceDirection = surfaceDirection;
- this.secondaryDirection = secondaryDirection;
- }
-
- public Vector3i getTargetBlock() {
- return targetBlock;
- }
-
- public Side getSurfaceDirection() {
- return surfaceDirection;
- }
-
- public Side getSecondaryDirection() {
- return secondaryDirection;
- }
-}
View
5 src/main/java/org/terasology/math/Side.java
@@ -15,6 +15,7 @@
*/
package org.terasology.math;
+import javax.vecmath.Vector3f;
import java.util.EnumMap;
/**
@@ -83,6 +84,10 @@ public static Side inDirection(int x, int y, int z) {
return (z > 0) ? BACK : FRONT;
}
+ public static Side inDirection(Vector3f dir) {
+ return inDirection(dir.x, dir.y, dir.z);
+ }
+
/**
* Determines which direction the player is facing
* @param x right/left
View
7 src/main/java/org/terasology/model/structures/RayBlockIntersection.java
@@ -21,6 +21,7 @@
import org.terasology.model.blocks.management.BlockManager;
import javax.vecmath.Vector3d;
+import javax.vecmath.Vector3f;
import java.util.ArrayList;
import java.util.Collections;
@@ -70,13 +71,13 @@ public boolean equals(Object o) {
return this._blockPosition.equals(i.getBlockPosition());
}
- Vector3d getSurfaceNormal() {
- return _surfaceNormal;
+ public Vector3f getSurfaceNormal() {
+ return new Vector3f(_surfaceNormal);
}
public BlockPosition calcAdjacentBlockPos() {
Vector3d pos = getBlockPosition().toVector3d();
- pos.add(getSurfaceNormal());
+ pos.add(_surfaceNormal);
return new BlockPosition(pos);
}
View
3 src/main/java/org/terasology/rendering/gui/components/UIMinionbarCell.java
@@ -95,6 +95,9 @@ public void render() {
_selectionRectangle.renderTransformed();
MinionBarComponent inventory = CoreRegistry.get(LocalPlayer.class).getEntity().getComponent(MinionBarComponent.class);
+ if (inventory == null) {
+ return;
+ }
if (inventory.MinionSlots.size() <= _id)
return;

0 comments on commit c24b9f1

Please sign in to comment.